My favorites | Sign in
Project Logo
                
Search
for
Updated Dec 03, 2007 by piotr.dobrowolski
Labels: Featured, Phase-Deploy
Readme  
Quick startup guide

Introduction

Here's a short introduction how to use gwt-hermes.

Details

1. download gwt-hermes.jar

2. add Hermes to your module file add a section that will look like this:

<inherits name="com.overto.gwt.hermes.Hermes" />

3. declare an interface of JSON service you want to call Exactly like in case of GWT RPC you have to define an interface of your service, i.e.:

public interface TestService extends RemoteJSONService {
  public int testMethod(String param);
}

PLEASE NOTE:

  • you have to extend RemoteJSONService, not RemoteService
  • this interface must match your server side interface

  • supported param and return types include: primitives, arrays of primitives, classes (must have public parameterless interface) and arrays of classes. Primitive type wrappers (Integer, Boolean etc.) and collections are not supported.

classes have to expose properties by public getters and setters

4. declare an async interface for your service Again exactly the same as in GWT RPC:

public interface TestServiceAsync {
  public void testMethod(String param, AsyncCallback callback);
}

PLEASE NOTE:

  • this interface name has to be your service name + Async
  • all methods in this interface should have return type void
  • the last param of every method must be of type AsyncCallback

5. use GWT.create to create async version of your interface

TestServiceAsync testService = (TestServiceAsync) GWT.create(TestService.class);

6. use JSONServiceDefTarget to configure service address Once again - exactly like in GET RPC:

JSONServiceDefTarget serviceTarget = (JSONServiceDefTarget) testService;	
serviceTarget.setServiceEntryPoint("http://foo.com/json");
serviceTarget.setAppendMethodNameToAddress(false);

PLEASE NOTE:

  • the last line is specific to JSON RPC. You can define if method name should be appended to called URL, i.e. if this param would be true in the example above and we would call testMethod, the requested URL would be: http://foo.com/json/testMethod. If this param is set to false the passed entry point is not modified.
  • you can set user name and password by using JSONServiceDefTarget methods

7. call your service Exactly the same syntax as in GWT here:

testService.testMethod("a", new new AsyncCallback() {

				public void onFailure(Throwable caught) {
					Window.alert(caught.toString());
					
				}

				public void onSuccess(Object result) {
					Window.alert(result.toString());
				}
				
			});

The result can be cast to the result type of the method.

Enjoy!


Comment by batl...@lovelysystems.com, Sep 02, 2008

seems like there is a typo:

testService.testMethod("a", new new AsyncCallback?() {

should be:

testService.testMethod("a", new AsyncCallback?() {


Sign in to add a comment
Hosted by Google Code