CXF SOAP 客户端出站消息正文为空
CXF SOAP Client outbound message has empty body
我已经使用 WSDL2Java 生成了一组 类 并构建了一个测试客户端来尝试调用 SOAP 服务。
生成了 类,但是当我调用 Web 服务时,我注意到出站消息的 body
是空的。
以下是我得到的东西的一些信息:
Ant 脚本
<target depends="clear-cxf-client-src" name="cxf-wsdl-java">
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
<arg value="-client"/>
<arg value="-d"/>
<arg value="${src.dir}"/>
<arg value="-exsh"/>
<arg value="true"/>
<arg value="-autoNameResolution"/>
<arg value="-wsdlLocation"/>
<arg value="${wsdl.url}"/>
<arg value="${wsdl.url}"/>
<classpath>
<path refid="cxf.classpath"/>
</classpath>
</java>
</target>
客户端代码
URL wsdlURL = Service.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
Service service = new Service();
ReqServicePortType port = service.getReqServicePort();
String endpoint = "http://server:port/<path to end point>";
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
provider.getRequestContext().put("schema-validation-enabled", "true");
Client client = ClientProxy.getClient(port);
LoggingInInterceptor loggingInInterceptor = new LoggingInInterceptor();
loggingInInterceptor.setPrettyLogging(true);
LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
loggingOutInterceptor.setPrettyLogging(true);
client.getInInterceptors().add(loggingInInterceptor);
client.getOutInterceptors().add(loggingOutInterceptor);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
CustomHeader header= new CustomHeader();
//setting header value....
header.setTimestamp(sdf.format(new Date()));
Holder<CustomHeader> headers = new Holder<CustomHeader>(header);
ReqDoc reqDoc = new ReqDoc();
//setting reqDoc value...
reqDoc.setTranxId("5");
ProcessReq req = new ProcessReq();
req.setInput(reqDoc);
ProcessReqResponse response = port.processReq(req, headers);
RespDoc respDoc = null;
if(response != null){
respDoc = response.getOutput();
}
String msgCode = "";
String msgDesc = "";
if(respDoc != null){
msgCode = respDoc.getMsgCode();
msgDesc = respDoc.getMsgDesc();
}
System.out.println("msgCode: " + msgCode);
System.out.println("msgDesc: " + msgDesc);
出站消息日志
INFO: Outbound Message
--------------------------- ID: 1 Address: http://server:port/<path to service> Encoding: UTF-8 Http-Method: POST Content-Type: text/xml Headers: {Accept=[*/*], Authorization=[Basic 12341323232323=], SOAPAction=["Service_Binder_processReq"]} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header>
<header xmlns:ns3="http://<my package>" xmlns:ns2="http://<my schema>" xmlns="http://<my schema>">
<timestamp>20150525115746</timestamp>
</header> </soap:Header> <soap:Body/> </soap:Envelope>
如您所见,我尝试将 chuking 设置为 false
,但它仍然是一样的。
如有任何意见或想法,我们将不胜感激。谢谢。
发现当您 运行 生成的客户端 class 没有引用 CXF Lib jar 文件时会发生这种情况。将它们添加到class路径后,便会生成邮件正文。
在我的例子中,由于类路径上的 cxf jar 版本不同,soap 主体是空的。我正在使用依赖于 cxf 版本 3.0.6 的 camel-cxf 2.5.3。我错误地将 cxf-rt-transports-http-jetty 3.1.1 版本包含在我的 gradle 脚本中,该脚本添加了 3.1.1 cxf-core 并导致了空肥皂体问题。通过将 3.0.6 版用于 cxf-rt-transports-http-jetty 解决了这个问题,现在主体已正确填充。
我已经使用 WSDL2Java 生成了一组 类 并构建了一个测试客户端来尝试调用 SOAP 服务。
生成了 类,但是当我调用 Web 服务时,我注意到出站消息的 body
是空的。
以下是我得到的东西的一些信息:
Ant 脚本
<target depends="clear-cxf-client-src" name="cxf-wsdl-java">
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
<arg value="-client"/>
<arg value="-d"/>
<arg value="${src.dir}"/>
<arg value="-exsh"/>
<arg value="true"/>
<arg value="-autoNameResolution"/>
<arg value="-wsdlLocation"/>
<arg value="${wsdl.url}"/>
<arg value="${wsdl.url}"/>
<classpath>
<path refid="cxf.classpath"/>
</classpath>
</java>
</target>
客户端代码
URL wsdlURL = Service.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
Service service = new Service();
ReqServicePortType port = service.getReqServicePort();
String endpoint = "http://server:port/<path to end point>";
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
provider.getRequestContext().put("schema-validation-enabled", "true");
Client client = ClientProxy.getClient(port);
LoggingInInterceptor loggingInInterceptor = new LoggingInInterceptor();
loggingInInterceptor.setPrettyLogging(true);
LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
loggingOutInterceptor.setPrettyLogging(true);
client.getInInterceptors().add(loggingInInterceptor);
client.getOutInterceptors().add(loggingOutInterceptor);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
CustomHeader header= new CustomHeader();
//setting header value....
header.setTimestamp(sdf.format(new Date()));
Holder<CustomHeader> headers = new Holder<CustomHeader>(header);
ReqDoc reqDoc = new ReqDoc();
//setting reqDoc value...
reqDoc.setTranxId("5");
ProcessReq req = new ProcessReq();
req.setInput(reqDoc);
ProcessReqResponse response = port.processReq(req, headers);
RespDoc respDoc = null;
if(response != null){
respDoc = response.getOutput();
}
String msgCode = "";
String msgDesc = "";
if(respDoc != null){
msgCode = respDoc.getMsgCode();
msgDesc = respDoc.getMsgDesc();
}
System.out.println("msgCode: " + msgCode);
System.out.println("msgDesc: " + msgDesc);
出站消息日志
INFO: Outbound Message
--------------------------- ID: 1 Address: http://server:port/<path to service> Encoding: UTF-8 Http-Method: POST Content-Type: text/xml Headers: {Accept=[*/*], Authorization=[Basic 12341323232323=], SOAPAction=["Service_Binder_processReq"]} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header>
<header xmlns:ns3="http://<my package>" xmlns:ns2="http://<my schema>" xmlns="http://<my schema>">
<timestamp>20150525115746</timestamp>
</header> </soap:Header> <soap:Body/> </soap:Envelope>
如您所见,我尝试将 chuking 设置为 false
,但它仍然是一样的。
如有任何意见或想法,我们将不胜感激。谢谢。
发现当您 运行 生成的客户端 class 没有引用 CXF Lib jar 文件时会发生这种情况。将它们添加到class路径后,便会生成邮件正文。
在我的例子中,由于类路径上的 cxf jar 版本不同,soap 主体是空的。我正在使用依赖于 cxf 版本 3.0.6 的 camel-cxf 2.5.3。我错误地将 cxf-rt-transports-http-jetty 3.1.1 版本包含在我的 gradle 脚本中,该脚本添加了 3.1.1 cxf-core 并导致了空肥皂体问题。通过将 3.0.6 版用于 cxf-rt-transports-http-jetty 解决了这个问题,现在主体已正确填充。