我有这个Mule ESB测试项目:
<?xml version="1.0" encoding="UTF-8"?>
<mule 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.4.0" 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">
<flow name="testFlow1" doc:name="testFlow1">
<poll frequency="60000" doc:name="Poll">
<flow-ref name="testFlow2" doc:name="Flow Reference"/>
</poll>
<processor ref="" />
</flow>
<sub-flow name="testFlow2" doc:name="testFlow2">
<set-payload value="<root>
<entry>
<key>mobile_phone</key>
<value>380996547889</value>
</entry>
</root>" doc:name="Set Payload"/>
<logger message="XML: #[message.payload]" level="INFO" doc:name="Log XML"/>
<logger message="MobilePhone: #[xpath('/root/entry/key[text()="mobile_phone"]/../value/text()')]" level="INFO" doc:name="Log Properties"/>
</sub-flow>
</mule>
启动后我在日志中出现此错误:
**********************************************************************
* Application: test *
* OS encoding: UTF-8, Mule encoding: UTF-8 *
* *
* Agents Running: *
* JMX Agent *
**********************************************************************
INFO 2013-11-18 14:39:39,190 [main] org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'test' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2013-11-18 14:39:40,270 [[test].connector.polling.mule.default.receiver.01] org.mule.api.processor.LoggerMessageProcessor: XML: <root> <entry> <key>mobile_phone</key> <value>380996547889</value> </entry> </root>
ERROR 2013-11-18 14:39:40,545 [[test].connector.polling.mule.default.receiver.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "xpath('/root/entry/key[text()="mobile_phone"]/../value/text()').getText()" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unable to resolve method: java.util.ArrayList.getText() [arglength=0]]
[Near : {... xpath('/root/entry/key[text()= ....}]
^
[Line: 1, Column: 1] (org.mvel2.PropertyAccessException)
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:1078 (null)
2. Execution of the expression "xpath('/root/entry/key[text()="mobile_phone"]/../value/text()').getText()" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:218 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3. Execution of the expression "xpath('/root/entry/key[text()="mobile_phone"]/../value/text()').getText()" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
[Error: unable to resolve method: java.util.ArrayList.getText() [arglength=0]]
[Near : {... xpath('/root/entry/key[text()= ....}]
^
[Line: 1, Column: 1]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1078)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
即。由于未知原因,标记value
的测试值的XPath函数返回ArrayList对象而不是String。
有人知道如何强制XPath返回String对象吗?
答案 0 :(得分:0)
通过在XML中添加<?xml version="1.0" encoding="utf-8"?>
标头解决。没有这个Mule XPath函数表现得很奇怪。