Hi Thierry,
First, I'm new to GWT and Restlet, so apologies if my questions are not
relevant.
I already read about the on-line documentation (especially pointers you gave
me) but I still can't solve my issues.
I have an already running REST service at http://localhost:/components.
I want to access it with GWT2 with the help of restlet. So, I wrote a simple
GWT app (MyApp, see below) to retrieve data from this service.
My GWT app is run with GAE at http://localhost:8890/.
I'm able to configure this GWT project by adding restlet jars in WEB-INF/lib
but I still have some issues/questions.
1/ By using the Myapp class listed below, I cannot see any message on the web
page. In another way, if the same code is launched by a clickHandler defined on
a button, I can see the trace (text variable). So, can't we do calls to rest
services at the application loading?
2/ By using the version with a button and aclick handler, JsonRepresentation is
an empty array and JSONObject object is null. I got no error messages saying
that the request cannot be proceed, so I don't understand what is happening.
3/ The redirector seems to work, if I visit http://localhost:8890/components I
got the response formated in json.
If I use a router, it doesn't work. But perhaps I'm not using redirector in the
right way.
By reading the documentation, I don't understand which Redirector mode to use?
Do I need to use a router?
My first need is to redirect all calls to http://localhost:8890/components to
http://localhost:/components. My future need will be to redirect
http://localhost:8890/host/components to http://host:/components
4/ My last question is about resources. the Rest Service send me back resources
marshalled in json. I would like to have my json automatically unmarshalled in
a resource object. I saw
http://www.restlet.org/documentation/2.0/tutorial#part12.
Is it the way to do that? It seems to be for the server part. What for the
client part?
Thank you very much for your patience and your availability.
It's really handsome.
Regards,
Christophe.
-
public class Myapp implements EntryPoint {
public void onModuleLoad() {
ClientResource r = new
ClientResource(http://localhost:8890/components;);
// Set the callback object invoked when the response is received.
r.setOnReceived(new Uniform() {
public void handle(Request request, Response response) {
String text;
// Get the representation as an JsonRepresentation
JsonRepresentation rep = new JsonRepresentation(
response.getEntity() );
text += JsonRepresentation = + rep.toString();
// Displays the properties and values.
try {
JSONObject object = rep.getValue().isObject();
text += JSONObject = + object;
if (object != null) {
for (String key : object.keySet()) {
RootPanel.get(callButtonContainer).add( new
HTML(key + : + object.get(key)) );
}
}
} catch (IOException e) {
e.printStackTrace();
}
RootPanel.get(defaultContainer).add( new HTML(text) );
}
});
}
}
public class MyRedirector extends Application {
@Override
public synchronized Restlet createInboundRoot() {
// Create a root router
Router router = new Router(getContext());
// Create a Redirector to Google search service
String target = http://localhost:{rr};;
Redirector redirector = new Redirector(getContext(), target,
Redirector.MODE_CLIENT_TEMPORARY);
// Attach the extractor to the router
// router.attach(/redirectme/, redirector);
// return router;
return redirector;
}
}
web-app
servlet
servlet-nameadapter/servlet-name
servlet-classorg.restlet.ext.gwt.GwtShellServletWrapper/servlet-class
init-param
param-nameorg.restlet.application/param-name
param-valueorg.myorg.server.MyRedirector/param-value
/init-param
/servlet
servlet-mapping
servlet-nameadapter/servlet-name
url-pattern/*/url-pattern
/servlet-mapping
/web-app
--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2435155