Hi, 1) Since the servicemix-camel component store the XML message as Source.class, you can't get XML String by calling toString() method. But you can leverage the Camel's converter[1] to get XML String.
exch.getIn().getBody(String.class) 2) If you want to send the response back , you need to set the endpoint's the Message Exchange Pattern to be InOut [2]. Please try to set the jbi service endpoint uri like this. "jbi:service:http://www.servicemix.org/example/my-service-camel?mep=in-out" [1] http://camel.apache.org/type-converter.html [2] http://camel.apache.org/request-reply.html Willem Fly13DW wrote: > 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.