问题
I'm doing a development to send a SOAP
request to a remote web service and get a response using apache Camel
.
In this case, I succesfully generated Client Side wsdl2java Code using the cxf-codegen-plugin
for the WSDl mentioned below.
- Sample WSDL URL :
http://www.webservicex.net/stockquote.asmx?WSDL
And after doing some researches, I created below sample code to send a SOAP request to the web service defined in there and get a response with apache Camel using the generated client code.
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);
But it gives below error.
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
What have I miss here? Data binding? or anything else? I generated the client code using cxf so how I can send this using cxf?
What I simply want is to send a SOAP request to a remote web service and get a response using apache Camel.
- Camel Version : 2.9.0
- Java Version : 1.7.x / 1.8.x
回答1:
It would be better to use the CXF component for this. Depending on how the CXF code is generated you might just send & receive a string instead of an object in your example - see How to tell cxf to keep the wrapper types in methods? for more information.
Here's your example with 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);
来源:https://stackoverflow.com/questions/38662895/send-a-soap-request-to-a-remote-web-service-and-get-a-response-using-apache-came