Http Binding question
jcoders Apr 24, 2013 4:36 PMhi,
I am trying to do the following
1) pick up documents from a ftp folder, route it using camel to a reference end point that has http binding to post the file to a RESTeasy webservice
Everything works fine all the way to the posting part, i have debug statements in the webservice firing off saying it got the document, printing etc works but i m not sure how to get/process the response i would get back from the RESTeasy webservice.My switchyard.xml is as follows
<?xml version="1.0" encoding="UTF-8"?> <switchyard xmlns="urn:switchyard-config:switchyard:1.0" xmlns:camel="urn:switchyard-component-camel:config:1.0" xmlns:file="urn:switchyard-component-camel-file:config:1.0" xmlns:ftp="urn:switchyard-component-camel-ftp:config:1.0" xmlns:http="urn:switchyard-component-http:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="switchyard-myFtp" targetNamespace="urn:com.example.switchyard:switchyard-myFtp:1.0"> <sca:composite name="switchyard-myFtp" targetNamespace="urn:com.example.switchyard:switchyard-myFtp:1.0"> <sca:component name="CamelServiceRoute"> <camel:implementation.camel> <camel:java class="com.example.switchyard.switchyard_myFtp.CamelServiceRoute"/> </camel:implementation.camel> <sca:service name="CamelService"> <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.CamelService"/> </sca:service> <sca:reference name="FileWriter"> <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.FileWriter"/> </sca:reference> </sca:component> <sca:service name="CamelService" promote="CamelServiceRoute/CamelService"> <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.CamelService"/> <ftp:binding.ftp> <operationSelector operationName="acceptMessage"/> <ftp:contextMapper/> <ftp:directory>in</ftp:directory> <ftp:host>host</ftp:host> <ftp:username>${userName}</ftp:username> <ftp:password>pwd</ftp:password> <ftp:consume> <ftp:delete>true</ftp:delete> <ftp:recursive>true</ftp:recursive> </ftp:consume> </ftp:binding.ftp> </sca:service> <sca:reference name="FileWriter" multiplicity="0..1" promote="CamelServiceRoute/FileWriter"> <sca:interface.java interface="com.example.switchyard.switchyard_myFtp.FileWriter"/> <http:binding.http> <http:contextMapper/> <http:address>http://localhost:8080/IronMan3/service/order/int</http:address> <http:method>POST</http:method> <http:contentType>text/plain</http:contentType> </http:binding.http> </sca:reference> </sca:composite> </switchyard>
my camel route is in java dsl and looks like the following
package com.example.switchyard.switchyard_myFtp; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; public class CamelServiceRoute extends RouteBuilder { /** * The Camel route is configured via this method. The from: * endpoint is required to be a SwitchYard service. */ public void configure() { // TODO Auto-generated method stub from("switchyard://CamelService").log( "Received message for 'CamelService' : ${body}") .choice() .when( ///give full xpath below xpath("//a:A/a:B = 'blah'") .namespace("a", "http://someval") ) .to("switchyard://FileWriter") // .process(new PrintResult()) .otherwise() .to("file:D:/Temp/wd"); } }
How i get the response back from the webservice in the CamelServiceRoute class above ? I tried the .process method but it prints out the entire original message versus the response.My PrintResult class is as follows
package com.example.switchyard.switchyard_myFtp; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class PrintResult implements Processor { public void process(Exchange exchange) throws Exception { String msg = exchange.getIn().getBody(String.class); System.out.println("Data received: " + msg); } }
Thanks in advance