【问题标题】:CXF SOAP Client outbound message has empty bodyCXF SOAP 客户端出站消息的正文为空
【发布时间】:2015-05-25 04:11:52
【问题描述】:

我使用 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,但还是一样。

感谢任何 cmets 或想法。谢谢。

【问题讨论】:

    标签: java cxf soap-client


    【解决方案1】:

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

    【讨论】:

    • 我也面临类似的问题。但就我而言,我不使用 CXF,我使用的是 JAXB 客户端。你知道可能是什么问题吗?
    【解决方案2】:

    在我的情况下,由于类路径上的 cxf jar 版本不同,soap 主体是空的。我正在使用取决于 cxf 版本 3.0.6 的骆驼 cxf 2.5.3。我在我的 gradle 脚本中错误地包含了 cxf-rt-transports-http-jetty 3.1.1 版本,它添加了 3.1.1 cxf-core 并导致了空肥皂体问题。通过为 cxf-rt-transports-http-jetty 放置 3.0.6 版本修复了该问题,现在正文已正确填充。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多