Mule ESB 3.6 - Best way to convert BufferedInputStream to XML

混江龙づ霸主 提交于 2019-12-04 21:50:29
David McInnes

Thanks to the answer for this stackoverflow question helped provide the solution to my question.

Answer:

Add the NODESET option to the xpath3 MEL and then a DOM to XML transformer to convert the DOM object back to XML.

#[xpath3('//Order',payload,'NODESET')]

I also had to add all the splitting components into a sub-flow, especially for my HTTP source (as I kept getting payloadAsString() errors.

Mule Flow

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<file:connector name="PickupFile2" autoDelete="true" streaming="false" validateConnections="true" doc:name="File"/>
<mulexml:object-to-xml-transformer returnClass="java.lang.String" encoding="UTF-8" name="Object_to_XML" doc:name="Object to XML"/>
<mulexml:dom-to-xml-transformer name="DOM_to_XML" doc:name="DOM to XML"/>
<flow name="collectionsplitterFlow2">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/CollectionSplitter" doc:name="HTTP"/>
    <set-session-variable variableName="Filename" value="HTTP" doc:name="Session Variable"/>
    <flow-ref name="collectionsplitterSub_Flow" doc:name="collectionsplitterSub_Flow"/>
    <set-payload value="Response2" doc:name="Set Payload"/>
</flow>
<sub-flow name="collectionsplitterSub_Flow">
    <splitter expression="#[xpath3('//Order',payload,'NODESET')]" doc:name="Splitter"/>
    <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    <file:outbound-endpoint path="C:\Mule\CollectionSplitter\Backup\01_SplitFile" outputPattern="#[sessionVars.Filename]-split2-#[function:datestamp].xml" connector-ref="File" responseTimeout="10000" transformer-refs="DOM_to_XML" doc:name="File"/>
</sub-flow>
<flow name="collectionsplitterFlow">
    <file:inbound-endpoint path="C:\Mule\CollectionSplitter\In" moveToPattern="#[message.inboundProperties['originalFilename']]-backup-#[function:datestamp].xml" moveToDirectory="C:\Mule\CollectionSplitter\Backup" connector-ref="PickupFile2" responseTimeout="10000" doc:name="File">
        <file:filename-regex-filter pattern="(.*).xml" caseSensitive="false"/>
    </file:inbound-endpoint>
    <set-session-variable variableName="Filename" value="#[message.inboundProperties['originalFilename']]" doc:name="Session Variable"/>
    <flow-ref name="collectionsplitterSub_Flow" doc:name="collectionsplitterSub_Flow"/>
    <logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>

Your flow looks good. I tried it on my machine and I see where you're coming from. Try changing the Mule expression from #[xpath3('//Order')] to #[xpath('//Order')]. Doing so caused Mule to successfully generate two Mule messages - one for each Order element.

HTH,

Justin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!