WSO2 API管理器将JSON转换为XML(并导致请求失败)

时间:2018-09-13 16:03:14

标签: wso2 wso2-am

我们将WSO2 API管理器用作API网关。我拥有的API之一是仅JSON的非静态API。它使用HTTP POST请求和JSON作为数据交换格式。我对此有一个非常基本的配置:配置为允许POST / *的REST API。

一些响应包括JSON,它具有诸如"P~A"之类的字符串作为对象键。当我尝试通过网关调用此命令时,它会阻塞响应:

2018-09-13 18:37:37,890 [-] [PassThroughMessageProcessor-36] ERROR JsonUtil #writeAsJson. Could not convert OMElement to JSON. Invalid XML payload. Error>>> Unexpected character '~' (code 126) excepted space, or '>' or "/>"
 at [row,col {unknown-source}]: [1,4956]
2018-09-13 18:37:37,891 [-] [PassThroughMessageProcessor-36] ERROR PassThroughHttpSSLSender Failed to submit the response
org.apache.axis2.AxisFault: Could not convert OMElement to JSON. Invalid XML payload.
        at org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:372)
        at org.apache.synapse.commons.json.JsonFormatter.writeTo(JsonFormatter.java:84)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.submitResponse(PassThroughHttpSender.java:573)
        at org.apache.synapse.transport.passthru.PassThroughHttpSender.invoke(PassThroughHttpSender.java:264)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
        at org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:230)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:531)
        at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:118)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
        at org.apache.synapse.rest.Resource.process(Resource.java:343)
        at org.apache.synapse.rest.API.process(API.java:338)
        at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:90)
        at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:56)
        at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:304)
        at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:554)
        at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:188)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:262)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '~' (code 126) excepted space, or '>' or "/>"
 at [row,col {unknown-source}]: [1,4956]
        at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:647)
        at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:2996)
        at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2963)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2839)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1073)
        at javax.xml.stream.util.StreamReaderDelegate.next(Unknown Source)
        at javax.xml.stream.util.StreamReaderDelegate.next(Unknown Source)
        at org.codehaus.stax2.ri.Stax2ReaderAdapter.next(Stax2ReaderAdapter.java:129)
        at org.codehaus.stax2.ri.Stax2EventReaderImpl.peek(Stax2EventReaderImpl.java:367)
        at org.apache.synapse.commons.staxon.core.event.SimpleXMLEventWriter.add(SimpleXMLEventWriter.java:118)
        at org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:368)
        ... 23 more
2018-09-13 18:37:37,892 [-] [PassThroughMessageProcessor-36] ERROR Axis2Sender Access-Control-Allow-Headers:authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction,Access-Control-Allow-Methods:HEAD,DELETE,POST,PATCH,PUT,GET,Access-Control-Allow-Origin:*,Content-Type:application/json;charset=utf-8,<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject>

(然后继续并包含XML,该XML尝试将JSON中的"P~A"密钥用作<P~A> XML标签,这正是它所扼制的内容)

API定义 not 没有启用消息中介,并且还禁用了响应缓存。因此,我不清楚为什么它甚至使用中介器并尝试将JSON响应完全转换为XML。

所以,问题是:如何使它工作?通过配置它来处理将其转换为XML还是不需要?

我还要指出,此过程中需要花费很长时间。得到(错误)响应需要很长时间,但是我看到响应数据很快到达了API管理器。

我们也正在运行WSO2 Analytics服务。我试图阻止它,以防它引起问题。没有帮助

0 个答案:

没有答案