简体   繁体   English

CXF SOAP客户端出站消息具有空主体

[英]CXF SOAP Client outbound message has empty body

I had generated a set of classes using WSDL2Java and had built a testing client to try invoke the SOAP Service. 我使用WSDL2Java生成了一组类,并构建了一个测试客户端来尝试调用SOAP服务。

The classes are generated, but when I call the web service, i notice that the body of the outbound message is empty. 生成类,但是当我调用Web服务时,我注意到出站消息的body是空的。

The following is some info on the stuff i got: 以下是我得到的东西的一些信息:

The Ant script 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>

The client code 客户端代码

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

The outbound message log 出站消息日志

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>

As you can see i'd tried setting chuking to false but it's still the same. 你可以看到我尝试将chuking设置为false但它仍然是相同的。

Any comments or idea is appreciated. 任何意见或想法表示赞赏。 Thanks. 谢谢。

It was found that this happens when you run the generated client class without referencing the CXF Lib jar files. 发现当您在不引用CXF Lib jar文件的情况下运行生成的客户端类时会发生这种情况。 After adding them into the classpath, the body of the message is then generated. 将它们添加到类路径中后,将生成消息正文。

In my case the soap body was empty due to different versions of cxf jars on the classpath. 在我的情况下,由于类路径上的不同版本的cxf jar,soap body是空的。 I am using camel-cxf 2.5.3 which depends on cxf version 3.0.6. 我使用的是camel-cxf 2.5.3,它取决于cxf 3.0.6版。 I included mistakenly the cxf-rt-transports-http-jetty 3.1.1 version in my gradle script which added the 3.1.1 cxf-core and that caused the empty soap body issue. 我在我的gradle脚本中错误地包含了cxf-rt-transports-http-jetty 3.1.1版本,该脚本添加了3.1.1 cxf-core并导致空肥皂体问题。 By putting the version 3.0.6 for cxf-rt-transports-http-jetty fixed the issue and now the body is correctly populated. 通过将版本3.0.6用于cxf-rt-transports-http-jetty修复了问题,现在正确填充了正文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM