json - Wso2 esb में जेसन बॉडी में एम्परसेंड कैसे पास करें I




rest wso2esb (2)

मैं ईएसबी 4.8.1 में भी उसी की कोशिश की। चूंकि मैंने अपनी त्रुटि लॉग में जावा स्क्रिप्ट त्रुटियों को देखा I ने जावा स्क्रिप्ट मध्यस्थ के रूप में भी जोड़ा नीचे नमूना एपीआई देखें।

   <api name="TestAPI" context="/test">
      <resource methods="POST" url-mapping="/status" faultSequence="fault">
         <inSequence>
            <script language="js">var symbol = mc.getPayloadXML()..*::password.toString();
               mc.setPayloadXML(
                  &lt;m:getQuote xmlns:m="http://services.samples/xsd"&gt;
                     &lt;m:request&gt;
                        &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
                     &lt;/m:request&gt;
                  &lt;/m:getQuote&gt;);</script>
            <send>
               <endpoint name="test-I_APIproductionEndpoint_0">
                  <http uri-template="http://127.0.0.1:8888/"/>
               </endpoint>
            </send>
         </inSequence>
         <outSequence>
            <send/>
         </outSequence>
      </resource>
   </api>

तब मैं निम्नानुसार अनुरोध भेजें

curl -v -X POST -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz & abc"}' http://127.0.0.1:8280/test/status

मैं देख सकता हूँ कि मेरे मूल्यों को ठीक से वापस अंत करने के लिए पास। बस पुष्टि करने के लिए कि मैं जाप संदेश को सत्यापित करने के लिए ईएसबी और बैक एंड के बीच TCPMon को जोड़ा गया। इसके साथ वापस जा रहे हैं और साइन इन करें तार लॉग यहां हैं और TCPMon आउटपुट भी संलग्न हैं।

