我需要获取包含重复元素的传入XML消息,并将这些消息拆分为单独的消息以进行后续处理。然后,我需要重新组合结果并通过HTTP进行响应。
我正在使用Splitter节点和XPath作为第一步。但是,它只访问XML中的第一个元素,并且不会将XML保留到下一个阶段。我尝试了the example from the documentation,但它的输出相同。
我在Anypoint Studio中运行Mule 3.6.1 CE。
NB处理元素的顺序很重要,因此我不只是想做一个Scatter-Gather。
这是我的示例XML: -
<?xml version="1.0" encoding="UTF-8"?>
<itm:ItemList
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:itm="http://schemas.goochjs.org/item-v1"
xsi:schemaLocation="http://schemas.goochjs.org/item-v1 item-v1.xsd">
<itm:Item sequence="1" action="create">
<itm:Thing type="something">
<itm:Description>Something</itm:Description>
</itm:Thing>
<itm:Thing type="anything">
<itm:Description>Something else</itm:Description>
</itm:Thing>
</itm:Item>
<itm:Item sequence="2" action="update">
<itm:Thing type="anything">
<itm:Description>A wotsit</itm:Description>
</itm:Thing>
</itm:Item>
<itm:Item sequence="2" action="create">
<itm:Thing type="something">
<itm:Description>A doohinky</itm:Description>
</itm:Thing>
</itm:Item>
<itm:Item sequence="3" action="delete">
<itm:Thing type="something">
<itm:Description>A different doohinky</itm:Description>
</itm:Thing>
</itm:Item>
</itm:ItemList>
这是我的代码: -
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="splitter-endpoint" host="0.0.0.0" port="8081" basePath="/splitter" doc:name="HTTP Listener Configuration"/>
<mulexml:namespace-manager includeConfigNamespaces="true">
<mulexml:namespace prefix="itm" uri="http://schemas.goochjs.org/item-v1"/>
</mulexml:namespace-manager>
<flow name="mule-splitter-aggregatorFlow">
<http:listener config-ref="splitter-endpoint" path="/" allowedMethods="post" doc:name="HTTP"/>
<splitter expression="#[xpath3('/itm:ItemList/itm:Item')]" doc:name="Splitter"/>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
这是日志中的输出: -
INFO 2015-03-19 10:48:17,440 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.routing.ExpressionSplitter: The expression does not evaluate to a type that can be split: java.lang.String
INFO 2015-03-19 10:48:17,441 [[mule-splitter-aggregator].splitter-endpoint.worker.01] org.mule.api.processor.LoggerMessageProcessor:
Something
Something else
我错过了什么?我尝试在拆分之前添加各种不同的变换器(例如 Object to XML ,如建议here),但无济于事。
答案 0 :(得分:4)
尝试强制xpath表达式返回NODESET:
<splitter expression="#[xpath3('/itm:ItemList/itm:Item', payload, 'NODESET')]"
doc:name="Splitter" />