Hello, I am trying to use camel as a component in ServiceMix. The component is well configured so that a route is defined in a class that extends RouteBuilder. The incoming message is like this: <message xmlns="http://servicemix.apache.org/test3">Hello</message>.
Then, I would like to make some transformations: - convert the xml in SOAP message so that it can be send to a Web Service - convert back SOAP response to XML: <helloResponse xmlns:odens="http://ode/bpel/unit-test.wsdl"> <TestPart xmlns:q0="http://ode/bpel/unit-test.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Hello World</TestPart> </helloResponse> ----> <message xmlns="http://servicemix.apache.org/test3">Hello World</message> I tried this: public void configure() { from("jbi:service:http://www.servicemix.org/example/my-service-camel") .process(new XMLProcessor()); } private class XMLProcessor implements Processor { public void process(Exchange exch) throws Exception { System.out.println("Channel : " + channel); Message inMessage = exch.getIn(); String jaxbContext1 = "org.apache.servicemix.test3"; String inputWS = null; try { // XML UNMARSHAL JAXBContext jc = JAXBContext.newInstance(jaxbContext1); Unmarshaller u = jc.createUnmarshaller(); // ------------------------------------------- // this doesn't work //Object appDefaults = u.unmarshal(new ByteArrayInputStream(inMessage.getBody().toString().getBytes())); // ------------------------------------------- Object appDefaults = u.unmarshal(new ByteArrayInputStream("<message xmlns=\"http://servicemix.apache.org/test3\">Hello</message>".getBytes())); inputWS = ((JAXBElement<String>)appDefaults).getValue(); System.out.println(inputWS); } catch (Exception e) { e.printStackTrace(); } // generate the SOAP output HelloWorld hw = new HelloWorld(); HelloWorldPortType client = hw.getHelloWorldSOAP11PortHttp(); // call the web service String output = client.hello(inputWS); try { // XML MARSHAL JAXBContext context = JAXBContext.newInstance(jaxbContext1); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); marshaller.marshal(new ObjectFactory().createMessage(output), baos); Message m = new DefaultMessage(); m.setBody(baos.toString()); // ------------------------------------------- // this doesn't work exch.setOut(m); // ------------------------------------------- } catch (Exception e) { e.printStackTrace(); } } } 1) When I call exch.getIn().getBody().toString(), I am not getting the body. How can I get the true body? 2) Forcing the body I receive, I can see a OK response is send, but the message is not send back. What's wrong with the exch.setOut(m)? Is there another solution to send a response? Thank you for your answers. -- View this message in context: http://www.nabble.com/RouteBuilder%3A-how-to-get-the-body-and-to-manually-send-a-response--tp23836381p23836381.html Sent from the Camel - Users mailing list archive at Nabble.com.
