复杂的 Mule XPath 表达式抛出异常

编程入门 行业动态 更新时间:2024-10-22 23:47:10
本文介绍了复杂的 Mule XPath 表达式抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在 Mule 中的 XPath 表达式下运行.它一个接一个地给我错误.有人可以帮我纠正这些 Mule XPath 表达式吗:

<xm:namespace prefix="acord" uri="ACORD/Standards/Life/2"/><xm:namespace prefix="soap" uri="schemas.xmlsoap/soap/envelope/"/></xm:namespace-manager><set-variable variableName="pwaHolding"value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value"/><set-variable variableName="pwaPolNumber"value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Holding[@id=$pwaHolding]/acord:Policy/acord:PolNumber').text]"/>

我在尝试执行以上 XPATH 表达式时遇到异常:

消息:表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID'的执行).value"失败.(org.mule.api.expression.ExpressionRuntimeException).消息负载的类型:字符串代码:MULE_ERROR--2--------------------------------------------------------------------------------异常堆栈是:1. [错误:意外令牌:37][近:{... @tc == '37']/@OriginatingObjec ....}]^[行:1,列:96](组织.mvel2.CompileException)org.mvel2piler.ExpressionCompiler:247 (null)2. 表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value"的执行失败.(org.mule.api.expression.ExpressionRuntimeException)org.mule.el.mvel.MVELExpressionLanguage:211 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)3. 表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value"的执行失败.(org.mule.api.expression.ExpressionRuntimeException).消息负载的类型:字符串(org.mule.api.transformer.TransformerMessagingException)org.mule.transformer.AbstractTransformer:123 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)--------------------------------------------------------------------------------根异常堆栈跟踪:[错误:意外令牌:37][近:{... @tc == '37']/@OriginatingObjec ....}] ^[行:1,列:96]在 org.mvel2piler.ExpressionCompiler._compile(ExpressionCompiler.java:247)在 org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:1944)在 org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:862)+ 3 更多(设置调试级别日志记录或-Dmule.verbose.exceptions=true")

大卫,

即使在将 ' 替换为 &quot; 之后,我仍然遇到以下错误:

消息:表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value"的执行失败.(org.mule.api.expression.ExpressionRuntimeException).消息负载的类型:字符串代码:MULE_ERROR--2--------------------------------------------------------------------------------异常堆栈是:1. [错误:意外令牌:37][近:{... @tc == '37']/@OriginatingObjec ....}]^[行:1,列:96] (org.mvel2.CompileException)org.mvel2piler.ExpressionCompiler:247 (null)2. 表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value"的执行失败.(org.mule.api.expression.ExpressionRuntimeException)org.mule.el.mvel.MVELExpressionLanguage:211 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)3. 表达式xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value"的执行失败.(org.mule.api.expression.ExpressionRuntimeException).消息负载的类型:字符串(org.mule.api.transformer.TransformerMessagingException)org.mule.transformer.AbstractTransformer:123 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)

我的第二个 XPATH 表达式也有问题,但也失败了.请帮我解决这个问题

解决方案

该错误来自于您在由 ' 分隔的字符串中使用了 ' 的事实,它可以不行.例如,在以下表达式中,问题围绕 '37':

value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value"/>

另一个问题是 MEL 表达式末尾缺少结束的 ].

尝试:

value="#[xpath("//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID&quot;).value"/>

看看你的第二个 XPath,我看到了 [@id=$pwaHolding].我假设此时您正在尝试使用由第一个 XPath 提取的 pwaHolding 流变量.这将不起作用,因为 MVEL 没有字符串插值.您需要改为使用连接,顺便说一句,不要忘记将 @id 与值进行比较:

[@id‌='&quot;+ pwaHolding + &quot;']

I am trying to run below XPath expressions in Mule. Its giving me errors one after another. Can someone help me correcting these Mule XPath expressions :

<xm:namespace-manager includeConfigNamespaces="true"> <xm:namespace prefix="acord" uri="ACORD/Standards/Life/2" /> <xm:namespace prefix="soap" uri="schemas.xmlsoap/soap/envelope/" /> </xm:namespace-manager> <set-variable variableName="pwaHolding" value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value" /> <set-variable variableName="pwaPolNumber" value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Holding[@id=$pwaHolding]/acord:Policy/acord:PolNumber').text]" />

I am getting below exception when trying to execute above XPATH expressions :

Message :Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String Code : MULE_ERROR--2 -------------------------------------------------------------------------------- Exception stack is: 1. [Error: unexpected token: 37] [Near : {... @tc == '37']/@OriginatingObjec ....}] ^ [Line: 1, Column: 96] (org. mvel2.CompileException) org.mvel2piler.ExpressionCompiler:247 (null) 2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException) org.mule.el.mvel.MVELExpressionLanguage:211 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException) org.mule.transformer.AbstractTransformer:123 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html) -------------------------------------------------------------------------------- Root Exception stack trace: [Error: unexpected token: 37] [Near : {... @tc == '37']/@OriginatingObjec ....}] ^ [Line: 1, Column: 96] at org.mvel2piler.ExpressionCompiler._compile(ExpressionCompiler.java:247) at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:1944) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:862) + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Hi David,

I even after replacing ' with &quot; I am still getting below error :

Message : Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String Code : MULE_ERROR--2 -------------------------------------------------------------------------------- Exception stack is: 1. [Error: unexpected token: 37] [Near : {... @tc == '37']/@OriginatingObjec ....}] ^ [Line: 1, Column: 96] (org.mvel2.CompileException) org.mvel2piler.ExpressionCompiler:247 (null) 2. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException) org.mule.el.mvel.MVELExpressionLanguage:211 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 3. Execution of the expression "xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc == '37']/@OriginatingObjectID').value" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException) org.mule.transformer.AbstractTransformer:123 (www.mulesoft/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)

I have my second XPATH expression in question which is also failing. Please help me get around this as well

解决方案

The error comes from the fact you use a ' inside a string delimited by ', which can not work. For example in the following expression the issue is around '37':

value="#[xpath('//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID').value" />

Another issue is that a closing ] is missing at the end of the MEL expression.

Try with:

value="#[xpath(&quot;//acord:TXLife/acord:TXLifeRequest/acord:OLifE/acord:Relation[acord:RelationRoleCode/@tc = '37']/@OriginatingObjectID&quot;).value" />

Looking at your second XPath, I see [@id=$pwaHolding]. I assume that at this point you are trying to use the pwaHolding flow variable extracted by the first XPath. This will not work as MVEL does not have string interpolation. You need to instead use concatenation and, by the way, not forget to single quote the value @id is compared to:

[@id‌='&quot; + pwaHolding + &quot;']

更多推荐

复杂的 Mule XPath 表达式抛出异常

本文发布于:2023-11-28 15:33:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   抛出   异常   Mule   XPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!