Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java WSO2 ESB JSON到SOAP_Java_Rest_Soap_Wso2_Wso2esb - Fatal编程技术网

Java WSO2 ESB JSON到SOAP

Java WSO2 ESB JSON到SOAP,java,rest,soap,wso2,wso2esb,Java,Rest,Soap,Wso2,Wso2esb,当前的大多数文档都是关于SOAP到JSON的,我希望在使用WSO2 ESB将JSON响应对象转换为SOAP服务时,是否有参考资料或教程。提前谢谢 样本服务: AFAIU您希望使用json内容调用soap服务并获得json响应。如果这是您的需求,示例将对您有所帮助。如果您希望允许SOAP客户端通过WSO2ESB访问REST服务,那么这是可能的。看看这个示例: 您可以做的是创建一个位于REST服务前面的SOAP代理服务。然后,该代理服务将接收SOAP请求,将请求转换为REST请求并转发给REST服务

当前的大多数文档都是关于SOAP到JSON的,我希望在使用WSO2 ESB将JSON响应对象转换为SOAP服务时,是否有参考资料或教程。提前谢谢

样本服务:

AFAIU您希望使用json内容调用soap服务并获得json响应。如果这是您的需求,示例将对您有所帮助。

如果您希望允许SOAP客户端通过WSO2ESB访问REST服务,那么这是可能的。看看这个示例:


您可以做的是创建一个位于REST服务前面的SOAP代理服务。然后,该代理服务将接收SOAP请求,将请求转换为REST请求并转发给REST服务。然后,它可以将JSON中的REST响应转换为SOAP响应并返回到SOAP客户端

您可以通过以下类似的配置来实现这一点:;(我们必须将“messageType”属性设置为“text/xml”,以便在响应客户端时使用SOAP消息生成器。)


但是,如果您的JSON响应对象与您从提供的示例服务中获得的对象完全相同(即,如果它是一个匿名对象数组),那么ESB将减少响应以仅包含第一个元素(请参见下面的SOAP响应)


1.
10260
曼彻斯特联队
21
17
1.
3.
54
28
26
52
冠军联赛

我可以在ESB 4.5.0中通过以下步骤转换完整的JSON负载。这些步骤涉及更改应用程序/json内容类型的消息生成器和消息格式化程序

更改JSON的消息生成器、格式化程序;在CARBON_HOME/repository/conf/axis2/axis2.xml文件中,通过注释掉以下行,断开默认消息生成器和消息格式化程序

<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONBuilder"/>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONStreamFormatter"/>
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONStreamBuilder"/>

通过取消以下行的注释,使JSONStreamBuilder和JSONStreamFormatter参与进来

<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONBuilder"/>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONStreamFormatter"/>
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONStreamBuilder"/>

编写一个Javascript函数来转换和构建新的XML负载

function transformRequest(mc) {
    var array = mc.getPayloadJSON();
    var payload = <games/>;

    for (i = 0; i < array.length; ++i) {
        var elem = array[i];
        payload.game += <game>
            <position>{elem.position}</position>
            <team_id>{elem.team_id}</team_id>
            <team>{elem.team}</team>
            <played>{elem.played}</played>
            <won>{elem.won}</won>
            <drawn>{elem.drawn}</drawn>
            <lost>{elem.lost}</lost>
            <for>{elem["for"]}</for>
            <against>{elem.against}</against>
            <difference>{elem.difference}</difference>
            <points>{elem.points}</points>
            <info>{elem.info}</info>
        </game>
    }
    mc.setPayloadXML(payload);
}
功能转换请求(mc){
var array=mc.getPayloadJSON();
var有效载荷=;
对于(i=0;i
修改outSequence以对传入的JSON负载执行转换

<outSequence>
    <script language="js" key="conf:/repository/esb/scripts/transformrequest.js" function="transformRequest"/>
    <property name="messageType" value="text/xml" scope="axis2"/>
    <send/>
</outSequence>


感谢阿米拉的回复,但不幸的是,这不是我的要求。我共享的示例服务链接是一个rest服务,它在调用后发送JSON响应。我想知道的是,是否有可能将这个JSON响应转换为SOAP响应。不幸的是,JSON响应与上面的非常相似,ESB只包含SOAP响应中的第一个元素,这一问题的任何可能解决方法?Mohamed,我建议了一种新方法来完成您的需求。