Ich entwickle eine soap webserivce mit Apache cxf.So fügen Sie dem http-Header einen Platz hinzu Content-Type, z. B .: text/xml; charset = utf-8
Und alle Seife Antwort Header zurück Content-Type: text/xml; charset = utf-8.
Aber der Kunde (die andere Firma) akzeptiert nur Content-Type: 'text/xml; charset = utf-8 ',
die Unterschiede sind, dass es einen Abstand zwischen text/xml gibt; und charset = utf-8 und das einfache Zitat.
Also ich möchte cxf Interceptor oder Java-Filter verwenden, um den Content-Type-Wert, wie unter Code zu ändern.
Ich kann bereits ein einzelnes Zitat erfolgreich mit CXF Interceptor oder Java-Filter hinzufügen, kann aber immer noch keinen Platz hinzufügen.
Der Raum, den ich hinzugefügt magisch verschwunden.
Bitte geben Sie mir die Lösung.
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)
}