[2016-08-10 14:30:21,236] DEBUG - wire >> "POST /test/status HTTP/1.1[\r][\n]"
[2016-08-10 14:30:21,236] DEBUG - wire >> "Host: 127.0.0.1:8280[\r][\n]"
[2016-08-10 14:30:21,236] DEBUG - wire >> "User-Agent: curl/7.43.0[\r][\n]"
[2016-08-10 14:30:21,236] DEBUG - wire >> "Accept: */*[\r][\n]"
[2016-08-10 14:30:21,236] DEBUG - wire >> "Content-Type: application/json[\r][\n]"
[2016-08-10 14:30:21,236] DEBUG - wire >> "Content-Length: 41[\r][\n]"
[2016-08-10 14:30:21,237] DEBUG - wire >> "[\r][\n]"
[2016-08-10 14:30:21,237] DEBUG - wire >> "{"username":"xyz","password":"xyz & abc"}"
[2016-08-10 14:30:21,245] DEBUG - wire << "POST /status HTTP/1.1[\r][\n]"
[2016-08-10 14:30:21,245] DEBUG - wire << "Content-Type: application/json[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "Accept: */*[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "Host: 127.0.0.1:8888[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "[\r][\n]"
[2016-08-10 14:30:21,246] DEBUG - wire << "2f[\r][\n]"
[2016-08-10 14:30:21,247] DEBUG - wire << "{"getQuote":{"request":{"symbol":"xyz & abc"}}}[\r][\n]"
[2016-08-10 14:30:21,247] DEBUG - wire << "0[\r][\n]"
[2016-08-10 14:30:21,247] DEBUG - wire << "[\r][\n]"

मेरे पास एक समस्या है जब एक JSON बॉडी वैल के अंदर एम्पर्सस पास होता है जब WSO2 esb पर एक REST API कॉल करता है, यह एक अपवाद देता है। लेकिन मुझे एएसबी के माध्यम से बैकएंड को इस '&' मान को पास करना होगा और ऐसा नहीं होगा &amp;

मैंने निम्नलिखित तरीकों से भेजने की कोशिश की, लेकिन कोई सफलता नहीं मिली

  • &amp;
  • url एन्कोडेड मान
  • हेक्साडेसिमल मान

कृपया मुझे इस समस्या को हल करने में मदद करें।

यह अपवाद है जो मुझे मिला है

[2016-08-10 13:52:26,538] ERROR -  The script engine returned an error executing the inlined js script function mediate {org.apache.synapse.mediators.bsf.ScriptMediator}
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: TypeError: error: Unexpected character encountered (lex state 3): ' ' (<Unknown Source>#1) in <Unknown Source> at line number 1
        at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
        at javax.script.CompiledScript.eval(CompiledScript.java:92)
        at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:291)
        at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:235)
        at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:203)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
        at org.apache.synapse.rest.Resource.process(Resource.java:297)
        at org.apache.synapse.rest.API.process(API.java:341)
        at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:76)
        at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:63)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:220)
        at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:344)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:385)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.mozilla.javascript.EcmaError: TypeError: error: Unexpected character encountered (lex state 3): ' ' (<Unknown Source>#1)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
        at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
        at org.mozilla.javascript.xml.impl.xmlbeans.XML.createFromJS(XML.java:388)
        at org.mozilla.javascript.xml.impl.xmlbeans.XML.jsConstructor(XML.java:3065)
        at org.mozilla.javascript.xml.impl.xmlbeans.XMLObjectImpl.execIdCall(XMLObjectImpl.java:549)
        at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
        at org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:313)
        at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2132)
        at org.mozilla.javascript.gen.c92._c0(<Unknown Source>:1)
        at org.mozilla.javascript.gen.c92.call(<Unknown Source>)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
        at org.mozilla.javascript.gen.c92.call(<Unknown Source>)
        at org.mozilla.javascript.gen.c92.exec(<Unknown Source>)
        at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55)
        ... 21 more
[2016-08-10 13:52:26,540]  WARN -  Executing fault handler due to exception encountered {org.apache.synapse.core.axis2.SynapseMessageReceiver}
[2016-08-10 13:52:26,540]  WARN -  ERROR_CODE : 0 {org.apache.synapse.FaultHandler}
[2016-08-10 13:52:26,541]  WARN -  ERROR_MESSAGE : The script engine returned an error executing the inlined js script function mediate {org.apache.synapse.FaultHandler}
[2016-08-10 13:52:26,541]  WARN -  ERROR_DETAIL : org.apache.synapse.SynapseException: The script engine returned an error executing the inlined js script function mediate
        at org.apache.synapse.mediators.AbstractMediator.handleException(AbstractMediator.java:313)
        at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:241)
        at org.apache.synapse.mediators.bsf.ScriptMediator.mediate(ScriptMediator.java:203)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
        at org.apache.synapse.rest.Resource.process(Resource.java:297)
        at org.apache.synapse.rest.API.process(API.java:341)
        at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:76)
        at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:63)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:220)
        at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:344)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:385)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: TypeError: error: Unexpected character encountered (lex state 3): ' ' (<Unknown Source>#1) in <Unknown Source> at line number 1
        at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
        at javax.script.CompiledScript.eval(CompiledScript.java:92)
        at org.apache.synapse.mediators.bsf.ScriptMediator.mediateForInlineScript(ScriptMediator.java:291)
        at org.apache.synapse.mediators.bsf.ScriptMediator.invokeScript(ScriptMediator.java:235)
        ... 18 more
Caused by: org.mozilla.javascript.EcmaError: TypeError: error: Unexpected character encountered (lex state 3): ' ' (<Unknown Source>#1)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
        at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
        at org.mozilla.javascript.xml.impl.xmlbeans.XML.createFromJS(XML.java:388)
        at org.mozilla.javascript.xml.impl.xmlbeans.XML.jsConstructor(XML.java:3065)
        at org.mozilla.javascript.xml.impl.xmlbeans.XMLObjectImpl.execIdCall(XMLObjectImpl.java:549)
        at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
        at org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:313)
        at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2132)
        at org.mozilla.javascript.gen.c92._c0(<Unknown Source>:1)
        at org.mozilla.javascript.gen.c92.call(<Unknown Source>)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
        at org.mozilla.javascript.gen.c92.call(<Unknown Source>)
        at org.mozilla.javascript.gen.c92.exec(<Unknown Source>)
        at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:55)
        ... 21 more

मैंने वायर लॉग सक्षम के साथ एक ही चीज़ की कोशिश की है और यह बिना किसी बदलाव के लिए मेरे लिए काम किया है। आपके द्वारा कोशिश की गई ESB संस्करण क्या है यदि आप तार लॉग सक्षम करते हैं तो आप क्या करेंगे और किस प्रकार निम्नानुसार निकलता है। मैंने शरीर के पैरामीटर को जोड़ा और प्रतीक दिया

[2016-08-10 11:11:05,643] DEBUG - wire >> "POST /pizzashack/1.0.0/order HTTP/1.1[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Host: 172.17.0.1:8243[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Accept: application/json[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Accept-Language: en-US,en;q=0.5[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Content-Type: application/json[\r][\n]"
[2016-08-10 11:11:05,643] DEBUG - wire >> "Authorization: Bearer 0227aad0-bc8c-3a4a-b010-fadb7582b488[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "Referer: https://127.0.0.1:9443/store/apis/info?name=PizzaShackAPI&version=1.0.0&provider=admin[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "Content-Length: 169[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "origin: https://127.0.0.1:9443[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "Connection: keep-alive[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "[\r][\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "{[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "customerName": "string&test",[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "delivered": true,[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "address": "string",[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "pizzaType": "string",[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "creditCardNumber": "string",[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "quantity": 0,[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "  "orderId": 0[\n]"
[2016-08-10 11:11:05,644] DEBUG - wire >> "}"
[2016-08-10 11:11:05,647] DEBUG - wire << "POST /am/sample/pizzashack/v1/api/order HTTP/1.1[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Accept: application/json[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "origin: https://127.0.0.1:9443[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Referer: https://127.0.0.1:9443/store/apis/info?name=PizzaShackAPI&version=1.0.0&provider=admin[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Accept-Language: en-US,en;q=0.5[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Host: localhost:9443[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "a9[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "{[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "customerName": "string&test",[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "delivered": true,[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "address": "string",[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "pizzaType": "string",[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "creditCardNumber": "string",[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "quantity": 0,[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "  "orderId": 0[\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "}[\r][\n]"
[2016-08-10 11:11:05,647] DEBUG - wire << "0[\r][\n]"
[2016-08-10 11:11:05,648] DEBUG - wire << "[\r][\n]"




ampersand