Hi again,

This enhancement is now in SVN trunk (future 2.1 M4):

      - ClientResource now respects any change to the clientInfo preferences
        when using dynamic proxies (via wrap() for example). It only overwrites
        them if the default preferences state (empty lists) is found at 
invocation
        time. 

Note that in this case, conversion hints provided via annotation values such as 
"gwt" are ignored.

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg
Noelios Technologies ~ http://www.noelios.com


-----Message d'origine-----
De : Jerome Louvel [mailto:[email protected]] 
Envoyé : mardi 12 avril 2011 15:13
À : 'discuss'
Objet : RE: Cannot select MediaType when using ClientResource.wrap

Hi Christoph,

It should be possible to override those settings by using a value in your 
Restlet annotations such as @Get("gwt") or @Get("jos"). For the latter case, 
you need to register this extension into the metadataService of your 
application:

   getMetadataService().addExtension("jos", MediaType.APPLICATION_JAVA_OBJECT);

This isn't fully satisfactory as you need to touch the annotated interface. A 
better approach would be to override ClientResource and extend the 
handle(Request) method.

In this extended method, you can customize/rewrite the clientInfo preferences. 
This will be executed after the annotation/proxy processing logic. Let me know 
if this doesn't work.

I'm also exploring in 2.1 a smarter default logic that would respect any 
predefine client preference in the prototype request wrapped by ClientResource. 
Stay tuned!

Hope this helps,
Jérôme


-----Message d'origine-----
De : christoph.dietze [mailto:[email protected]] 
Envoyé : mardi 12 avril 2011 13:25
À : [email protected]
Objet : Cannot select MediaType when using ClientResource.wrap

Hello,

I set up a server which can serve a resource in both APPLICATION_JAVA_OBJECT, 
as well as APPLICATION_JAVA_OBJECT_GWT representation.
I can test this using
new
ClientResource("http://blockedcontent:8888/service/hello";).get(MediaType.APPLICATION_JAVA_OBJECT);
and
new
ClientResource("http://blockedcontent:8888/service/hello";).get(MediaType.APPLICATION_JAVA_OBJECT_GWT);

However, when using the ClientResource.wrap() I cannot select the MediaType.
- when org.restlet.ext.gwt-2.0.6.jar is in the client's classpath, the accepted 
mediatypes of the request always are 
[application/x-java-serialized-object+gwt:1.0,
application/x-java-serialized-object:1.0,
application/x-java-serialized-object+xml:1.0]

- when org.restlet.ext.gwt-2.0.6.jar is not in the client's classpath, the 
accepted mediatypes are [application/x-java-serialized-object:1.0,
application/x-java-serialized-object+xml:1.0]

Setting the accepted mediatypes as described here does not work 
http://restlet-discuss.1400322.n2.nabble.com/Restlet-Server-GWT-restlet-client-tp6200833p6200833.html
i.e., I tried both
ClientResource cr = new
ClientResource("http://blockedcontent:8888/service/hello";);
cr.getClientInfo().setAcceptedMediaTypes(
        Arrays.asList(new Preference(MediaType.APPLICATION_JAVA_OBJECT)));
ContactResource resource = cr.wrap(ContactResource.class); Contact contact = 
resource.retrieve(); // ...

and
ClientResource cr = new
ClientResource("http://blockedcontent:8888/service/hello";);
ContactResource resource = cr.wrap(ContactResource.class); ClientProxy p = 
(ClientProxy) resource; 
p.getClientResource().getClientInfo().setAcceptedMediaTypes(
        Arrays.asList(new Preference(MediaType.APPLICATION_JAVA_OBJECT)));
Contact contact = resource.retrieve();

But I get always get the GWT representation when the gwt jar is in the 
classpath. This fails to deserialize since I call from a Java program, not a 
GWT app. I want to get the java object mediatype.

Thus, it seems that the client's accepted media types of a wrapped resource are 
solely derived from the libraries on the classpath and cannot be overwritten.
So,how can I use a java serialized object mediatype with ClientResource.wrap, 
even though the gwt jar is in the classpath?


--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Cannot-select-MediaType-when-using-ClientResource-wrap-tp6264755p6264755.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2719056

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2719091

Reply via email to