簡體   English   中英

駱駝的封送處理問題,無法正確封送SOAP請求?

[英]Marshaling issue with Camel, unable to correctly marshal SOAP request?

我試圖使用Camel路由通過SOAP / JAX-WS調用Web服務,並不斷收到錯誤消息:CaughtExceptionMessage:HTTP操作無法調用帶有statusCode:404的http://xyz.com/Service

使用Soap UI Works文件調用相同的服務,所以我的猜測是請求沒有被編組相同,並且該服務無法找到正在調用的方法,從而導致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>

駱駝吐出以下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);

要封送的請求對象的位置是進入該駱駝路線的郵件正文。 駱駝對請求的處理是什么導致404錯誤?

任何幫助或想法將不勝感激。

事實證明,駱駝沒有添加contentType標頭或SOAPAction標頭,因此Web服務拋出404錯誤,因為它不接受請求作為有效的SOAP調用(很可能contentType對於使其正常工作並不關鍵)。 我以為Camel和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的請求的封送工作正常,不需要進行任何更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM