1

I have a JSON in the queue: {"user":'Alex', "times": 34}. I want from this data to send a soap request to the server

WSDL:

wsdl

my route:

<route>
    <from uri="rabbitmq://10.0.62.201/exchange1?queue=from-lanbilling" />
    <to uri="cxf://http://0.0.0.0:8000?wsdlURL=http://localhost:8000/?wsdl" />
    <log message="message ${body}" />
</route>

how can I transform JSON data from the queue for soap request?

UPDATE

I had to use camel-http with forced soap-string xml:

blueprint:

<camelContext
    xmlns="http://camel.apache.org/schema/blueprint">

    <route>
        <from uri="rabbitmq://10.0.62.201/exchange1?queue=from-lanbilling" />
            <process ref="jTos" />      
            <log message="message ${body}" />
        <!--  <to uri="cxf://http://0.0.0.0:8000?dataFormat=PAYLOAD" />  -->
                    <setHeader headerName="Content-Type">
            <constant>application/xml; charset=utf-8</constant>
        </setHeader>
        <to uri="http://0.0.0.0:8000"/>
        <log message="message ${body}" />
    </route>


</camelContext>

JsonToSoap:

public class JsonToSoap implements Processor {

public void process(Exchange exchange) throws Exception {

    String json = exchange.getIn().getBody(String.class);
    JSONObject obj = new JSONObject(json);

    String name = obj.getString("name");
    Integer timer = obj.getInt("timer");

    String soap_xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:spy=\"spyne.examples.hello\">\r\n" + 
            "   <soapenv:Header/>\r\n" + 
            "   <soapenv:Body>\r\n" + 
            "      <spy:say_hello>\r\n" + 
            "         <spy:name>" + name +"</spy:name>\r\n" + 
            "         <spy:times>" + timer + "</spy:times>\r\n" + 
            "      </spy:say_hello>\r\n" + 
            "   </soapenv:Body>\r\n" + 
            "</soapenv:Envelope>";


    exchange.getOut().setBody(soap_xml);


}
}

how do i do the same thing only through camel-cxf? I think there is a more elegant solution.

D. Batmanov
  • 39
  • 1
  • 8

1 Answers1

2

Check out AtlasMap! (https://atlasmap.io) it has a Camel component. It supports transforming data to and from XML, JSON and Java objects.

Disclaimer: I created AtlasMap

Matt Pavlovich
  • 4,087
  • 1
  • 9
  • 17
  • How can I do this with regular tools? How generally to create soap request from camel? – D. Batmanov Feb 22 '19 at 17:01
  • 1
    A SOAP request is just an XML document over HTTP . Camel provides you a couple options- -you can send XML and use the camel-http4 component, or generate a Java object from the SOAP WSDL and use the CXF endpoint. CXF will convert the Java object to XML and send it over HTTP for you. – Matt Pavlovich Feb 22 '19 at 17:53
  • Also-- if you are using Eclipse, it has tools to generate XML from XSD. Google around and you can get sample XML generated pretty quick. .. and there is always SOAP-UI.. feed it the WSDL and it'll generate the requests too – Matt Pavlovich Feb 23 '19 at 16:22
  • please look at my UPDATE, any ideas? – D. Batmanov Feb 25 '19 at 07:04
  • @MattPavlovich I am using AtlasMap, but I have some questions. Can you please kindly look into my post https://stackoverflow.com/questions/56605561/xml-to-json-conversion-using-atlasmap – Mohammad Hasan Jun 14 '19 at 21:55
  • @MohammadHasan your question was responded by one of the core contributors to AtlasMap, so you got a good answer =). Stream processing isn't in atlasmap yet. What you could do in camel is process breaking up the stream (splitter) in Camel before you pass it to AtlasMap and then (optionally) have Camel re-assemble if re-assembly is required. If you do not need re-assembly, Camel is the better place to do the splitting ahead of having AtlasMap do the conversion. – Matt Pavlovich Jun 17 '19 at 16:28
  • 1
    @Matt Pavlovich yes that was exactly in my mind to use splitter and then use atlasMap. I will try. Anyways this is good tool for conversion. – Mohammad Hasan Jun 17 '19 at 18:34