com.isomorphic.rpc

## Class RPCRequest

- java.lang.Object
- - com.isomorphic.base.Base
  - - com.isomorphic.rpc.BaseRequest
    - - com.isomorphic.rpc.RPCRequest

- All Implemented Interfaces:
    Committable, java.util.concurrent.Callable

      public class RPCRequest
      extends BaseRequest
      implements java.util.concurrent.Callable

  RPCRequest encapsulates the data sent by the client-side RPCManager. Use the server-side RPCManager class to parse an RPC HttpRequest and retrieve RPCRequest objects.
  See Also:
    `RPCManager`, `RPCResponse`

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RPCResponse` | `call()` Calls through to execute()
    `RPCResponse` | `execute()` If this request is a DMI request, executes the request through the DMI layer and returns an RPCResponse.
    `java.lang.String` | `getAppID()` If this is a DMI request, returns the appID against which this request is being made.
    `java.lang.Object` | `getData()` Retrieves the data sent by the client.
    `java.util.List` | `getMethodArguments()` If this is a DMI request, returns the arguments the client is passing to the DMI method.
    `java.lang.String` | `getMethodName()` If this is a DMI request, returns the name of the DMI method being invoked by the client.
    `java.lang.String` | `getServerObjectID()` If this is a DMI request, returns the ID of the ServerObject against which this request is being made.
    `boolean` | `isDMI()` Returns true if this request is a DMI request, false if it is a custom RPC.

    - ### Methods inherited from class com.isomorphic.rpc.BaseRequest

      `freeAllResources, getContext, getDsTransaction, getDSTransaction, getRPCManager, isClientRequest, setClientRequest, setContext, setDsTransaction, setDSTransaction, setRPCManager`

- - ### Method Detail

    - #### getData

          public java.lang.Object getData()

      Retrieves the data sent by the client. You'll need to cast the data to the appropriate type. The type is determined by the type of JavaScript object that you provided as the "data" parameter to RPCManager.send(). Here's the mapping of JS types to their corresponding Java types:

      JS Type | Java Type
      Object: {} | Map
      Array: [] | List
      String | String
      Number | Long|Double
      Boolean | Boolean
      Date | java.util.Date

      Note that the order of keys/values in the Maps created on the server is not guaranteed because JavaScript Object literals do not guarantee order.

    - #### isDMI

          public boolean isDMI()

      Returns true if this request is a DMI request, false if it is a custom RPC.
      Returns:
        true if this request is a DMI request, false if it is a custom RPC.

    - #### getAppID

          public java.lang.String getAppID()

      If this is a DMI request, returns the appID against which this request is being made. This appID maps directly to the the XML definition file as .app.xml.
      Returns:
        the appID
      See Also:
        `RPCRequest.isDMI()`

    - #### getServerObjectID

          public java.lang.String getServerObjectID()

      If this is a DMI request, returns the ID of the ServerObject against which this request is being made. Note that this field can contain either the ID of the ServerObject or the className of the ServerObject depending on what was passed by the client.

      If you're using the loadDMIStubs JSP tag and calling methods directly on the resulting JavaScript classes, the client will always send ServerObject ID if one exists on the ServerObject XML definition and the className if the ID does not exist.

      Returns:
        the ID or className of the ServerObject
      See Also:
        `RPCRequest.isDMI()`

    - #### getMethodName

          public java.lang.String getMethodName()

      If this is a DMI request, returns the name of the DMI method being invoked by the client. This maps directly to the 'name' attribute of the <method> definition under ServerObject->visibleMethods in your .app.xml.
      Returns:
        the DMI method name being invoked by the client.
      See Also:
        `RPCRequest.isDMI()`

    - #### getMethodArguments

          public java.util.List getMethodArguments()

      If this is a DMI request, returns the arguments the client is passing to the DMI method. The arguments are in the order provided by the client and have already been translated from JavaScript format to their equivalent Java types.

      Note that the DMI method invoked may declare that it takes additional, optional arguments that are provided by the DMI layer itself because they cannot be directly passed by the client such as the HttpServletRequest or the HttpSession objects.

      Returns:
        the appID
      See Also:
        `RPCRequest.getMethodName()`, `RPCRequest.isDMI()`

    - #### call

          public RPCResponse call()
                           throws java.lang.Exception

      Calls through to execute()
      Throws:
        `java.lang.Exception`
      See Also:
        `RPCRequest.execute()`

    - #### execute

          public RPCResponse execute()
                              throws java.lang.Exception

      If this request is a DMI request, executes the request through the DMI layer and returns an RPCResponse.

      If you're writing your own RPC endpoint to replace the provided IDACall, you can use this method in conjuction with isDMI() to preserve builtin DMI handling by writing a dispacher like so:

           if (rpcRequest.isDMI()) {
               rpcManager.send(rpcRequest, rpcRequest.execute());
           } else {
               // Custom RPC - do something with it...
           }

      Specified by:
        `execute` in class `BaseRequest`
      Returns:
        the RPCResponse as generated by the builtin RPC or DMI layer or an error RPCResponse if the request is not a DMI request.
      Throws:
        `java.lang.Exception`