繁体   English   中英

使用apache骆驼将数据从队列传输到soap服务器

[英]data transfer from the queue to the soap server using apache camel

我在队列中有一个JSON: {"user":'Alex', "times": 34} 我想从此数据发送肥皂请求到服务器

WSDL:

WSDL

我的路线:

<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>

我如何从队列中转换JSON数据以进行肥皂请求?

UPDATE

我不得不将camel-http与强制的soap-string xml一起使用:

蓝图:

<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);


}
}

我如何仅通过camel-cxf做同样的事情? 我认为有一个更优雅的解决方案。

看看AtlasMap! https://atlasmap.io )它具有骆驼组件。 它支持在XML,JSON和Java对象之间来回转换数据。

免责声明:我创建了AtlasMap

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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