Friday, October 1, 2010

Tip on Specifying GWT-RPC Remote Service Relative Path

Robert Hanson's excellent introduction to a GWT-RPC application got me started, but I bumped into this:


com.google.gwt.user.client.rpc.StatusCodeException:
HTTP ERROR: 404

NOT_FOUND

RequestURI=/relative-path


My fix was to remove the leading slash in the value for setServiceEntryPoint, or to specify it as an annotation on the service interface (again, without a leading slash, as per the example in this Google article). Here's my EntryPoint implementation:


public class MyApplication implements EntryPoint {

public void onModuleLoad() {

MyServiceAsync svc = (MyServiceAsync) GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) svc;
endpoint.setServiceEntryPoint("relative-path"); // omit leading slash!

AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result) {
RootPanel.get().add(new HTML(result.toString()));
}

public void onFailure(Throwable ex) {
RootPanel.get().add(new HTML(ex.toString()));
}
};

svc.myMethod("Do some Stuff...", callback);
}
}

Alternately, I omit the ServiceDefTarget stuff in the EntryPoint and instead specify it in the service interface:


@RemoteServiceRelativePath("relative-path")
public interface MyService extends RemoteService
{
public String myMethod(String s);
}

I prefer this approach since it's more consistent with a web services approach.

No comments:

Post a Comment