当前位置: 首页 > 知识库问答 >
问题:

向远程web服务发送SOAP请求并使用apache Camel获得响应

郤望
2023-03-14

我正在进行一个开发,向远程web服务发送SOAP请求,并使用Apache Camel获得响应。

在本例中,我使用下面提到的WSDl的cxf-codegen-plugin成功地生成了客户端wsdl2java代码。

  • 示例WSDL URL:http://www.webservicex.net/stockquote.asmx?WSDL

在做了一些研究之后,我创建了下面的示例代码,用于向其中定义的web服务发送SOAP请求,并使用生成的客户机代码获得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

我只想向远程web服务发送一个SOAP请求,并使用apache Camel获得响应。

  • 骆驼版本:2.9.0
  • Java版本:1.7.x/1.8.x

共有1个答案

微生运浩
2023-03-14

为此最好使用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);
 类似资料:
  • 好的,我对网络服务完全陌生,对于我正在做的一个项目,我试图了解整个SOAP。我想我对正在发生的事情有一个模糊的理解,但是我缺少一些具体的信息,我在谷歌上找不到任何有用的东西。 我已经阅读了其他人提出的问题,例如使用java向Web服务发出的SOAP请求,但我仍然无法完全弄清楚发生了什么。 具体来说,我尝试使用这里提供的服务http://ec.europa.eu/taxation_customs/v

  • 我有以下WCF服务操作: 我可以通过导航到服务在浏览器中加载WSDL。但是,当我在Jmeter中向同一服务发送“SOAP/XML-RPC请求”时,我收到了响应代码-400-错误请求。 以下是我正在使用的Soap消息:

  • 问题内容: 是否可以使用Python的库发送SOAP请求? 问题答案: 确实有可能。 这是一个使用普通请求lib调用Weather SOAP Service的示例: 一些注意事项: 标头很重要。没有正确的标头,大多数SOAP请求将无法工作。可能是更 正确 使用的标头(但weatherservice更喜欢 这将以xml字符串形式返回响应-然后,您需要解析该xml。 为简单起见,我以纯文本形式包含了该

  • 我需要使用https协议向我的web服务发送请求。使用SOAP UI,它工作得很好,也为https请求提供响应,但是,如果我发送https请求,它提供以下异常javax.xml.ws.WebServiceException:未能访问WSDL:https://abc:8443/xyz/FileTransferService?WSDL。它失败的原因是:

  • XMLHttpRequest 对象用于和服务器交换数据。 向服务器发送请求 如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 open() 和 send() 方法:xmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); 方法 描述 open(method,url,async) 规定请求的类型、URL 以及是否异步处理

  • 问题内容: 我有以下代码来从SOAP Web服务获取响应。 这是我在SOAPUI中的SOAP请求 这是我在SOAPUI中得到的响应 最后,这是我为获取此数据所做的代码。 执行完上面的代码后,我得到以下错误: 谁能告诉我为什么我没有通过代码在SOAPUI bt中获得成功。 我已经提到了许多SO链接,但无法解决我的问题。 提前致谢。 问题答案: 长期面对此问题后,我找到了解决方案。任何人都可以尝试一下