0

我正在尝试使用 Camel 路由通过 SOAP/JAX-WS 调用 Web 服务,并不断收到错误消息:CaughtExceptionMessage:HTTP operation failed invoking http://xyz.com/Service with statusCode: 404。

使用 Soap UI 工作文件调用相同的服务,所以我的猜测是请求没有得到相同的编组,并且服务无法找到正在调用的方法,导致 404。Soap UI 提供以下请求 XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:bfg="http://xyz.com/Service">
   <soapenv:Header/>
   <soapenv:Body>
      <bfg:login>
         <bfg:request>
            <ipAddress>1.2.3.4</ipAddress>
            <locationId>0</locationId>
            <password>Foo</password>
            <productId>1</productId>
            <username>Bar</username>
            <vendorSoftwareId>0</vendorSoftwareId>
         </bfg:request>
       </bfg:login>
   </soapenv:Body>
</soapenv:Envelope>

Camel 吐出以下 XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:ns3="http://xyz.com/Service" 
      xmlns:ns4="http://xyz.com/Other">    
<ns2:Body>        
    <ns3:login>            
       <ns3:request>                
           <ipAddress>1.2.3.4</ipAddress>                
           <locationId>0</locationId>                
           <password>Foo</password>                
           <productId>0</productId>                
           <username>Bar</username>               
           <vendorSoftwareId>0</vendorSoftwareId>            
       </ns3:request>       
    </ns3:login>    
  </ns2:Body>
</ns2:Envelope> 

差异很小,实际上只是名称空间。将 XML 复制并粘贴到 SoapUI 中,然后使用它将产生有效的请求/响应。

骆驼路线和配置如下:

private final SoapJaxbDataFormat globalServiceSoap = 
    new SoapJaxbDataFormat(Service.class.getPackage().getName(),  
     new ServiceInterfaceStrategy(Service.class, true));

from(RouteConstants.LOGIN_SERVICE_END_POINT_URI)
     .routeId("internal::loginGlobalService").marshal(globalServiceSoap)
    .to(endpointUri).unmarshal(globalServiceSoap).process(postLoginProcessor);

要编组的请求对象是进入该 Camel 路由的消息正文。骆驼在请求上做了什么导致它以 404 失败?

任何帮助或想法将不胜感激。

4

1 回答 1

0

事实证明,Camel 没有添加contentType标头或SOAPAction标头,因此 Web 服务抛出 404,因为它不接受作为有效 SOAP 调用的请求(很可能这contentType对于使其正常工作并不重要)。我原以为骆驼和他们SoapJaxbDataFormat会足够聪明地添加那种类型的东西(我看到的例子表明应该这样做),但似乎不是。

使用基于 java 代码的路由定义很容易添加缺少的标头:

from(RouteConstants.LOGIN_SERVICE_END_POINT_URI)
    .routeId("internal::loginGlobalService")
    .setHeader(Exchange.CONTENT_TYPE, constant("text/xml"))
    .setHeader("SOAPAction",   constant("login")).marshal(globalServiceSoap)
    .to(endpointUri).unmarshal(globalServiceSoap).process(postLoginProcessor);

并且由此产生的请求被很好地接受了。对 XML 的请求的编组工作正常,无需更改。

于 2013-09-17T01:33:34.787 回答