Making Remote Procedure Calls (RPC) with Google Web Toolkit (GWT)

GWT provides framework for exchanging Java objects between Client and Server components of web application over HTTP. In GWT, RPC service is defined by an interface that extends the GWT RemoteService Interface.

Creating GWT Service

In order to define RPC, you need to write three components

  1. Define Interface in Client Side for your Service that extends RemoteService and list RPC method call.
  2. Define Service Class in Server side that extends RemotServiceServlet.
  3. Add Servlet information to the web.xml file
  4. Add @RemoteServiceRelativePath information to the Interface class on the client side.
  5. Define an Asynchronous interface to the service to be called from the client-side code.

Calling GWT Service

For calling GWT Service you need to instantiate a service interface using GWT.create();

We need to specify service entry point URL for the service using ServiceDefTarget

And finally create a AsynCallback object so that client can be notified when service call is completed.

And at the end Make a call to the service with specific callback attached to it.