You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID (ATTSI)" <dk...@att.com> on 2011/04/26 01:02:51 UTC
Setting "Accept" header value in in interceptor only halfway works
If I send a request to my service without setting the "Accept" header, I get XML back. In the service, I check "acceptableMediaTypes", and it's "application/xml".
If I set the "Accept" request header to "application/json", I get JSON back. In the service, I check "acceptableMediaTypes", and it's "application/json".
I set the "_type" query parameter to "json", I get JSON back. In the service, I check "acceptableMediaTypes", and it's "application/json".
Everything's fine so far. The next test has the problem.
I have an interceptor that looks for certain query parameters and translates them to header parameters. One of the keys it looks for is "Accept". I set the "Accept" query parameter to "application/json". I watched my interceptor execute the following line:
((Map<String, List<String>>) inMessage.get(Message.PROTOCOL_HEADERS)).put(key, list);
Where "key" was "Accept", and "list" was a one-element list containing the value "application/json".
Inside the service, I printed the value of "acceptableMediaTypes", and it's "application/json".
However, when the service rendered the response, it was XML, not JSON.
What could I be missing?
Re: Setting "Accept" header value in in interceptor only halfway works
Posted by Sergey Beryozkin <sb...@gmail.com>.
HI David
On Tue, Apr 26, 2011 at 12:02 AM, KARR, DAVID (ATTSI) <dk...@att.com> wrote:
> If I send a request to my service without setting the "Accept" header, I get XML back. In the service, I check "acceptableMediaTypes", and it's "application/xml".
>
> If I set the "Accept" request header to "application/json", I get JSON back. In the service, I check "acceptableMediaTypes", and it's "application/json".
>
> I set the "_type" query parameter to "json", I get JSON back. In the service, I check "acceptableMediaTypes", and it's "application/json".
>
> Everything's fine so far. The next test has the problem.
>
> I have an interceptor that looks for certain query parameters and translates them to header parameters. One of the keys it looks for is "Accept". I set the "Accept" query parameter to "application/json". I watched my interceptor execute the following line:
>
> ((Map<String, List<String>>) inMessage.get(Message.PROTOCOL_HEADERS)).put(key, list);
>
> Where "key" was "Accept", and "list" was a one-element list containing the value "application/json".
>
> Inside the service, I printed the value of "acceptableMediaTypes", and it's "application/json".
>
> However, when the service rendered the response, it was XML, not JSON.
>
In the interceptor, please also do:
message.put(Message.ACCEPT_CONTENT_TYPE, "application/json");
It's a bit of duplication, but CXF HTTP transport does do it too
(probably to text/xml by default). It is an issue that JAX-RS frontend
assumes that Message.ACCEPT_CONTENT_TYPE is always set and thus
ignores the value available in the map, that can bee improved - but
adding the above line should make it all work for you
Cheers, Sergey
> What could I be missing?
>