简体   繁体   中英

data transfer from the queue to the soap server using apache camel

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM