2012-12-07 33 views
3

我的要求是有一個代理Web服務,它將接收來自客戶端的請求,然後通過camel進行路由,將其充實並轉發給其他客戶端的真實web服務,獲得響應併發送它回到原來的請求者。camel cxf代理不能與http端點一起工作

我基本上看過camel-cxf-proxy示例(http://camel.apache.org/cxf-proxy-example.html)和camel-cxf-example在駱駝distribution.Its完全類似於camel-cxf -proxyand與這條路線上來

<from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" /> 
<camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo> 
<to ref="XService"></to> 

其中端點

<endpoint id="XService" uri="http://xx.xx.xxx.xx:8080/X_Service" /> 

<cxf:cxfEndpoint id="soapMessageEndpoint" address="http://localhost:8181/ProviderInformationDirectoryService" wsdlURL="wsdl/HPD_ProviderInformationDirectory.wsdl" endpointName="s:ProviderInformationDirectory_Port_Soap" serviceName="s:ProviderInformationDirectory_Service" xmlns:s="urn:ihe:iti:hpd:2010"/> 

正如你所看到的第二項服務是HTTP endpoint.And首先是駱駝CXF proxy.I纔有WSDL和在這一點上不需要impl.the數據格式是MESSAGE,因爲我需要將整個soap信封發送到s第二個Web服務,並在客戶端的請求中有一些有用的標題。但是,當我使用示例soap信封運行此路由時,它始終會出現500響應。我在想,發送到真正的web服務的消息不是它所期望的。

我試圖跟蹤駱駝的路線,但它並沒有顯示much.I希望它會表現出真正的請求到http endpoint.i試圖攔截器配置,但沒有工作either.Trace只顯示以下

Failed delivery for (MessageId: ID-ALHCAN0437-63941-1354828653539-45-2 on ExchangeId: ID-ALHCAN0437-63941-1354828653539-45-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking http://X:8080/X_Service with statusCode: 500 

我也嘗試了下面這似乎工作。

<from uri="cxf:bean:soapMessageEndpoint?dataFormat=MESSAGE" /> 
<camel:convertBodyTo type="java.lang.String"></camel:convertBodyTo> 
<to uri="bean:callRemoteWS"></to> 

callRemoteWS(callRemoteMethod)獲取的SoapEnvelope作爲串並做出HTTPPost請求上述端點,返回該響應。

public String callRemoteMethod(String request) throws Exception{ 



      HttpClient client = new HttpClient(); 

      BufferedReader br = null; 

      PostMethod method = new PostMethod("http://x.x.x.x:8080/X_Service"); 

      RequestEntity entity =new StringRequestEntity(request); 

      method.setRequestEntity(entity); 

      try{ 
       int returnCode = client.executeMethod(method); 

       if (returnCode != HttpStatus.SC_OK) { 
        System.err.println("Method failed: " + method.getStatusLine()); 
        return "Error"; 
       } 

       // Read the response body. 
       byte[] responseBody = method.getResponseBody(); 

       System.out.println(new String(responseBody)); 

       // Deal with the response. 
       // Use caution: ensure correct character encoding and is not binary data 
       return new String(responseBody); 
      } finally { 
       method.releaseConnection(); 
       if(br != null) try { br.close(); } catch (Exception fe) {} 
      } 

      } 

我很困惑,爲什麼用HTTP web服務沒有工作,第二個簡單的駱駝CXF代理工作(它應該與它:P)。是我的代碼有ok.It似乎沒有我的權利。我很確定有些交換屬性設置錯誤,或者發送到真實web服務的內容是錯誤的。從代理獲得的內容用於在第二個路由中使Httppost調用,所以來自代理的內容不會錯誤。從交換和發送到真正的Web服務出現問題。任何人都可以拋出一些光。

回答

0

我認爲這是我的一部分.soap擴展動作頭一個愚蠢的錯誤有不同的操作和有效載荷是一個不同的method.I被調用與有效載荷

+0

錯誤的操作,如果你發現這個問題不對其他人有用,隨時刪除它:) –

+1

不要刪除,對我有用 –

+0

您可以請建議,您是如何設法指定SOAP操作標頭的,因爲我正在路由到不同的端點時正在獲取之前的操作與您遇到的錯誤相同。 –

相關問題