CXF SOAP客户机出站消息正文为空



我已经使用WSDL2Java生成了一组类,并构建了一个测试客户端来尝试调用SOAP服务。

生成了类,但是当我调用web服务时,我注意到出站消息的body为空。

以下是我得到的东西的一些信息:

<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>

正如你所看到的,我已经尝试将chking设置为false,但它仍然是相同的。

任何意见或想法都是赞赏的。谢谢。

当您运行生成的客户机类而不引用CXF Lib jar文件时,就会发生这种情况。将它们添加到类路径后,就会生成消息体。

在我的例子中,soap主体是空的,因为类路径上有不同版本的cxf jar。我使用的是camel-cxf 2.5.3,它依赖于cxf 3.0.6版本。我在gradle脚本中错误地包含了3.1.1版本的cxf-rt-transports-http-jetty,它添加了3.1.1版本的cxf-core,这导致了空soap体问题。通过将cxf-rt-transports-http-jetty的3.0.6版本修复了这个问题,现在正文被正确填充。

最新更新