我在WSO2 ESB(4.8.1)代理服务中处理来自REST API的纯XML响应时遇到了麻烦。我的outSequence显然将API调用结果有效负载转换为SOAP消息,它不是(纯XML),在进一步处理时会导致错误。我使用HTTP端点但使用地址端点时会出现相同的错误。我必须使用GET作为请求方法,因为API不允许使用POX。 (这个问题似乎与WSO2 ESB: log and convert response from the RDF REST service back to SOAP中已经提到过的问题相似,但它似乎没有在ESB 4.8.1中得到修复,而且我无法使用那里提到的解决方法。
这是我的终点:
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Alfresco_login">
<http uri-template="http://localhost:8080/alfresco/service/api/login?u={query.param.name}&pw={query.param.password}" method="get"></http>
</endpoint>
这是代理:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Alfresco_proxy"
transports="https,http">
<target endpoint="Alfresco_login">
<inSequence>
<property name="query.param.name" value="XXX"/>
<property name="query.param.password" value="XXX"/>
</inSequence>
<outSequence>
<log/>
<send/>
</outSequence>`enter code here`
</target>
<description/>
</proxy>
这是我从API获得的回复:
<?xml version="1.0" encoding="UTF-8"?>
<ticket>TICKET_605cbf0977db895db9bbc6e5eb6d4dba75454cc4</ticket>
这是我尝试记录响应后得到的错误:
ERROR_EXCEPTION : org.apache.synapse.SynapseException: Error while building message
ERROR_DETAIL : org.apache.synapse.SynapseException: Error while building message at org.apache.synapse.mediators.AbstractMediator.handleException(AbstractMediator.java:313) at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70) 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$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.apache.axis2.AxisFault: Error while building Passthrough stream at org.apache.synapse.transport.passthru.util.RelayUtils.handleException(RelayUtils.java:236) at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:111) at org.apache.synapse.transport.passthru.util.RelayUtils.buildMessage(RelayUtils.java:82) at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:68) ... 11 more Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found ticket at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234) at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249) 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:118) at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:107) ... 13 more
有人在这里找到了解决方法吗?
答案 0 :(得分:5)
最后,主要问题出现在正确的MessageBuilder配置中。只要服务响应是一个简单的XML并且因此它在响应头中标记,WSO2就将它传递给客户端就好了。一旦响应标记不同 - 在我的情况下它是application / atom + xml,默认的MessageBuilder没有应用,因此WSO2期望contnent是SOAP。我将构建器配置添加到\ repository \ conf \ axis2 \ axis2.xml:
<messageBuilder class="org.apache.axis2.builder.ApplicationXMLBuilder" contentType="application/atom+xml"/>
现在工作正常。
请参阅https://docs.wso2.com/display/ESB480/Working+with+Message+Builders+and+Formatters和https://docs.wso2.com/display/ESB402/Message+Relay+Building+Blocks