[ 
https://issues.apache.org/jira/browse/CXF-4891?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13606735#comment-13606735
 ] 

Todd Orr commented on CXF-4891:
-------------------------------

The MessageBodyWriter approach works for my simple case of adding charset, but 
I also have a need to look at the marshalled object to discover and analyze a 
number of annotations. I'd end up having to perform the marshalling myself, 
which would be redundant.
                
> Cannot set content-type header
> ------------------------------
>
>                 Key: CXF-4891
>                 URL: https://issues.apache.org/jira/browse/CXF-4891
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS, Transports
>    Affects Versions: 2.6.2, 2.7.3
>            Reporter: Todd Orr
>
> 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 Phases.
> 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: http://www.atlassian.com/software/jira

Reply via email to