Hi,
I am struggling to get the Restlet GWT to query my rest service (provided by
resteasy, but I can't change this implemenation). I made a minimal example
which calls the rest service (stripped some GWT code), which unfortunately does
not work.
public class My_frontend_gwt implements EntryPoint {
public void onModuleLoad() {
final Button myButton = new Button("My");
myButton.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
final Client client = new Client(Protocol.HTTP);
client.get("http://localhost:8088/com.myapp/rest/books/books.xml",
new Uniform() {
public void handle(Request request, Response
response, Uniform callback) {
try {
nameField.setText(response.getEntity().getText());
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
});
}
When I invoke the rest service with a curl call, I get (curl
http://localhost:8088/com.myapp/rest/books/books.xml):
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><collection><book><id_>1</id_><title>test1</title></book><book><id_>2</id_><title>test2</title></book></collection>
I am sure the service is also called from the GWT applications, since I see a
hibernate query log passing:
Hibernate: select book0_.id_ as id1_84_, ... from Book book0_
But the entitiy in the Response object in the handle method equals null, which
causes the getText() method to fail (I also tried getEntityAsXml() instead of
getEntity()). So, the results are not fed back into the response, in my opinion.
I am running this test with org.restlet.jar from restlet-gwt-2.0m4, which is
the only lib in my classpath. The imports I am using are
import org.restlet.Client;
import org.restlet.Uniform;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;
When using org.restlet.gwt-2.0-M3.jar from the maven repository and the
following snippet, the entity in my Response is still null, and the GWT hosted
mode provides me with the error shown below.
import org.restlet.gwt.Callback;
import org.restlet.gwt.Client;
import org.restlet.gwt.data.Protocol;
import org.restlet.gwt.data.Request;
import org.restlet.gwt.data.Response;
public class My_frontend_gwt implements EntryPoint {
public void onModuleLoad() {
final Button myButton = new Button("My");
myButton.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
final Client client = new Client(Protocol.HTTP);
client.get("http://localhost:8088/com.myapp/rest/books/books.xml",
new Callback() {
public void onEvent(Request request,
Response response) {
nameField.setText(response.getEntityAsXml().getText());
}
});
}
});
}
Error with stacktrace:
[ERROR] Uncaught exception escaped
java.lang.NullPointerException: null
at com.myapp.gwt. My_frontend_gwt $1$1.onEvent(My_frontend_gwt.java:75)
at
org.restlet.gwt.engine.http.HttpClientConverter$1.onEvent(HttpClientConverter.java:383)
at
org.restlet.gwt.engine.http.GwtHttpClientCall$2.onResponseReceived(GwtHttpClientCall.java:234)
at
com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at
com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at
com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at
com.google.gwt.dev.shell.mac.MethodDispatch.invoke(MethodDispatch.java:71)
at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2909)
at
com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at
com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
So, as a starter, I would like to get to the plain xml result in my response
(which is now giving me the NullPointerException). But it would be even better
if I can get an automatic translation between the xml result and a set of java
pojo's that I will make available for GWT, analogous to what Resteasy does to
go from my jpa model to the xml representation (with XmlAdapters for the
classes that have no default serialization in jaxb).
A long post, but I could not bring the message without this elaboration. Let me
know if I need certain aspects need more clarification.
Thanks,
Johannes
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2392787