Invoke GWT RPC services deployed on Google App Engine

SyncProxy allows you to invoke GWT RPC services from pure Java (no JSNI) code.
From version 0.1.2, you can invoke your RPC services deployed on AppEngine.

This post shows you how to use this new feature of SyncProxy.

The service interface

For example, we have an helloApp application and a RPC service GreetingService

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
  String greetServer(String name);
}

And the service implementation is as below

public class GreetingServiceImpl extends RemoteServiceServlet
      implements GreetingService {
  public String greetServer(String name) {
    return "Hello, " + name;
  }
}

Assume the application is deployed on AppEngine and the servlet URL is configured at http://example.appspot.com/helloApp/greet

Java client code

Create new proxy instance for the service interface:

private static GreetingService rpcService =
  SyncProxy.newProxyInstance(GreetingService.class,
        "http://example.appspot.com/helloApp", "greet");

This will create a new proxy instance which implements your GreetingService.

Then invoke the service method.

String result = rpcService.greetServer("SyncProxy");

Secure your service

We modify our service implement which enforce user to login to access to the service:

public class GreetingServiceImpl extends RemoteServiceServlet
      implements GreetingService {
  public String greetServer(String name) {
    // implement the security
    UserService userService = UserServiceFactory.getUserService();
    if (!userService.isUserLoggedIn()){
      throw new RuntimeException("Access Denied");
    }
    // We can also enforce only admin user can access to the service
    /*
    if (!userService.isUserAdmin()){
      throw new RuntimeException("Access Denied");
    }
    */

    return "Hello, " + name;
  }
}

Invoke the secured service

Before invoke the secured service, you have to login to the application.

SyncProxy.loginGAE("https://example.appspot.com",
    "http://example.appspot.com/helloApp/greet",
    "yourusername@gmail.com", "yourpassword");

Then invoke the service method.

String result = rpcService.greetServer("SyncProxy");

Download SyncProxy

Get SyncProxy (with source code) at http://code.google.com/p/gwt-syncproxy/

This entry was posted in AppEngine, GWT and tagged , , . Bookmark the permalink.

4 Responses to Invoke GWT RPC services deployed on Google App Engine

  1. Jeff Schnitzer says:

    This is very cool! Any metrics on how it compares, performancewise, to Hessian, SOAP, or JAX-RS web services?

  2. dilbert says:

    Does this library work on android?

  3. jogo says:

    First of all, great work! I’m trying to invoke remote service on GAE (greetServer), but no luck.

    Which version of GWT is SyncProxy compatible with? I’m using the latest version of GWT (2.3.0) and I see some serialization exceptions in the log.

  4. Trung says:

    There are no Benchmarks now. However, GWT RPC is NOT a generic, language-independent client-server communication.

    When developing GWT applications, the standard and straightforward communication between client (code run on Browser) and server (the service implementation) is GWT RPC.

    SyncProxy provides additional communication channel (Java client) to the existing GWT RPC service.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>