使用Mule EE v2.5.2:
我有一个选择的Mule流,它在有效负载上运行XPath表达式:
<choice doc:name="Is Fault?">
<when expression="#[xpath('/iXML:Fault') != null]">
<set-payload value="#[xpath('/iXML:Fault')]" doc:name="Retrieve Fault element"/>
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<mulexml:jaxb-xml-to-object-transformer jaxbContext-ref="JAXB_Context" doc:name="XML to JAXB Object"/>
<logger message="Exception Caught: #[payload.faultstring] - FaultCode #[payload.faultcode] - #[payload.detail.error]" level="ERROR" doc:name="Log Aorta Fault"/>
<message-filter throwOnUnaccepted="true" doc:name="Throw exception for Aorta Fault">
<not-filter>
<payload-type-filter expectedType="com.vatit.blaze.esb.dragon.dto.Fault"/>
</not-filter>
</message-filter>
</when>
<otherwise>
<logger message="Dragon message verified OK." level="TRACE" doc:name="Logger"/>
</otherwise>
</choice>
此时有效载荷如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<iXML:Envelope xmlns:iXML="urn:schemas-ixml-org:ixml.v1">
<aseloginResponse>
<iXML:Fault>
<iXML:faultcode>0</iXML:faultcode>
<iXML:faultstring>Unknown Aorta Fault Type</iXML:faultstring>
<iXML:runcode>No</iXML:runcode>
<iXML:detail>
<error code="30001">Invalid Login</error>
</iXML:detail>
</iXML:Fault>
</aseloginResponse>
</iXML:Envelope>
我添加了一个全局(在同一个XML文件中)命名空间管理器:
<mulexml:namespace-manager includeConfigNamespaces="true">
<mulexml:namespace prefix="iXML" uri="urn:schemas-ixml-org:ixml.v1"/>
</mulexml:namespace-manager>
然而,我仍然得到一个Mule错误:未声明的命名空间前缀iXML 当它到达XPath时:
2015-01-27 11:45:08 ERROR CatchMessagingExceptionStrategy:337 -
********************************************************************************
Message : com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "iXML"
at [row,col {unknown-source}]: [3,27] (javax.xml.transform.TransformerException)
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Undeclared namespace prefix "iXML"
at [row,col {unknown-source}]: [3,27] (org.xml.sax.SAXParseException)
org.mule.module.xml.stax.StaxSource$PseudoReader:208 (null)
2. com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "iXML"
at [row,col {unknown-source}]: [3,27] (javax.xml.transform.TransformerException)
org.apache.xalan.transformer.TransformerIdentityImpl:502 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/xml/transform/TransformerException.html)
3. com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "iXML"
at [row,col {unknown-source}]: [3,27] (javax.xml.transform.TransformerException) (org.mule.api.transformer.TransformerException)
org.mule.module.xml.transformer.XmlToDomDocument:83 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "iXML"
at [row,col {unknown-source}]: [3,27]
at org.mule.module.xml.stax.StaxSource$PseudoReader.parse(StaxSource.java:208)
at org.mule.module.xml.stax.StaxSource$PseudoReader.parse(StaxSource.java:188)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:485)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
2015-01-27 11:45:08 ERROR LoggerMessageProcessor:337 - Exception Caught: Execution of the expression "xpath('//Fault') != null" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: ReleasingInputStream
我能做错什么?
答案 0 :(得分:2)
以下对我来说非常好:
<mulexml:namespace-manager includeConfigNamespaces="true">
<mulexml:namespace prefix="iXML" uri="urn:schemas-ixml-org:ixml.v1"/>
</mulexml:namespace-manager>
<flow name="test-http">
<http:inbound-endpoint host="127.0.0.1" port="8081" doc:name="HTTP" />
<choice doc:name="Is Fault?">
<when expression="#[xpath('//iXML:Fault') != null]">
<logger message="ERROR TERRIBLE" level="ERROR" doc:name="Log Aorta Fault" />
</when>
<otherwise>
<logger message="Dragon message verified OK." level="ERROR" doc:name="Logger" />
</otherwise>
</choice>
</flow>
注意我稍微修改了XPath。我想知道您使用的Mule版本是什么?我刚试过3.6。