Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4891

Cannot set content-type header

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      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:

      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
      

      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.

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            redijedi Todd Orr
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: