org.licas.server

## Class ServerMethodHandler

- java.lang.Object
- - org.licas.server.ServerMethodHandler

- Direct Known Subclasses:
    BlockingServerMethodHandler, NonBlockingServerMethodHandler

      public abstract class ServerMethodHandler
      extends java.lang.Object

  Base class for the server handler to execute a single method call. A non-blocking call can pass a null response object, which should simply cancel the operation. Any direct server invocation that does not go through the system is assumed to be to the local file store and therefore requires a blocking call that returns a file result. The class can also parse a restful-style description of the method.
  Author:
    Kieran Greer

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `adminKey` The server service key
    `protected boolean` | `isBlocking` True if blocking call
    `protected boolean` | `isXmlRpc` True if licas xml-rpc parsing

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServerMethodHandler(java.lang.String theAdminKey)` Create a new instance of ServerMethodHandler.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `badRequestResponse(HttpEntity response, java.lang.String message)` Set values in the response to indicate a bad request.
    `MethodInfo` | `convertRequest(HttpEntity request)` Convert a message request description into a `MethodInfo` object.
    `protected void` | `convertResponse(HttpEntity response, java.lang.Object reply)` Configure the response object based on the message reply.
    `protected void` | `forbiddenResponse(HttpEntity response)` Set values in the response to indicate a forbidden request.
    `abstract HttpEntity` | `handleMethodExecution(BusEntity bo)` Handle the HTTP request.
    `protected void` | `noContentResponse(HttpEntity response)` Set values in the response to indicate a no content reply.
    `protected void` | `notFoundResponse(HttpEntity response)` Set values in the response to indicate a not found response.
    `protected boolean` | `processLocalCall(MethodInfo methodInfo, HttpEntity response)` Process a direct server call with no service invocation, if it is one.
    `protected HttpEntity` | `processServiceCall(BusEntity bo)` Process a direct server call with no service invocation, if it is one.
    `static boolean` | `serverRequest(java.lang.String message, MethodInfo methodInfo)` Return true if the message part is likely to be for a local server request, such as retrieve a file, not a service invocation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### isBlocking

          protected boolean isBlocking

      True if blocking call

    - #### isXmlRpc

          protected boolean isXmlRpc

      True if licas xml-rpc parsing

    - #### adminKey

          protected java.lang.String adminKey

      The server service key

  - ### Constructor Detail

    - #### ServerMethodHandler

          public ServerMethodHandler(java.lang.String theAdminKey)
                              throws java.lang.Exception

      Create a new instance of ServerMethodHandler.
      Parameters:
        `theAdminKey` - the server admin key.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### handleMethodExecution

          public abstract HttpEntity handleMethodExecution(BusEntity bo)

      Handle the HTTP request.
      Parameters:
        `bo` - the object retrieved from the message bus.
      Returns:
        the method execution result.

    - #### serverRequest

          public static boolean serverRequest(java.lang.String message,
                                              MethodInfo methodInfo)
                                       throws java.lang.Exception

      Return true if the message part is likely to be for a local server request, such as retrieve a file, not a service invocation. The `methodInfo` object is also updated.
      Parameters:
        `message` - the message part to evaluate.
        `methodInfo` - the method info to update with pre-defined values.
      Returns:
        true if likely to be a local server request.
      Throws:
        `java.lang.Exception` - any error.

    - #### processLocalCall

          protected boolean processLocalCall(MethodInfo methodInfo,
                                             HttpEntity response)
                                      throws java.lang.Exception

      Process a direct server call with no service invocation, if it is one.
      Parameters:
        `methodInfo` - the full method description.
        `response` - the response http object to return. Can be null.
      Returns:
        the response object with the reply data.
      Throws:
        `java.lang.Exception` - any error.

    - #### processServiceCall

          protected HttpEntity processServiceCall(BusEntity bo)

      Process a direct server call with no service invocation, if it is one.
      Parameters:
        `bo` - the object retrieved from the message bus.
      Returns:
        the response object with the reply data.

    - #### convertRequest

          public MethodInfo convertRequest(HttpEntity request)
                                    throws java.lang.Exception

      Convert a message request description into a `MethodInfo` object. This determines the request type (`XML-RPC or REST`) and parses as required.
      Parameters:
        `request` - the whole http request.
      Returns:
        the converted request message.
      Throws:
        `java.lang.Exception` - any error.

    - #### convertResponse

          protected void convertResponse(HttpEntity response,
                                         java.lang.Object reply)

      Configure the response object based on the message reply. If reply is null then non-blocking reply.
      Parameters:
        `response` - the response object.
        `reply` - method call reply, or null.

    - #### noContentResponse

          protected void noContentResponse(HttpEntity response)

      Set values in the response to indicate a no content reply.
      Parameters:
        `response` - the response object.

    - #### forbiddenResponse

          protected void forbiddenResponse(HttpEntity response)

      Set values in the response to indicate a forbidden request.
      Parameters:
        `response` - the response object.

    - #### notFoundResponse

          protected void notFoundResponse(HttpEntity response)

      Set values in the response to indicate a not found response.
      Parameters:
        `response` - the response object.

    - #### badRequestResponse

          protected void badRequestResponse(HttpEntity response,
                                            java.lang.String message)

      Set values in the response to indicate a bad request.
      Parameters:
        `response` - the response object.
        `message` - an additional message.