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.APPLICATION_XML);
// Perform theRequest here

Hope this helps.

On Tue, Nov 22, 2011 at 1:31 PM, Norm Deane <[email protected]> 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&dsMessageId=2884392
>



-- 
Fabián Mandelbaum
IS Engineer

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

Reply via email to