java - 使用apache Camel从队列到soap服务器的数据传输

标签 java soap apache-camel cxf camel-cxf

我的队列中有一个 JSON:{"user":'Alex', "times": 34}。 我想从这些数据向服务器发送 SOAP 请求

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>

如何转换来自 SOAP 请求队列的 JSON 数据?

更新

我必须使用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)它有一个Camel组件。它支持在 XML、JSON 和 Java 对象之间进行数据转换。

免责声明:我创建了 AtlasMap

关于java - 使用apache Camel从队列到soap服务器的数据传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54821304/

相关文章:

Android WSDL/SOAP 服务客户端

Java网络服务: null request parameter

java - 即使MQTT服务器无法访问,如何启动camel

error-handling - Camel ErrorHandler useOriginalMessage属性

java - JsonObject 添加属性 - map

java - Mockito 模拟列表时出现问题

java变量声明

java - 为什么我在 .setOnTouchListener() 上遇到 nullpointerException?

当服务器发回错误响应时,PHP SoapClient 返回 null

java - 根据文件夹内容暂停 apache Camel 路由