Reputation: 199
I have a code which execute correct as per web service calling. and its also log the return SOAP Header. Now i need to display same xml on UI, for that i need to retrieve output from camel context.
Code :
DefaultCamelContext context = new DefaultCamelContext();
// append the routes to the context
String myString = "<route id=\"my_Sample_Camel_Route_with_CXF\" xmlns=\"http://camel.apache.org/schema/spring\">"
+ " <from uri=\"file:///home/viral/Projects/camel/cxfJavaTest/src/data?noop=true\"/>"
+ " <log loggingLevel=\"INFO\" message=\">>> ${body}\"/>"
+ " <to uri=\"cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/wsdl/stockquote.wsdl&serviceName={http://www.webserviceX.NET/}StockQuote&portName={http://www.webserviceX.NET/}StockQuoteSoap&dataFormat=MESSAGE\"/>"
+ " <log loggingLevel=\"INFO\" message=\">>> ${body}\"/>"
+ " </route>";
;
InputStream is = new ByteArrayInputStream(myString.getBytes());
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
context.setTracing(true);
context.start();
Thread.sleep(3000);
System.out.println("Done");
context.stop();
Is there any way to get web service output using context variable or any other way to fetch response of web service which was print using log statement?
If you provide code than its very helpful to me.
Thanks In Advance.
Upvotes: 1
Views: 1824
Reputation: 6925
You can create a custom processor that will access the data in the your route.
class MyProcessor extends Processor {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class); //Maybe you need some other type.
//do your logic here
}
}
Then you can add it to your route like (you need to add it to your camel context registry):
<process id="myProcessor">
Also, why are you using the XML notation inside your code. It should be easier to use the Java DSL notation.
Upvotes: 2