16.7. 如何让 camel-cxf 响应以 xml 处理指令开始
如果您使用一些 SOAP 客户端,如 PHP,则会收到此类错误,因为 CXF 中没有添加 XML 处理指令 < ?xml version="1.0" 编码="utf-8"?>:
Error:sendSms: SoapFault exception: [Client] looks like we got no XML document in [...]
Error:sendSms: SoapFault exception: [Client] looks like we got no XML document in [...]
要解决这个问题,您只需要告诉 StaxOutInterceptor 为您编写 XML 开始文档,如下面的 WriteXmlDeclarationInterceptor 中:
作为替代方案,您可以为其添加消息标头,如 CxfConsumerTest 中的演示:
// set up the response context which force start document
Map<String, Object> map = new HashMap<String, Object>();
map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
exchange.getOut().setHeader(Client.RESPONSE_CONTEXT, map);
// set up the response context which force start document
Map<String, Object> map = new HashMap<String, Object>();
map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
exchange.getOut().setHeader(Client.RESPONSE_CONTEXT, map);