简体   繁体   English

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

[英]Converting incoming XML to JSON in a wso2 ESB 4.6.0 Proxy

I have a proxy which takes incoming XML and preforms an xslt transform on it to get the required xml format. 我有一个代理,它接收传入的XML并对其执行xslt转换,以获得所需的xml格式。 It should then be sent to the service as JSON so i've set the messageType as application/json however it arrives as 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>

I've tried various types of builders in the axis2.xml file however none seem to change the result. 我已经在axis2.xml文件中尝试了各种类型的构建器,但是似乎都没有改变结果。 Currently running WSO2 ESB 4.6.0 当前正在运行WSO2 ESB 4.6.0

Your Code should be like this: 您的代码应如下所示:

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

And you need to enable the tags mentioned in this document:- http://docs.wso2.org/wiki/display/ESB403/ESB+and+JSON . 并且您需要启用本文档中提到的标签: -http : //docs.wso2.org/wiki/display/ESB403/ESB+and+JSON If you are not getting data in json try the service in other browser 如果您没有在json中获取数据,请尝试在其他浏览器中使用该服务

Your proxy should work with no issue. 您的代理应该没有问题。 When we set, 当我们开始

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

message will turn into json by message formatter. 消息将通过消息格式化程序转换为json。 So if we log before send, its still in xml format. 因此,如果我们在发送之前记录日志,则其仍为xml格式。 You can see the converted message using a tool like tcpmon. 您可以使用tcpmon之类的工具查看转换后的消息。

I tested following sample, pointing to 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>

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

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