Return-Path: X-Original-To: apmail-cxf-issues-archive@www.apache.org Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42FC5E33F for ; Tue, 12 Mar 2013 20:59:16 +0000 (UTC) Received: (qmail 77888 invoked by uid 500); 12 Mar 2013 20:59:15 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 77854 invoked by uid 500); 12 Mar 2013 20:59:15 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 77428 invoked by uid 99); 12 Mar 2013 20:59:15 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Mar 2013 20:59:15 +0000 Date: Tue, 12 Mar 2013 20:59:15 +0000 (UTC) From: "Todd Orr (JIRA)" To: issues@cxf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (CXF-4891) Cannot set content-type header MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Todd Orr created CXF-4891: ----------------------------- Summary: 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.7.3, 2.6.2 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