I recently had to implement an anonymous chat client using a Jabber backend in GWT. No problem, I just implemented a RemoteServiceServlet with the necessary methods, and then a GWT client which polls the service for data.
Next, I got a request about adding the same functionality to an Eclipse RCP based application. I now had the choice of either implementing the service again using REST, WebServices, or something entirely different, but it would be much easier if I just called the GWT service directly, which leads me to the real purpose of this post: Using a proxy pattern, I've created the necessary mechanisms to make this posssible.
It works like this:
You create a service implementation. Copy any interfaces, exception classes, and shared classes to the client project, and add gwt-java.jar to the classpath. Access the remote service like this:
-
import dk.contix.gwt.java.GWTJava;
-
import dk.contix.gwt.java.example.ExampleService;
-
-
public class Test {
-
public void callService() {
-
ExampleService service = (ExampleService) GWTJava.create(
-
ExampleService.class,
-
"http://localhost:8080/example/exampleService");
-
service.voidTest();
-
}
-
-
}
Of course, you are bound by the same restrictions as when using the service from Javascript: Only classes which implement IsSerializable can be serialized, they must have empty constructors, and so on. But besides that, this is more or less what you need to do.



