相关文章推荐
阳光的枇杷  ·  c# - WPF datagrid ...·  1 年前    · 
才高八斗的骆驼  ·  用Windows ...·  1 年前    · 
个性的茄子  ·  node.js - In Visual ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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)
                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, 2018 at 9: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, 2018 at 2:32
                Thanks for answering @mike.jang. Actually I ended up asking my own question (see) because my problem was at tomcat level, not the same as you. Thanks anyway
– troig
                Mar 23, 2018 at 7:31
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.