0
在WSO2 ESB 4.8.1中,实现了一个接收json消息的API,并将新的json负载发送到后端。我调试API,我看到它将我的json有效载荷转换为xml,然后将其发送到后端。创建json,而不是在WSO2中发送XML ESB
仅供参考:我已经对axis2配置文件中的json流格式化程序和生成器取消了注释。
API源是:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="SdpProductStatus" context="/SdpServices/1/Aggregator/Product/Status">
<resource methods="POST">
<inSequence>
<property name="messageType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="ContentType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="productId" expression="json-eval($.productId)" scope="default" type="STRING" />
<property name="customerId" expression="json-eval($.customerId)" scope="default" type="STRING" />
<property name="description" expression="json-eval($.description)" scope="default" type="STRING" />
<property name="time" expression="json-eval($.time)" scope="default" type="STRING" />
<property name="state" expression="json-eval($.state)" scope="default" type="STRING" />
<log />
<property name="time" expression="concat(substring($ctx:time,1,4),'-',substring($ctx:time,5,2),'-',substring($ctx:time,7,2),' ',substring($ctx:time,10,2),':',substring($ctx:time,12,2),':',substring($ctx:time,14,2))" scope="default" type="STRING" />
<script language="js">mc.setProperty("state", mc.getProperty("state").replace("0","deactive")); mc.setProperty("state", mc.getProperty("state").replace("1","active"));</script>
<property name="POST_TO_URI" value="true" scope="axis2" />
<property name="REST_URL_POSTFIX" value="ActiveOrDeactive" scope="axis2" type="STRING" />
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2" type="STRING" />
<property name="messageType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="ContentType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<header name="Accept" scope="transport" value="application/json" />
<header name="Content-Type" scope="transport" value="application/json" />
<header name="ContentType" scope="transport" value="application/json" />
<payloadFactory media-type="json">
<format>{"productID":"$1","CustomerID":"$2", "Time":"$3","State":"$4","tempData":"$5","Description":"$6","Username":"$7","Password":"$8", "Instruction":"$9"}</format>
<args>
<arg evaluator="xml" expression="$ctx:productId" />
<arg evaluator="xml" expression="$ctx:customerId" />
<arg evaluator="xml" expression="$ctx:time" />
<arg evaluator="xml" expression="$ctx:state" />
<arg evaluator="xml" value="temp" />
<arg evaluator="xml" expression="$ctx:description" />
<arg value="test1" />
<arg value="test1" />
<arg value="create" />
</args>
</payloadFactory>
<log>
<property name="body" expression="json-eval($.)" />
</log>
<send buildmessage="true">
<endpoint>
<address uri="http://10.8.10.10:8080/service1.svc/" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log />
<property name="message" expression="json-eval($.MESSAGE)" scope="default" type="STRING" />
<filter source="json-eval($.STATUS)" regex="-?\d.*">
<then>
<property name="statusCode" value="200" scope="default" type="STRING" />
</then>
<else>
<property name="statusCode" expression="json-eval($.STATUS)" scope="default" type="STRING" />
</else>
</filter>
<property name="messageType" value="application/json" scope="axis2" type="STRING" />
<header name="Accept" scope="transport" value="application/json" />
<payloadFactory media-type="json">
<format>{"productId":$1,"id":"$2","customerId":"$3","status":{"statusCode":$4,"message":"$5"}}</format>
<args>
<arg evaluator="xml" expression="$ctx:productId" />
<arg evaluator="xml" value="55" />
<arg evaluator="xml" expression="$ctx:customerId" />
<arg evaluator="xml" expression="$ctx:statusCode" />
<arg evaluator="xml" expression="$ctx:message" />
</args>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/json" />
<send />
</outSequence>
</resource>
</api>
这是我所得到的在后端:
<jsonobject>....my payload converted to xml...</jsonobject>
谢谢,这没有奏效。但是我发现这个错误,我明天会写回答,应该是 ' 'not'属性名称=“messageType”value =“application/json; charset = utf-8;” scope =“axis2”type =“STRING”/>'在api的第一行按顺序排列。 –