在wso2 ESB 4.6.0代理中将传入的XML转换为JSON

时间:2013-07-23 13:12:08

标签: xml json wso2 wso2esb

我有一个代理,它接收传入的XML并对其执行xslt转换以获得所需的xml格式。 然后它应该作为JSON发送到服务,所以我将messageType设置为application / json但是它以XML形式到达。

<proxy xmlns="http://ws.apache.org/ns/synapse" name="XSLTTRANSPROXY_BRYN" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <xslt key="gov:/Complete.xsl">
            <property xmlns:ns="http://org.apache.synapse/xsd" name="GUID" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')"/>
         </xslt>
        <property name="messageType" value="application/json" scope="axis2"/>
         <log level="full"/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
      <endpoint>
         <address uri="http://localhost:54150/"/>
      </endpoint>
   </target>
   <description></description>
</proxy>

我在axis2.xml文件中尝试了各种类型的构建器,但似乎都没有改变结果。 目前正在运行WSO2 ESB 4.6.0

3 个答案:

答案 0 :(得分:3)

您的代码应该是这样的:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="XSLTTRANSPROXY_BRYN" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <xslt key="gov:/Complete.xsl">
            <property xmlns:ns="http://org.apache.synapse/xsd" name="GUID" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')"/>
         </xslt>
        <property name="messageType" value="application/json" scope="axis2"/>
         <log level="full"/>
<send>
<endpoint>
         <address uri="http://localhost:54150/"/>
      </endpoint>
</send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
         </target>
   <description></description>
</proxy>

您需要启用本文档中提到的代码: - http://docs.wso2.org/wiki/display/ESB403/ESB+and+JSON。如果您没有在json中获取数据,请在其他浏览器中尝试该服务

答案 1 :(得分:1)

您的代理应该没有问题。当我们设置时,

<property name="messageType" value="application/json" scope="axis2"/>

消息将由消息格式化程序变为json。因此,如果我们在发送之前记录,它仍然是xml格式。您可以使用tcpmon等工具查看转换后的消息。

我测试了以下示例,指向tcpmon。

<proxy name="TestProxy"
          transports="https http"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <endpoint>
            <address uri="http://localhost:8888/"/>
         </endpoint>
         <inSequence>
            <property name="messageType" value="application/json" scope="axis2"/>
            <log level="full"/>
         </inSequence>
         <outSequence>
            <send/>
         </outSequence>
      </target>
   </proxy>

答案 2 :(得分:0)

请按照以下链接中的说明操作 http://docs.wso2.org/wiki/display/ESB403/ESB+and+JSON