GWT RPC Lab 1
Create a Google Web Application
- In the LDS Tech IDE, go to File | New | Web Application Project
- In the Project Name: field, enter "GWT RPC".
- In the Package: field, enter "org.lds.gwt.rpc".
- Uncheck the Use Google App Engine check box.
- Click Finish.
This will create a new web application that has both client and server side components. The web application that gets created also contains a sample RPC service.
Examine the Sample RPC Service
- Open the Java source file /GWT RPC/src/org/lds/gwt/rpc/client/GreetingService.java. Notice how it extends RemoteService and has the @RemoteServiceRelativePath.
- Open the Java source file /GWT RPC/src/org/lds/gwt/rpc/client/GreetingServiceAsync.java. Compare the greetServer method with the one in the GreetingService class.
- Open the Java source file /GWT RPC/src/org/lds/gwt/rpc/server/GreetingServiceImpl.java to see the service implementation.
- Open the web descriptor /GWT RPC/war/WEB-INF/web.xml. Line 9 starts the servlet declaration. Line 14 starts the servlet mapping. Notice how the first part of the url-pattern matches the module name specified in the module descriptor and the second part matches the value of the @RemoteServiceRelativePath annotation in the remote service interface.
- Open the Java source file /GWT RPC/src/org/lds/gwt/rpc/client/GWT_RPC.java. This is the entry point for the GWT module. Go to line 35 to see how the client async interface is instantiated using deferred binding. Go to line 122 to see how the async interface is used to invoke the RPC service.
Run the Sample Application
- Right click on the project and select Run As | Web Application. This will start the GWT shell embedded in Eclipse. You should see a new Eclipse view called Development Mode open instead of the GWT Shell as we saw in previous labs.
- Copy the URL from the Development Mode view into your web browser.
- Test the demo app and make sure everything works.
Create Your Own Service
- Create an interface that extends RemoteService. Model this interface after GreetingService. Put at least one method in your service. This method should do something simple like return a string.
- Create a corresponding async interface. Model this interface after GreetingServiceAsync. This method must match the name of your newly created remote service interface with the word "Async" appended to it.
- Create an implementation of your service interface. Model this implementation after GreetingServiceImpl.
- Create a mapping for your service in web.xml.
- Add some code to the entry point that instantiates your service and invokes it.
- Test your service.
If you finish this lab early, go back and add multiple methods to your remote service.