WSO2 ESB有效负载工厂XML异常

时间:2017-03-22 00:39:06

标签: wso2 wso2esb

最近,任何在我的ESB上调用API资源的尝试都会在payloadFactory运行时导致XML异常(下面的堆栈跟踪)。完全删除payloadFactory似乎是解决此问题的唯一方法。我可以没有args,空格式,或完全静态的args和格式,应该有用,并且昨天工作了!

构建在ESB 5.0.0上,这样的资源示例如下所示:

<resource methods="POST" uri-template="/someUrl">
    <inSequence>
        <property name="acceptedRoles" value="RMD" scope="default" type="STRING/>
        <property name="myProp" value="json-eval($)" scope="default" type="STRING"/>
        <Package.ConnectorOne/>
        <Package.ConnectorTwo/>
        <loopback/>
    </inSequence>
    <outSequence>
        <payloadFactory media-type="json">
            <format>{"statusCode":$1,"errorMessage":"$2","errors":$3}</format>
            <args>
                <arg evaluator="xml" expression="get-property('statusCode')/>
                <arg evaluator="xml" expression="get-property('errorMessage')/>
                <arg evaluator="xml" expression="get-property('errors')/>
            </args>
        <payloadFactory>
        <send/>
    </outSequence>
    <faultSequence/>
</resource>

异常堆栈跟踪:

TID[-1234] [ESB] [2017-03-21 19:22:33,024] ERROR
{API_LOGGER.FleetManagement} - javax.xml.stream.XMLStreamException:
Unexpected symbol: START_OBJECT
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
org.apache.axiom.om.impl.llom.OMElementImpl.buildNext(OMElementImpl.java:653
)
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.buildNext(OMSourcedElemen
tImpl.java:880)
org.apache.axiom.om.impl.llom.OMNodeImpl.getNextOMSibling(OMNodeImpl.java:12
2)
org.apache.axiom.om.impl.llom.OMElementImpl.getNextOMSibling(OMElementImpl.j
ava:343)
org.apache.axiom.om.impl.traverse.OMChildrenIterator.getNextNode(OMChildrenI
terator.java:36)
org.apache.axiom.om.impl.traverse.OMAbstractIterator.hasNext(OMAbstractItera
tor.java:58)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:41
8)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:42
5)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:587
)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:654
)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:173)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:104)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:338)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:5
6)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediat
or.java:63)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:399)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:6
9)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageR
eceiver.java:75)
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosing
RESTHandler(ServerWorker.java:325)
org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingReq
uest(ServerWorker.java:371)
org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151
)
org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerP
ool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

javax.xml.stream.XMLStreamException: Unexpected symbol: START_OBJECT
org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
org.apache.axiom.om.impl.llom.OMElementImpl.buildNext(OMElementImpl.java:653
)
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.buildNext(OMSourcedElemen
tImpl.java:880)
org.apache.axiom.om.impl.llom.OMNodeImpl.getNextOMSibling(OMNodeImpl.java:12
2)
org.apache.axiom.om.impl.llom.OMElementImpl.getNextOMSibling(OMElementImpl.j
ava:343)
org.apache.axiom.om.impl.traverse.OMChildrenIterator.getNextNode(OMChildrenI
terator.java:36)
org.apache.axiom.om.impl.traverse.OMAbstractIterator.hasNext(OMAbstractItera
tor.java:58)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:41
8)
org.apache.synapse.commons.json.JsonUtil.removeIndentations(JsonUtil.java:42
5)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:587
)
org.apache.synapse.commons.json.JsonUtil.getNewJsonPayload(JsonUtil.java:654
)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:173)
org.apache.synapse.mediators.transform.PayloadFactoryMediator.mediate(Payloa
dFactoryMediator.java:104)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:338)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:5
6)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.mediators.builtin.LoopBackMediator.mediate(LoopBackMediat
or.java:63)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:97)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediat
or.java:59)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.
java:158) org.apache.synapse.rest.Resource.process(Resource.java:343)
org.apache.synapse.rest.API.process(API.java:399)
org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.jav
a:123)
org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.
java:101)
org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:6
9)
org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2Syn
apseEnvironment.java:304)
org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageR
eceiver.java:75)
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosing
RESTHandler(ServerWorker.java:325)
org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingReq
uest(ServerWorker.java:371)
org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151
)
org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerP
ool.java:172) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown
Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

2 个答案:

答案 0 :(得分:1)

我猜问题是在将参数传递给json时有效负载工厂介体中的表达式类型。

*<payloadFactory media-type="json">
            <format>{"statusCode":$1,"errorMessage":"$2","errors":$3}</format>
            <args>
                <***arg evaluator="xml"*** expression="get-property('statusCode')/>
                <arg evaluator="xml" expression="get-property('errorMessage')/>
                <arg evaluator="xml" expression="get-property('errors')/>
            </args>
        <payloadFactory>*

arg evaluationator =“xml” expression =“get-property('statusCode')的值从xml更改为 arg evaluateator = “json” expression =“get-property('statusCode')json并尝试一下。我认为异常是由于将xml解析为json。

评论错误是否得到解决。 感谢

答案 1 :(得分:1)

您尝试注入json有效负载的参数可能不是intboolean,这会导致解析异常。

试试这个:

 <payloadFactory media-type="json">
            <format>{"statusCode":"$1","errorMessage":"$2","errors": "$3"}</format>
            <args>
                <arg evaluator="xml" expression="get-property('statusCode')/>
                <arg evaluator="xml" expression="get-property('errorMessage')/>
                <arg evaluator="xml" expression="get-property('errors')/>
            </args>
<payloadFactory>

要查看调解期间发生的详细情况,请尝试设置突触记录器(org.apache.synapse)并将日志连接到DEBUG。