简体   繁体   中英

Mule flow using <all>..</all> to send msg to two XML-returning RESTful web services fails to merge XML results

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.

ie 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. ie

<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="#['&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;&lt;scans&gt;' + message.payloadAs(java.lang.String) + '&lt;/scans&gt;']" 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

一种选择是使用XSLT合并您的xml。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM