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)
–
–
–
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.