RPC Dispatch
Last updated
Was this helpful?
Last updated
Was this helpful?
Remote Procedure Call Dispatcher is a client server communication protocol. It serializes and deserializes the objects being sent over the wire.
##Reference
The example snippets are being taken from this Archetype .
##Overview Setting up the dispatching requires a few parts:
Guice or Spring
Client request. .
Action class. .
Result class. .
Server dispatch handler. .
Optional server dispatch server handler validator. .
###More Action and Result Examples
First of, you can start by reading Guice's guide if you're unfamiliar with it.
Basice Guice setup with web.xml
GuiceServletConfig
Then you need to either create this class or at the serve call to your existing ServletModule
Coming soon
##Client Request
Setting up the client request requires that the DispatchAsync
be available which is injected in the constructor.
In this example AsyncCallbackImpl<T>
implements AsyncCallback<T>
. Both can be used. The advantage of using AsyncCallbackImpl<T>
allows the application to globally catch onFailures. See more below.
##Shared Action Action designates the call taken place and carries the object(s) to the server. The action is shared with both the client and server and the encapsulated objects must be serializable. The contained objects must implement IsSerializable
or Serializable
.
##Shared Result Result designates the response to the call and carries the objects(s) back to the client. The result is shared with both client and server and the encapsulated objects must be serializable. The contained objects must implement IsSerializable
or Serializable
.
##Catching onSuccess or onFailure Globally Catching the onSuccess or onFailure for each request can be done by extending AsyncCallback<T>
.
AsyncCallback<T>
class can be used and it looks like this:
##Notes on implementing a ActionHandler There are essentially two ways to implement an ActionHandler for your Actions/Results
Method 1: Simply implement the com.gwtplatform.dispatch.server.actionhandler.ActionHandler interface
##Configuring Actions/ActionHandlers on the Server Before you can start using your ActionHandlers on the server. You need to tell Guice which ActionHandler is responsible for responding to which Action. This is done in the Guice ServerModule
##Configuring the Dispatch Module on the Client Before you can start using the RPC Dispatcher you have to install an implementation of the Dispatcher in your client gin configuration. In most cases, the default RpcDispatchAsyncModule
(included in GWTP) will be sufficient to install in the ClientModule
.
Then a request can be setup like this. .
Example Action. .
Example Result. .
Implementing AsyncCallback<T>
will allow you to catch the onFailure and/or the onSuccess. In this example the onFailure is caught so it could be used to notify the user of the failure. .
Method 2: If you have been browsing the GWTP examples, you will notice that the ActionHandlers extends a AbstractAction class rather than implementing the ActionHandler like the above example. This is just a base class implementing the com.gwtplatform.dispatch.server.actionhandler.ActionHandler interface and doing some wire up to reduce boilerplate. Here is an example of creating a base class implementing the ActionHandler class: