Reputation: 33
I have a Mule flow that is attempting to use an element to dispatch a single request to two different XML-returning RESTful web services (via outbound http endpoints) and then have the flow return the results in a single merged XML response with a single outer element tag. INSTEAD I'm merely getting a concatenation of the two XML responses.
i.e. the incorrect response I'm getting looks something like this (I've deleted the extra details of the XML):
<scans>
<scan> .... </scan>
<scan> ... </scan>
<scan> ... </scan>
</scans>
<scans>
<scan> ... </scan>
<scan> ... </scan>
</scans>
What I really want is:
<scans>
<scan> .... </scan>
<scan> ... </scan>
<scan> ... </scan>
<scan> ... </scan>
<scan> ... </scan>
</scans>
Here's my Mule configuration XML:
<flow name="xml-test" doc:name="xml-test">
<all doc:name="All" tracking:enable-default-events="true">
<processor-chain>
<https:outbound-endpoint exchange-pattern="request-response" host="${http.outbound.eu.host}" port="${http.outbound.eu.port}" path="#[path]" method="GET" followRedirects="true" connector-ref="HTTPSConnector" doc:name="EU GET" encoding="ISO-2022-KR"/>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
</processor-chain>
<processor-chain>
<https:outbound-endpoint exchange-pattern="request-response" host="${http.outbound.us.host}" port="${http.outbound.us.port}" path="#[path]" method="GET" followRedirects="true" connector-ref="HTTPSConnector" doc:name="US GET"/>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
</processor-chain>
</all>
</flow>
Any suggestions on what I can do to achieve that desired merged XML output? Much appreciated. Thanks!
-keith
... follow up (2014-04-27) tries:
I tried unsuccessfully to merge the two xml results by using a splitter on an xpath('//scan') and then wrapping the combined results in a "scans" tag. But the results I get have a stupid '[' between the "scans" tag and the first "scan" element. Argh. i.e.
<scans>
[
<scan>...</scan>
<scan>...</scan>
]
</scans>
Here's the relevant Mule flow steps:
<all doc:name="All" tracking:enable-default-events="true">
<processor-chain>
<https:outbound-endpoint exchange-pattern="request-response" host="${http.outbound.eu.host}" port="${http.outbound.eu.port}" path="#[path]" method="GET" followRedirects="true" connector-ref="HTTPSConnector" doc:name="EU GET" encoding="UTF-8" mimeType="text/xml" contentType="text/xml"/>
<splitter expression="#[xpath('//scan')]" doc:name="Splitter"/>
</processor-chain>
<processor-chain>
<https:outbound-endpoint exchange-pattern="request-response" host="${http.outbound.us.host}" port="${http.outbound.us.port}" path="#[path]" method="GET" followRedirects="true" connector-ref="HTTPSConnector" doc:name="US GET" encoding="UTF-8" mimeType="text/xml" contentType="text/xml"/>
<splitter expression="#[xpath('//scan')]" doc:name="Splitter"/>
</processor-chain>
</all>
<set-payload value="#['<?xml version=\"1.0\" encoding=\"utf-8\"?><scans>' + message.payloadAs(java.lang.String) + '</scans>']" doc:name="Set Payload"/>
Close but the pesky "[" prevents this from being what the client expects.
Also, the logs show the following apparent complaint about the splitting: "INFO ExpressionSplitter:197 - The expression does not evaluate to a type that can be split: org.dom4j.tree.DefaultElement"
Any help or pointers would be greatly appreciated. I have the "Mule In Action" 2nd edition (2014) book, but can't seem to find any advice in there for how to merge two XML streams into one with a wrapping container element.
Thanks !!
-keith
Upvotes: 2
Views: 222