cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Todd Orr (JIRA)" <>
Subject [jira] [Commented] (CXF-4891) Cannot set content-type header
Date Thu, 21 Mar 2013 12:57:16 GMT


Todd Orr commented on CXF-4891:

I've updated my version to 2.7.4-SNAPSHOT and converted some code to use the ContainerResponseFilter.
This approach has been met with initial excitement at the ease of use, but then disappointment
at the end result. As best as I can tell, String contentType = responseContext.getHeaderString(HttpHeaders.CONTENT_TYPE);
returns null when called during a response. I then attempt to reference responseContext.getMediaType(),
but this is also null. 

> Cannot set content-type header
> ------------------------------
>                 Key: CXF-4891
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS, Transports
>    Affects Versions: 2.6.2, 2.7.3
>            Reporter: Todd Orr
>            Assignee: Sergey Beryozkin
>             Fix For: 2.8.0, 2.7.4
> From within an interceptor I am trying to alter the content-type simply to add a few
parameters to the response header. I have attempted multiple ways to do so, across several
> Firstly, there are examples on the web of setting the header using Message.put(Message.CONTENT_TYPE,
"whatever"). This simply does not work. I then wrote the header using aMessage.put(Message.PROTOCOL_HEADERS,
arrayOfWhatever). This appears to work, but it's a lie. In the CXF response logging I see
what appears to be what I want:
> {code}
> ID: 18
> Response-Code: 200
> Content-Type: text/plain;charset=UTF-8;version=1.0.0-SNAPSHOT
> Headers: {Expires=[-1], Cache-Control=[no-cache], Pragma=[no-cache], Content-Type=[text/plain],
Date=[Tue, 12 Mar 2013 20:37:43 GMT]}
> Payload: 1.0
> {code}
> However, this must be getting overwritten between this logging statement and my client
because the browser only displays text/plain. Thinking this was just a browser error I used
Firfox and curl, both resulted in the same value of text/plain being returned.
> I have only been able to get the actual values changed by grabbing the HTTPServletResponse
using HttpServletResponse response = (HttpServletResponse) m.get(AbstractHTTPDestination.HTTP_RESPONSE);
and setting the content-type via response.setHeader(HttpHeaders.CONTENT_TYPE, contentType);.
However, this doesn't work right. First of all, it won't work if you attempt to write the
content type after MARSHAL because the stream has already been written to. And if you attempt
to write the value before MARSHAL, then when you attempt to pull the content-type from the
Message, you'll get a default content-type (I believe text/xml) value other than what the
body is. That is, if the content was marshalled to JSON, you will not get application/json
as expected.
> I have been over this for two days. I have attempted to use JAXRS handlers with similar
results. I simply do not see a way to affect the headers as I need to.
> I originally ran against 2.6.2, but was hoping that 2.7.3 corrected this. Unfortunately
both version exhibit this behavior.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message