Google Web Toolkit: AJAX Buzz Meets Real World Development : Page 4
With its Swing-like development framework and its awe-inspiring compiler/debugger, the Google Web Toolkit eases AJAX development.
by Gautam Shah
Jul 12, 2006
Page 4 of 5
Spotlight on GWT RPC
Figure 3 shows how the AJAX With Ease application uses GWT RPCs.
Figure 3. 'AJAX With Ease' Application Uses GWT RPCs
Let's go over each of the RPCs:
Remote Service interface: HelloService.java in the client folder extends GWT's RemoteService and represents the interface GWT's RPC plumbing needs to enable.
Asynchronous callback interface: HelloServiceAsync in the client folder is an asynchronous callback interface. The name of the class must be the service interface class's name followed by 'Async'. You do not need to implement this interface, as it is implemented by GWT in the background.
One of the peculiar aspects of GWT's RPC communication is that it is asynchronous, meaning when the client makes a call to the server it does not have to wait for the server to return the response immediately. The server later connects back to the client when it has data ready and supplies the client with the response data.
HelloConstants: This class is not required by GWT, but it is a necessary evil if you intend to both debug your applications in GWT Hosted Mode within Eclipse and deploy your applications in Web servers such as Apache Tomcat. The class defines a constant HELLO_SERVICE_URL that points to the Servlet path. When debugging applications, you need to use (uncomment) the line that sets HELLO_SERVICE_URL to /hello as expected by the GWT Hosted environment. However, when you are ready to build a WAR file to deploy to a Web server, you will need to use (uncomment) the line that sets HELLO_SERVICE_URL at runtime to a value equal to http://localhost:8080/ajaxwithease-0.1/hello when deployed in a Web server.
In addition to deploying your WAR file in a Web server, you will need to add Servlet mappings to web.xml as follows:
HelloRPC: A composite widget that consumes the HelloService service. It first retrieves a service endpoint for HelloService and then the endpoint entry point is set to the HelloServiceImpl Servlet path URL. An instance of AsyncCallback is created and passed as a parameter to the helloService.hello() function call. The onSuccess and onFailure of the AsyncCallback instance are overridden to perform AJAX With Ease application-specific processing:
public class HelloRPC extends Composite
HelloServiceAsync helloService = (HelloServiceAsync)
ServiceDefTarget endpoint = (ServiceDefTarget)
AsyncCallback callback =
public void onSuccess(Object result)
public void onFailure(Throwable caught)
When the server finishes processing and is ready to return data, it relies on AsyncCallback to callback (who else?) the client and invoke the onSuccess() method. Exceptions throw by the server are routed to the onFailure() method.
Your applications now have spiffy interfaces and fast data retrieval, but do they have any respect for history? With GWT, they will.