I'm having troubles processing a plain XML response from my REST API in a WSO2 ESB (4.8.1) proxy service. My outSequence obviously expexcts the API call result payload to be a SOAP message which it is not (plain XML) resulting in error while further processing it. I use the HTTP Endpoint but the same error occures when using the Address Endpoint. I have to use GET as the request method as the API does not allow POX. (The issue seems to be similar to the one already mentioned in WSO2 ESB: log and convert response from the RDF REST service back to SOAP however it does not seem to be fixed in ESB 4.8.1 and I'am unable to use the work-around mentioned there)
Here is my endpoint:
<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>
Here is the proxy:
<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>
This is the response I get from the API:
<?xml version="1.0" encoding="UTF-8"?>
<ticket>TICKET_605cbf0977db895db9bbc6e5eb6d4dba75454cc4</ticket>
And this the error I get once I try to log the response:
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
Anyone here finding a fix for this?
In the end the main problem showed up to be in proper MessageBuilder configuration. As long as the service response was a simple XML and as such it was marked in the response header, WSO2 passed it to the client just fine. Once the response was marked differently - in my case it was application/atom+xml, the default MessageBuilder did not applied and thus WSO2 expected the contnent to be SOAP. I added a builder configuration to the \repository\conf\axis2\axis2.xml:
Works fine now.
See https://docs.wso2.com/display/ESB480/Working+with+Message+Builders+and+Formatters and https://docs.wso2.com/display/ESB402/Message+Relay+Building+Blocks