簡體   English   中英

使用apache Camel將SOAP請求發送到遠程Web服務並獲得響應

[英]Send a SOAP request to a remote web service and get a response using apache Camel

我正在做一個開發,以將SOAP請求發送到遠程Web服務,並使用apache Camel獲得響應。

在這種情況下,我成功使用下面提到的WSD1的cxf-codegen-plugin codegen cxf-codegen-plugin生成了客戶端wsdl2java代碼。

  • WSDL示例網址: http://www.webservicex.net/stockquote.asmx?WSDLhttp://www.webservicex.net/stockquote.asmx?WSDL WSDL

在進行了一些研究之后,我創建了以下示例代碼,將SOAP請求發送到其中定義的Web服務,並使用生成的客戶端代碼通過apache Camel獲得響應。

CamelContext context = new DefaultCamelContext();

HttpComponent httpComponent = new HttpComponent();
context.addComponent("http", httpComponent);

ProducerTemplate template = context.createProducerTemplate();

GetQuote getQuote = new GetQuote();
getQuote.setSymbol("test123");

GetQuoteResponse getQuoteResponse = template.requestBody("http://www.webservicex.net/stockquote.asmx",getQuote, GetQuoteResponse.class);

System.out.println(getQuoteResponse);

但是它給出了以下錯誤。

Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: net.webservicex.GetQuote@10bdf5e5 of type: net.webservicex.GetQuote on: Message[ID-namal-PC-33172-1469806939935-0-1]. Caused by: No type converter available to convert from type: net.webservicex.GetQuote to the required type: java.io.InputStream with value net.webservicex.GetQuote@10bdf5e5. Exchange[ID-namal-PC-33172-1469806939935-0-2]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: net.webservicex.GetQuote to the required type: java.io.InputStream with value net.webservicex.GetQuote@10bdf5e5]

Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: net.webservicex.GetQuote to the required type: java.io.InputStream with value net.webservicex.GetQuote@10bdf5e5

我在這里想念什么? 數據綁定? 還是其他? 我使用cxf生成了客戶端代碼,因此如何使用cxf發送此代碼?

我只希望將SOAP請求發送到遠程Web服務,並使用apache Camel獲得響應。

  • 駱駝版本:2.9.0
  • Java版本:1.7.x / 1.8.x

為此最好使用CXF組件。 根據生成CXF代碼的方式,您可能只發送和接收字符串而不是示例中的對象-請參閱如何告訴cxf將包裝類型保留在方法中? 欲獲得更多信息。

這是您使用CXF的示例。

CamelContext context = new DefaultCamelContext();

CxfComponent cxfComponent = new CxfComponent(context);
CxfEndpoint serviceEndpoint =
    new CxfEndpoint("http://www.webservicex.net/stockquote.asmx", cxfComponent);

// Service class generated by CXF codegen plugin.
serviceEndpoint.setServiceClass(StockQuoteSoap.class);

ProducerTemplate template = context.createProducerTemplate();

// Request and response can be 'bare' or 'wrapped', see the service class.
String getQuoteResponse = template.requestBody(serviceEndpoint, "MSFT", String.class);

System.out.println(getQuoteResponse);

暫無
暫無

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

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