Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mule ESB XPath函数返回ArrayList而不是字符串_Java_Xml_Xpath_Mule - Fatal编程技术网

Java Mule ESB XPath函数返回ArrayList而不是字符串

Java Mule ESB XPath函数返回ArrayList而不是字符串,java,xml,xpath,mule,Java,Xml,Xpath,Mule,我有一个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

我有一个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="&lt;root&gt;
   &lt;entry&gt;
      &lt;key&gt;mobile_phone&lt;/key&gt;
      &lt;value&gt;380996547889&lt;/value&gt;
   &lt;/entry&gt;
&lt;/root&gt;" doc:name="Set Payload"/>
                <logger message="XML: #[message.payload]" level="INFO" doc:name="Log XML"/>
                <logger message="MobilePhone: #[xpath('/root/entry/key[text()=&quot;mobile_phone&quot;]/../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)
********************************************************************************
**********************************************************************
*应用:测试*
*OS编码:UTF-8,Mule编码:UTF-8*
*                                                                    *
*正在运行的代理:*
*JMX代理*
**********************************************************************
信息2013-11-18 14:39:39190[main]org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+已启动应用程序“测试”+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2013-11-18 14:39:40270[[test].connector.polling.mule.default.receiver.01]org.mule.api.processor.LoggerMessageProcessor:XML:mobile_phone 380996547889
错误2013-11-18 14:39:40545[[test].connector.polling.mule.default.receiver.01]org.mule.exception.defaultMessaginExceptionStrategy:
********************************************************************************
消息:执行表达式“xpath('/root/entry/key[text()=“mobile_phone”]/../value/text()”)。getText()失败。(org.mule.api.expression.ExpressionRuntimeException)。消息负载的类型为:String
代码:MULE_错误--2
--------------------------------------------------------------------------------
异常堆栈是:
1.[错误:无法解析方法:java.util.ArrayList.getText()[arglength=0]]
[近:{…xpath('/root/entry/key[text()=…}]
^
[行:1,列:1](org.mvel2.PropertyAccessException)
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:1078(null)
2.表达式“xpath('/root/entry/key[text()=“mobile_phone”]/../value/text()”).getText()的执行失败。(org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.mvelexpression语言:218(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
3.表达式“xpath('/root/entry/key[text()=“mobile_phone”]/../value/text()”).getText()的执行失败。(org.mule.api.expression.ExpressionRuntimeException)。消息负载的类型为:String(org.mule.api.MessaginException)
org.mule.execution.ExceptionToMessaginExceptionExecutionInterceptor:35(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
根异常堆栈跟踪:
[错误:无法解析方法:java.util.ArrayList.getText()[arglength=0]]
[近:{…xpath('/root/entry/key[text()=…}]
^
[行:1,列:1]
位于org.mvel2.optimizers.impl.refl.reflectAccessorOptimizer.getMethod(reflectAccessorOptimizer.java:1078)
位于org.mvel2.optimizers.impl.refl.reflectAccessorOptimizer.getMethod(reflectAccessorOptimizer.java:987)
位于org.mvel2.optimizers.impl.refl.reflectAccessorOptimizer.compilegeChain(reflectAccessorOptimizer.java:377)
+3个以上(为所有内容设置调试级别日志或“-Dmule.verbose.exceptions=true”)
********************************************************************************
也就是说,由于未知原因,标记
的测试值的XPath函数返回ArrayList对象,而不是字符串


有人知道如何强制XPath返回always String对象吗?

通过在XML中添加
头来解决。如果没有这个Mule XPath函数,它的行为会很奇怪。

注意到XPath返回数组列表中
XPath('/root/entry/key[text()=“mobile\u phone”]/../value/text()')
的值是
[org.dom4j.tree。DefaultText@17c1e333[文本:“380”],org.dom4j.tree。DefaultText@3a2b3574[文本:“996547889”]
。另一次该值为[org.dom4j.tree]。DefaultText@5b2eda6f[文本:“380996547”],org.dom4j.tree。DefaultText@6106dc2d[正文:“889”]可能重复尝试复制该问题,但没有成功。它永远不会返回Arraylist。通过在XML中添加
标头解决了此问题。如果没有此Mule XPath函数,其行为会异常。