After some difficulties I got a project working, which consists of a simple GWT application with a Restlet backend. The application consists of four OSGi bundles, which work inside eclipse PDE. Also, all of these modules and their dependencies are declared using Maven 2.
Overview:
The user interface is based on google‘s standard project from the google eclipse plugin.
The button Ping triggers a very simple REST call to the server (based on example from Restlet documentation)
tstBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ClientResource r = new ClientResource(“/ping”);
r.setOnResponse(new Uniform() {
public void handle(Request request, Response response) {
try {
tstBtn.setText(response.getEntity().getText());
} catch (IOException e) {
e.printStackTrace();
}
}
});
r.get();
}
});
Clicking this button should result in the caption of the button being filled with a response from the server.
The server resource is as following:
public class PingResource extends ServerResource {
@Get(“txt”)
public String toText() {
StringBuilder sb = new StringBuilder(“Restlet server alive. Method: “);
sb.append(getRequest().getMethod());
ChallengeResponse challengeResponse = getRequest()
.getChallengeResponse();
if (challengeResponse != null) {
sb.append(“/ Auth. scheme: “);
sb.append(challengeResponse.getScheme());
}
return sb.toString();
}
}
The send button should work in the same way as in the google example; only that the remote procedure call is facilitated using Restlet.
GWT Client:
GreetingServiceAsync r = GWT.create(GreetingServiceAsync.class);
r.getClientResource().setReference(“/services/greet”);
r.getClientResource().getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JAVA_OBJECT_GWT));
r.greetServer(new Name(nameField.getText()), new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
dialogBox
.setText(“Remote Procedure Call – Failure”);
serverResponseLabel
.addStyleName(“serverResponseLabelError”);
serverResponseLabel.setHTML(SERVER_ERROR+“<br/>”+caught.getMessage());
dialogBox.center();
closeButton.setFocus(true);
}
@Override
public void onSuccess(String result) {
dialogBox.setText(“Remote Procedure Call”);
serverResponseLabel
.removeStyleName(“serverResponseLabelError”);
serverResponseLabel.setHTML(result);
dialogBox.center();
closeButton.setFocus(true);
}
});
Restlet Server:
public class GreetingServiceServerResource extends ServerResource implements GreetingService {
@Override
public Representation handle() {
CompositeClassLoader customCL = new CompositeClassLoader();
customCL.addClassLoader(Thread.currentThread().getContextClassLoader());
customCL.addClassLoader(Name.class.getClassLoader());
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(customCL);
Representation rep = super.handle();
Thread.currentThread().setContextClassLoader(oldCL);
return rep;
}
@Override
@Post
public String greetServer(Name name) throws IllegalArgumentException {
System.out.println(“Name submitted: “+name.name);
return “Welcome “+name.name+” from Restlet!”;
}
}
OSGi Bundles:
Under equinox, the following modules were required:
id State Bundle
0 ACTIVE org.eclipse.osgi_3.5.2.R35x_v20100126
Fragments=2, 3
2 RESOLVED org.eclipse.persistence.jpa.equinox.weaving_1.1.3.v20091002-r5404
Master=0
3 RESOLVED javax.transaction_1.1.1.v201002111330
Master=0
17 ACTIVE org.hamcrest.core_1.1.0.v20090501071000
18 ACTIVE thrdGWTUser_0.0.2.SNAPSHOT
19 ACTIVE javax.servlet_2.5.0.v200806031605
21 ACTIVE org.junit4_4.5.0.v20090824
41 ACTIVE org.eclipse.osgi.services_3.2.0.v20090520-1800
49 ACTIVE thrdRestletGWT_0.0.2
50 ACTIVE thrdRestletExtSimple_0.0.2
51 ACTIVE zzSampleGWTClient_0.0.2
52 ACTIVE zzSampleRestletServer_0.0.2
Lessons Learned and Helpful Resources
– org.restlet.ext.simpleframework is deprecated and should not be used
– the current version for the Maven GWT plugin is 1.3-SNAPSHOT or 1.3.1.google. My projects worked with 1.3-SNAPSHOTS at the end.
– Restlet might have problems with transporting String objects. Therefore I encapsulated the String with the username in a Name object.
– Classloaders: GWT RPC, OSGi and Restlet
– GWT Module XXX not found in project sources or resources.
– CLAP Protocol in Restlet and OSGi
– GWT + OSGi + Maven
– Restlet Server: OSGi and Maven
– Deployment of GWT Applications (Part 2)
– Maven, GWT and Eclipse Quick start (Part 1)
Hi, I am looking for a proof of concept of GWT, Restlet and Maven and found your article: https://nexnet.wordpress.com/2010/10/06/proof-of-concept-gwt-restlet-osgi-and-maven/
Can I download a zip with all the files from somewhere, I would very much like to test this myself.
Thanks,
Magnus
Sure, it’s sent to your email address. Thanks Max
Can U send me the compressed file, too? It would be very nice, thx a lot.
Thanks and best regards,
k
Could you please send me POC on Restlet and maven…
Sure, it’s sent.
I also would like have an access to this POC’s sources…
Thanks 🙂
hi, Can U send me the sources on gwt+restlet+ogsi,
Thanks
Ray
hi, Can U send me the sources on gwt+restlet+ogsi,
Thanks
Hi Ray, Sent you parts of the source files I found. However, restlet/gwt versions etc. should be outdated by now. I have a newer post just on Restlet (https://nexnet.wordpress.com/2011/09/02/restlet-quickstart/). Maybe it’s best to start from there and add the GWT and OSGi part to the example given there!
For the OSGi part, have a look here: https://sites.google.com/site/eclipsemaven/
Hi,
is there any chance to get the source code?
Thnx
Sent the files to your email!
can you share with me your project.
Thanks so much