2017-05-22 36 views
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> 

回答

0

你能<header name="Content-Type" scope="transport" value="application/json" />建設payloadFactory過嗎?

<property name="messageType" value="application/json" scope="axis2" type="STRING" /> 
<header name="Accept" scope="transport" value="application/json" /> 
<header name="Content-Type" scope="transport" value="application/json" /> 

OR

嘗試像下面,在這裏我跳過 「評估=」 XML 「」。

 <args> 
      <arg expression="$ctx:productId"/> 
      <arg value="55"/> 
      <arg expression="$ctx:customerId"/> 
     </args> 
+0

謝謝,這沒有奏效。但是我發現這個錯誤,我明天會寫回答,應該是 ''not'屬性名稱=「messageType」value =「application/json; charset = utf-8;」 scope =「axis2」type =「STRING」/>'在api的第一行按順序排列。 –