Hi Norm,

Could you explain why you want to restrict the accepted media types in this 
case (Restlet annotated interfaces)?

Another workaround is to add an annotation value such as @Get("xml") to enforce 
XML usage. Otherwise, we plan to add a per-application control of the converter 
used/excepted and their relative order in next Restlet version. Right now this 
setting is global to the Restlet engine.

Best regards,
Jerome
--
http://www.restlet.org
http://twitter.com/#!/jlouvel




-----Message d'origine-----
De : Norm Deane [mailto:[email protected]] 
Envoyé : mardi 22 novembre 2011 18:26
À : [email protected]
Objet : RE: Re: ClientResource.wrap Response Variants?

Yes but when using the ClientResource.wrap approach you're abstracted from all 
of that (the Request, Response, ClientInfo, etc) and the wrap method creates an 
anonymous InvocationHandler/Dynamic Proxy that sets the ClientInfo for you like 
so...

// Updates the client preferences
List<org.restlet.representation.Variant> responseVariants = 
annotation.getResponseVariants(getMetadataService(),
getConverterService());

if (responseVariants != null) {
   request.setClientInfo(new ClientInfo(responseVariants)); }

So even if I had previously set my media type preferences on the Request 
(through ClientResource.setClientInfo()) the anonymous InvocationHandler 
created by wrap will override them and specify all media types that the 
ConverterService is capable of handling. 

Norm


> Hello. The correct way to restrict accepted media types for a client
> (read: in an HTTP request) is by means of the HTTP header Accept.
> Please take a look here:
> http://wiki.restlet.org/docs_2.0/130-restlet.html for Restlet mappings 
> for HTTP headers (that page will tell you the property of which class 
> you have to set/get to manipulate the headers).
> 
> In  your case, I guess it's something like:
> 
> Request theRequest = ....
> theRequest.getClientInfo().getAcceptedMediaTypes().put(MediaType.APPLI
> CATION_XML);
> // Perform theRequest here
> 
> Hope this helps.
> 
> On Tue, Nov 22, 2011 at 1:31 PM, Norm Deane <norm dot deane at vanderbilt dot 
> edu> wrote:
> > I was able to restrict the media types that my client was willing to accept 
> > by registering only the converters for the media types I wanted the client 
> > to accept.
> >
> > List<ConverterHelper> converters = new ArrayList<ConverterHelper>(); 
> > converters.add(new OrderingContextConverter(new 
> > XmlOrderingContextDataBinder())); converters.add(new 
> > OrderModificationPlanConverter(new 
> > XmlOrderModificationPlanDataBinder()));
> >
> > Engine.getInstance().setRegisteredConverters(converters);
> >
> > Is this the only way to do this? If not, is this the correct approach?
> >
> > Thanks,
> >
> > Norm
> >
> >> I'm using the ClientResource (Restlet 2.0.10) and would like to explicitly 
> >> control the media types that my client will accept. More specifically I 
> >> only want my client to accept "application/xml" but in looking at the code 
> >> in ClientResource.wrap...
> >>
> >>                         // Updates the client preferences
> >>                         List<org.restlet.representation.Variant> 
> >> responseVariants = annotation
> >>                                 
> >> .getResponseVariants(getMetadataService(),
> >>                                         getConverterService());
> >>
> >>                         if (responseVariants != null) {
> >>                             request.setClientInfo(new ClientInfo(
> >>                                     responseVariants));
> >>                         }
> >>
> >> It looks like it will always override any preferences I set on my 
> >> ClientInfo with whatever the ConvertService is capable of handling. Is 
> >> there a way around this?
> >>
> >> Thanks,
> >>
> >> Norm
> >
> > ------------------------------------------------------
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessage
> > Id=2884392
> >
> 
> 
> 
> --
> Fabián Mandelbaum
> IS Engineer

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

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

Reply via email to