Thank You VERY VERY much Thierry : it works. Just one thing, it works, as long as the application doesn't run in hosted mode. (I'm afraid I made somme test in these environment).
Thanks. ________________________________ De : Thierry Boileau [mailto:thierry.boil...@noelios.com] Envoyé : mercredi 23 mars 2011 18:56 À : discuss Cc : ROSTAING TAYARD Philippe Objet : Re: Restlet Server, GWT, restlet client Hello Philippe, the main problem is that the GWT *extension* for the server side (jse, jee, gae edition), is able to serialize an objet sent to a GWT client, and deserialize an object sent by a GWT client. It is not able to deserialize an object sent to a GWT client... I remember that these formats are distinct. That is to say, it can not be used to deserialize the entity you get from the server, in your case... Having said that, you may think why do the server sent automatically such representation? When wrapping a ClientProxy resource, the list of accepted media types is computed according to the list of converters available in the classpath, just because these converters will cope with the entity. As a side note, the order of declaration of the converters in the classpath is important, because the related preferences have the same weight, so the first one will be chosen. I hope the explanation is clear enough, feel free to ask for more details. Now, as a workaround, you can change the order of the classpath, or remove the GWT converter from your groovy client project, or update the computed preferences: ClientResource clientResource = new ClientResource("http://localhost:8080/contacts/123"); ContactResource cr = clientResource.wrap(ContactResource.class); ClientProxy p = (ClientProxy) cr; p.getClientResource().getClientInfo().setAcceptedMediaTypes(Arrays.asList(new Preference<MediaType>(MediaType.APPLICATION_JAVA_OBJECT))); I recognize this is a bit tricky. We have to think to simplify this. Best regards, Thierry Boileau Hi All, I'm totally newbie, and this is what I want to do with restlet : - have a restlet server serving a GWT application - have a restlet client accessing this server Instead of making a long discussion, I enclosed an example (I don't know where I find the original source). When I request with curl, I have the folowing answers : Default : curl localhost:8080/contacts/123 --> //OK[8,7,0,6,5,4,3,2,40,1,["fr.compagniedesalpes.contact.model.Contact/792528633","Scott","fr.compagniedesalpes.contact.model.Address/3727213108","Mountain View","USA","10 bd Google","20010","Tiger"],0,6] XML: curl -H "Accept: application/xml" localhost:8080/contacts/123 --> <?xml version="1.0" encoding="UTF-8" ?> <fr.compagniedesalpes.contact.model.Contact> <firstName>Scott</firstName> <lastName>Tiger</lastName> <homeAddress> <line1>10 bd Google</line1> <zipCode>20010</zipCode> <city>Mountain View</city> <country>USA</country> </homeAddress> <age>40</age> JSON : curl -H "Accept: application/json" localhost:8080/contacts/123 --> {"fr.compagniedesalpes.contact.model.Contact":{"firstName":"Scott","lastName":"Tiger","homeAddress":{"line1":"10 bd Google","zipCode":20010,"city":"Mountain View","country":"USA"},"age":40}} GWT : curl -H "Accept: application/x-java-serialized-object+gwt" localhost:8080/contacts/123 --> //OK[8,7,0,6,5,4,3,2,40,1,["fr.compagniedesalpes.contact.model.Contact/792528633","Scott","fr.compagniedesalpes.contact.model.Address/3727213108","Mountain View","USA","10 bd Google","20010","Tiger"],0,6] Everything seems fine, but when I request with a little groovy script, I've got an exception : Script : package fr.compagniedesalpes.contact import org.restlet.resource.ClientResource ClientResource clientResource = new ClientResource("http://localhost:8080/contacts/123") ContactResource cr = clientResource.wrap(ContactResource.class) Contact contact = cr.retrieve() clientResource.release() println contact.age println contact.firstName println contact.homeAddress --> Exception : java.lang.NumberFormatException: Expected type 'int' but received a non-numerical value: //OK[8,7,0,6,5,4,3,2,40,1,["fr.compagniedesalpes.contact.model.Contact/792528633","Scott","fr.compagniedesalpes.contact.model.Address/3727213108","Mountain View","USA","10 bd Google","20010","Tiger"],0,6] at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.getNumberFormatException(ServerSerializationStreamReader.java:825) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.readInt(ServerSerializationStreamReader.java:491) at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamReader.readObject(AbstractSerializationStreamReader.java:104) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader$ValueReader$8.readValue(ServerSerializationStreamReader.java:137) at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamReader.deserializeValue(ServerSerializationStreamReader.java:384) at org.restlet.ext.gwt.ObjectRepresentation.getObject(ObjectRepresentation.java:116) at org.restlet.ext.gwt.GwtConverter.toObject(GwtConverter.java:141) at org.restlet.service.ConverterService.toObject(ConverterService.java:158) at org.restlet.resource.UniformResource.toObject(UniformResource.java:644) at org.restlet.resource.ClientResource$1.invoke(ClientResource.java:1658) It seems that the client did not understand the response ? Why ? The server libraries are : com.thoughtworks.xstream.jar gwt-servlet.jar javax.xml.stream.jar org.codehaus.jettison.jar org.restlet.ext.gwt.jar org.restlet.ext.servlet.jar org.restlet.ext.xml.jar org.restlet.ext.xstream.jar org.restlet.jar <-- j2se edition org.restlet.jar <-- gwt edition The client libraries are : org.restlet.ext.json.jar <-- gwt edition org.restlet.ext.xml.jar <-- gwt edition org.restlet.jar <-- j2se edition org.restlet.jar <-- gwt edition I really read a LOT of documentation, but I did not find the answer. What desperate my most is the fact that I saw it working. If someone can do something for me, I will appreciate. At least, all the librairies come from the 2.0.5 Restlet version, and I use gwt 2.0.1. Thanks. ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2713482 ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2714688