无法解析 OutSequence wso2 esb 中的 JSON 响应?

Can't parse JSON response in the OutSequence wso2 esb?

在 Outsequence 的开头我使用了这个:

<property name="messageType" value="application/JSON" scope="axis2"/>

但我仍然收到错误消息 Content not allowed in prolog。

如果我不使用任何中介直接将响应发送给客户端,我不会收到任何错误。

下面是完整的堆栈跟踪:

[2015-07-07 12:11:35,747] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
        at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
        at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:55)
        at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:138)
        at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:107)
        at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:82)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:68)
        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.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:268)
        at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
        at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool.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)

我能够解析 JSON 响应。

使用的 WSO2 ESB 版本 - 4.8.1

下面是代理代码。

   <?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="JsonProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <log level="full">
                <property name="################ REQUEST ###################" expression="$body"/>
            </log>
            <send>
                <endpoint>
                    <address uri="http://ip.jsontest.com/"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
            <log level="full">
                <property name="################ RESPONSE###################" expression="$body"/>
            </log>
            <log>
                <property name="::::::::::::::::::::::::::::: JSON :::::::::::::::::::::::::::" expression="json-eval($.)"/>
            </log>
            <send/>
        </outSequence>
    </target>
    <description/>
</proxy>

请交叉检查以下行是否仅在 axis2.xml

中未注释
<messageFormatter contentType="application/json"
                          class="org.apache.synapse.commons.json.JsonStreamFormatter"/>

<messageFormatter contentType="application/json/badgerfish"
                          class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>

<messageBuilder contentType="application/json"
                        class="org.apache.synapse.commons.json.JsonStreamBuilder"/>

<messageBuilder contentType="application/json/badgerfish"
                        class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>