我正在使用 JSON 有效负载发布到 ESB (4.6.0) 代理服务。这是一个传递代理服务,它路由到一个 jaggery JS 应用程序。jaggery 应用程序正在尝试从有效负载访问 JSON,但由于 JSON 字符串已转义,因此无法访问。
以下是请求标头(来自 web --> ESB):
POST /services/testJaggPS HTTP/1.1
Host: pb-dvwa8:7280
Content-Length: 29
Cache-Control: no-cache
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
{
"PARAM": "hello world"
}
以下是来自 jaggery 应用程序的 JSON 响应:
{"RESPONSE" : {"test" : "hi", "PARAM" : null, "content" : "{\n \"PARAM\" : \"HELLO WORLD\" \n}"}}
请注意,“内容”(存储来自网络的 JSON 有效负载的变量)正在被转义。
我研究了消息生成器/格式化程序,但它并没有解决这个问题。这是我当前的代理服务(可能不需要所有的消息生成器):
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testJaggPS"
transports="https http"
startOnLoad="true"
trace="disable">
<target endpoint="jaggRouter">
<inSequence>
<builder>
<messageBuilder contentType="application/xml"
class="org.apache.axis2.builder.ApplicationXMLBuilder"
formatterClass="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
<messageBuilder contentType="application/xop+xml"
class="org.apache.axis2.builder.MTOMBuilder"/>
<messageBuilder contentType="multipart/related"
class="org.apache.axis2.builder.MIMEBuilder"/>
<messageBuilder contentType="application/json"
class="org.apache.axis2.json.JSONBuilder"
formatterClass="org.apache.axis2.json.JSONMessageFormatter"/>
<messageBuilder contentType="application/x-www-form-urlencoded"
class="org.apache.axis2.builder.XFormURLEncodedBuilder"
formatterClass="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
<messageBuilder contentType="text/xml"
class="org.apache.axis2.builder.SOAPBuilder"
formatterClass="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
<messageBuilder contentType="application/soap+xml"
class="org.apache.axis2.builder.SOAPBuilder"
formatterClass="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
<messageBuilder contentType="application/json/badgerfish"
class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
</builder>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="contentType" value="application/json" scope="axis2"/>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="contentType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</target>
</proxy>
这是我的粗略代码:
<% // load core files response.contentType = 'application/json'; var url = request.getRequestURL(); var theContent = request.getContent(); // note null 'PARAM' and escaped 'content' response.content = {"RESPONSE" : { "test" : "hi", "PARAM" : theContent.PARAM, "content" : theContent }}; %>