CXF 生成的客户端发送以下 SOAP 请求,该请求不从其端返回记录:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PersonSearch xmlns="http://tlo.com/">
<genericSearchInput>
....
</genericSearchInput>
</PersonSearch>
</soap:Body>
</soap:Envelope>
SoapUI 请求如下所示并返回记录:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tlo="http://tlo.com/">
<soapenv:Header/>
<soapenv:Body>
<tlo:PersonSearch>
<!--Optional:-->
<tlo:genericSearchInput>
...
</tlo:genericSearchInput>
</tlo:PersonSearch>
</soapenv:Body>
</soapenv:Envelope>
我看到的唯一区别是默认 namespace 声明而不是 soap 信封上的 namespace 声明以及 namespace 前缀的使用。我已经尝试了几种不同的方法来让 CXF 生成的客户端创建相同类型的 soap 请求。任何人都可以提供一些指示还是我需要使用其他东西?
我在 JDK 6 上使用 org.apache.cxf:cxf-codegen-plugin:2.5.2。
最佳答案
您是否使用 JAXB 进行数据绑定(bind)?我能够通过使用 XMLBEANS 来解决同样的问题。查看 wsdl2java 的 db 标志:http://cxf.apache.org/docs/wsdl-to-java.html
我仍在寻找比仅仅更改数据绑定(bind)更好的解决方案。
20012-04-18 更新:来自 cxf 用户邮件列表的 Sergey 和 Aki 非常友好地向我展示了 CXF 的 TransformationFeature。在客户端使用以下代码对我有用:
MyService myService = new MyService();
myPort = myService.getMyServiceHttpSoap11Endpoint();
// See http://cxf.apache.org/docs/transformationfeature.html
Client client = ClientProxy.getClient(myPort);
Map<String, String> outTransformMap = Collections.singletonMap(
"{http://myNamespace}*",
"{http://myNamespace}*");
org.apache.cxf.interceptor.transform.TransformOutInterceptor transformOutInterceptor =
new org.apache.cxf.interceptor.transform.TransformOutInterceptor();
transformOutInterceptor.setOutTransformElements(outTransformMap);
client.getOutInterceptors().add(transformOutInterceptor);
我在 CXF 2.5.2 中使用它。根据 Aki,对于 2.5.3 和 2.5.6,您必须使用 defaultNamespace 属性。
关于java - CXF-CODEGEN 生成的客户端需要 soap 信封上的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537462/