RPC Hello example

This example shows a very basic RPC example. It is created on a Linux system, but should work on other OS'es as well.

It is a modified version of the basic sample that is created when you use the

applicationCreator
command.
Click here for the source code.

How does it work?

Below, I describe the steps that I followed to create this demo:
  • create an application:
    applicationCreator com.lodgon.ajax.rpchello.client.Hello
    This step creates the default directories and files.
  • create an ant-file:
    projectCreator -ant rpchello
    This ant-file is used to compile the server-classes.
  • Create HelloService.java in com.lodgon.ajax.rpchello.client:
    package com.lodgon.ajax.rpchello.client;
    
    import com.google.gwt.user.client.rpc.RemoteService;
    
    public interface HelloService extends RemoteService {
    
      public String getHello (String question);
    
    }
    
    

    This interface will be called by the main client class.
  • Create the asyncinterface:
    For each interface, an asynchronous interfaces needs to be created, in this case com.lodgon.ajax.rpchello.client.HelloServiceAsync:
    package com.lodgon.ajax.rpchello.client;
    
    import com.google.gwt.user.client.rpc.AsyncCallback;
    
    public interface HelloServiceAsync {
    
      public void getHello (String s, AsyncCallback callback);
    
    }
    
    
  • Implement the interface in a server package:
    First, make sure a directory src/com/lodgon/ajax/rpchello/server is created. Inside this directory, create the HelloServiceImpl:
    package com.lodgon.ajax.rpchello.server;
    
    import com.google.gwt.user.server.rpc.*;
    
    public class HelloServiceImpl extends RemoteServiceServlet implements com.lodgon.ajax.rpchello.client.HelloService {
    
      public String getHello (String question) {
        return (question + question.toUpperCase());
      }
    
    }
    
  • Modify the Hello.java file that the applicationCreator created in com/lodgon/ajax/rpchello/client. The code you need is included in the source code.
  • Modify the Hello.gwt.xml file in com/lodgon/ajax/rpchello, by adding
    
    
  • compile the classes: ant -f rpchello.ant.xml
  • run the demo: Hello-shell

    The code generated by the gwt-compiler will use an RPC mechanism to call the getHello method on the server. Therefore, the code in com.lodgon.ajax.rpchello.server.HelloServiceImpl is exectured on the server, and may refer to your own backend classes. The code in com.lodgon.ajax.rpchello.client package is translated into Javascript, hence only the supported types can be used here.

    Comments? I would love to get feedback: johan at lodgon.com

    Back to my gwt-page