1

I develope a soap webserivce by using apache cxf.

And all the soap response header return Content-Type: text/xml;charset=utf-8.

But the client (the other company) only accept Content-Type: 'text/xml; charset=utf-8',

the differences are that there is a space between text/xml; and charset=utf-8 and the single quotation.

So I want to use cxf interceptor or java filter to change the Content-Type value, like below code.

I already can add singe quotation successfully by using cxf interceptor or java filter, but still can not add space.

The space I added magically disappeared.

Please provide me the solution .

Myfilter.java

@Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {

        HttpServletResponse response = (HttpServletResponse) res;
        HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(response)
           {
            @Override
            public ServletOutputStream getOutputStream() throws java.io.IOException
            {
                ServletResponse response = this.getResponse();

                    response.setContentType("\'text/xml;   charset=utf-8\'");  // result:Content-Type: 'text/xml;charset=utf-8' (no space)


                return super.getOutputStream();
            }
        };
    //  wrapper.setContentType("\'text/xml; charset=utf-8\'"); // result:Content-Type: text/xml;charset=UTF-8 (not success)

    //  wrapper.addHeader("Content-Type", "\'text/xml; charset=utf-8\'"); // result:Content-Type: text/xml;charset=UTF-8 (not success)
    //  wrapper.setHeader("Content-Type", "\'text/xml;   charset=utf-8\'");// result:Content-Type: text/xml;charset=UTF-8 (not success)


        chain.doFilter(req, wrapper);

    }

ModiyContentTypeOutInterceptor.java (cxf interceptor)

    @Override
    public void handleMessage(SoapMessage message) throws Fault {

         Map<String, List<String>> headers = new HashMap<String, List<String>>();

         headers.put("Content-Type", Arrays.asList("\'text/xml; charset=utf-8\'"));
         message.put(Message.PROTOCOL_HEADERS, headers);
         // the result is stll :'text/xml;charset=utf-8' (no space)

    }
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
mike.jiang
  • 177
  • 1
  • 3
  • 15

1 Answers1

1

I have found the solution.

Just add a whole blank.

mike.jiang
  • 177
  • 1
  • 3
  • 15
  • 1
    Hi! Could you explain a little bit what do you mean with a whole blank? I'm facing with the same issue. Thanks – troig Mar 21 '18 at 09:44
  • English is not my mother language. So I think I used the wrong term. I mean the space that is fullwidth form actually. – mike.jiang Mar 23 '18 at 02:32
  • Thanks for answering @mike.jang. Actually I ended up asking my own question ([see](https://stackoverflow.com/questions/49409116/keep-the-space-after-semicolon-in-content-type-header-response-using-tomcat)) because my problem was at tomcat level, not the same as you. Thanks anyway – troig Mar 23 '18 at 07:31