oracle 如果找不到 xpath 匹配项,bpws:getVariableData() 会导致错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6072036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bpws:getVariableData() causes fault if no xpath match is found
提问by user762738
I wanted to use "bpws:getVariableData()" to assign a value only if the xpath expression find a match. If not, nothing should happen. Unfortunately the bpel processing stops with a fault, if the xpath expression finds no match. Is there a way to achieve this behavior?
我想使用 "bpws:getVariableData()" 仅当 xpath 表达式找到匹配项时才分配一个值。如果没有,什么都不应该发生。不幸的是,如果 xpath 表达式找不到匹配项,则 bpel 处理会因错误而停止。有没有办法实现这种行为?
Thanks for your help.
谢谢你的帮助。
回答by user762738
I found that the oracle BPEL engine provides a feature to ignore missing from data. This Flag can be added to the copy element as follows:
我发现 oracle BPEL 引擎提供了忽略数据丢失的功能。可以将这个标志添加到复制元素中,如下所示:
<copy bpelx:ignoreMissingFromData="yes|no"/>
More info on how to set it in the JDeveloper: http://download.oracle.com/docs/cd/E17904_01/integration.1111/e10224/bp_manipdoc.htm#SOASE87087
有关如何在 JDeveloper 中设置它的更多信息:http: //download.oracle.com/docs/cd/E17904_01/integration.1111/e10224/bp_manipdoc.htm#SOASE87087
This solves the problem with the fault message that is thrown. However it still does not show the wanted behavior. My intension was that no assignment is done, if the xpath expression cannot be evaluated. Using the bpelx:ignoreMissingFromData flag however assigns the empty string "" to the target.
这解决了抛出的故障消息的问题。然而,它仍然没有显示出想要的行为。我的意图是,如果无法评估 xpath 表达式,则不进行任何分配。但是,使用 bpelx:ignoreMissingFromData 标志将空字符串 "" 分配给目标。
In my use case I want to merge tow XML documents. I want to assign a new value to an element in document1 only if the element shows up in document2. If not, leave the element in document1 unchanged.
在我的用例中,我想合并两个 XML 文档。仅当元素出现在 document2 中时,我才想为 document1 中的元素分配一个新值。如果不是,则保持 document1 中的元素不变。
I solved the problem using a transformation instead of a BPEL assign. In the xsl I use the following statement. The transformation gets two XML documents a input. Document1 is referenced via the parameter $parameter_referenceDocument1.
我使用转换而不是 BPEL 分配解决了这个问题。在 xsl 中,我使用以下语句。转换获取两个 XML 文档作为输入。Document1 通过参数 $parameter_referenceDocument1 引用。
<elementName>
<xsl:if test="xpathInDocument2">
<xsl:value-of select="xpathInDocument2"/>
</xsl:if>
<xsl:if test="not(xpathInDocument2)">
<xsl:value-of select="$parameter_referenceDocument1.xpathInDocument1"/>
</xsl:if>
</elementName>
I know its ugly, but solves the problem. If anyone has a better solution, please let me know.
我知道它丑陋,但解决了问题。如果有人有更好的解决方案,请告诉我。
回答by vanto
No, the BPEL standard requires the engine to throw a selectionFailure in this case. To avoid such situations, make sure you have properly initialized variables and/or validate variable against a schema. Also you may guard an assign activity with an if/switch activity to check for the presence of the element before accessing it. You may also consider writing an custom XPath function that returns a default value in case the demanded element does not exist in the variable. However, I'm not sure if the Oracle BPEL engine supports that.
不,BPEL 标准要求引擎在这种情况下抛出 selectionFailure。为避免这种情况,请确保您已正确初始化变量和/或针对架构验证变量。此外,您可以使用 if/switch 活动保护分配活动,以在访问元素之前检查元素是否存在。您还可以考虑编写一个自定义 XPath 函数,该函数在变量中不存在所需元素的情况下返回默认值。但是,我不确定 Oracle BPEL 引擎是否支持。
回答by sweetfa
You can create a scope around the assign activity and using an exception handler on the scope catch the selectionFailure, the item which will then carry on processing.
您可以围绕分配活动创建一个范围,并在该范围上使用异常处理程序捕获 selectionFailure,然后将继续处理该项目。
In the exception handler you could then assign a default value if required.
在异常处理程序中,您可以根据需要分配一个默认值。
To clarify Vanto's statement, the Oracle BPEL engine does support custom XPath functions which would allow you to do that.
为了澄清 Vanto 的声明,Oracle BPEL 引擎确实支持允许您这样做的自定义 XPath 函数。