简体   繁体   中英

How to get rid of xmlPayload when posting JSON Array through WSO2 API Manager?

We've set up WSO2 API Manager 1.6 and want to have a RESTful webservice behind it. But when we send a JSON array to the webservice it gets modified.

We're using the axis2.xml_PT because we just want passthrough of the message. In Publisher I've set the endpoint to be a URL endpoint with "format" and "optimize" options set to "leave as is". But when I run this command:

curl -H "Content-Type: application/json" -k -d '[{"price":"9,99"},{"price":"24,99"}]' -v 'http://our.url.here:8280/calle/0.1/'

this is what is sent to the webservice behind the API Manager (captured using nc -l 1234 )

POST http://10.87.16.127:1234/ HTTP/1.1
Content-Type: application/json
Accept: */*
activityID: 1277246320952979749505377
Transfer-Encoding: chunked
Host: 1.2.3.4:1234
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO

33
{"xmlPayload":[{"price":"9,99"},{"price":"24,99"}]}
0

Where did "xmlPayload" come from? I don't want the message to be read or modified, just passed through.

How can i get the desired behavior? When posting a JSON Object instead of an array it seems to work fine.

UPDATE 1: If I use Content-Type: text/plain the message passes through untouched.

UPDATE 2: I edited axis2.xml like this and the message got through OK. Is this the right way to do it?

$ diff -Nur axis2.xml.bup axis2.xml
--- axis2.xml.bup   2014-09-18 11:12:04.851000719 +0000
+++ axis2.xml   2014-09-18 11:26:29.421472188 +0000
@@ -167,7 +167,7 @@

         <!--JSON Message Formatters-->
         <messageFormatter contentType="application/json"
-                          class="org.apache.axis2.json.JSONMessageFormatter"/>
+                          class="org.apache.axis2.format.PlainTextFormatter"/>
         <!--messageFormatter contentType="application/json"
                           class="org.apache.axis2.json.JSONStreamFormatter"/-->
         <messageFormatter contentType="application/json/badgerfish"
@@ -229,7 +229,7 @@

         <!--JSON Message Builders-->
         <messageBuilder contentType="application/json"
-                        class="org.apache.axis2.json.JSONBuilder"/>
+                        class="org.apache.axis2.format.PlainTextBuilder"/>
         <!--messageBuilder contentType="application/json"
                         class="org.apache.axis2.json.JSONStreamBuilder"/-->
         <messageBuilder contentType="application/json/badgerfish"

If you need to pass JSON request pay load without touching them you may use following configuration. Then it will pass request payload without building according to any specific content type. Usually we do recommend this builder formatter for unknown data types and when you wanted to just pass through without building according to specific type.

<messageBuilder contentType="text/json"
                  class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

Please let us know above solutions worked or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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