Overriding mediaType extensions using Filters

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Overriding mediaType extensions using Filters

ganges
This post was updated on .
Hi,

We are actually mapping the media types with the uri suffix's.

 Map<String, MediaType> type = config.getMediaTypeMappings();
 type.put("json", MediaType.APPLICATION_JSON_TYPE);
 type.put("xml", MediaType.APPLICATION_XML_TYPE);

And i have a resource which @Produces "application/xml".

Now, my requirement to receive the response in application/xml format from server for the uri's ending with suffix myhost.com/key.json

Since i have mapped the suffix's with media types as specified above which is always producing the JSON in this case.
Also, i have provided application/xml in the Accepts param in request header but didn't work.

I can't turn off the mediatype mapping as most of the resources need to produce application/json & application based on suffixes. But few resources i need to bypass the mediatype mapping for the uri suffixes ending with .json.

Please let me know if there is a way to fix this.

Thank you in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Overriding mediaType extensions using Filters

Markus Karg-2-3
I assume the mapping is static (does not change at runtime). Then you can either override the media type in a pre-matching (!) filter (otherwise it is simply too late), or you can simply get rid of the filter and just use two @GET methods having distinct @Produces annotations and distinct @Path("key.json) annotations (Jersey will do the rest).

-Markus

-----Ursprüngliche Nachricht-----
Von: ganges [mailto:[hidden email]]
Gesendet: Montag, 7. März 2016 03:05
An: [hidden email]
Betreff: [Jersey] Overriding mediaType extensions using Filters

Hi,

We are actually mapping the media types with the uri suffix's.

 Map<String, MediaType> type = config.getMediaTypeMappings();  type.put("json", MediaType.APPLICATION_JSON_TYPE);  type.put("xml", MediaType.APPLICATION_XML_TYPE);

And i have a resource which @Produces "application/xml".

Now, my requirement to send the response in application/xml format for the uri's ending with suffix myhost.com/key.json

Since i have mapped the suffix's with media types which is always producing the JSON in this case.
Also, i have observed the Accepts is ignored in my request header.

I can't turn off the mediatype mapping as some of the resources need to produce application/json for json uri suffixes.

Is there a way i can fix this?





--
View this message in context: http://jersey.576304.n2.nabble.com/Overriding-mediaType-extensions-using-Filters-tp7583633.html
Sent from the Jersey mailing list archive at Nabble.com.
Loading...