如果未找到 xpath 匹配,bpws:getVariableData() 会导致错误
我想仅当 xpath 表达式找到匹配项时才使用“bpws:getVariableData()”来分配值。如果没有,就不会发生任何事情。不幸的是,如果 xpath 表达式找不到匹配项,bpel 处理会因错误而停止。有没有办法实现这种行为?
感谢您的帮助。
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?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现 oracle BPEL 引擎提供了忽略数据缺失的功能。可以将此标志添加到复制元素,如下所示:
有关如何在 JDeveloper 中设置它的更多信息:http://download.oracle.com/docs/cd/E17904_01/integration.1111/e10224/bp_manipdoc.htm#SOASE87087
这解决了抛出错误消息的问题。但是它仍然没有显示出想要的行为。我的意图是,如果无法计算 xpath 表达式,则不会完成任何分配。然而,使用 bpelx:ignoreMissingFromData 标志会将空字符串“”分配给目标。
在我的用例中,我想合并两个 XML 文档。仅当该元素出现在 document2 中时,我才想为 document1 中的元素分配新值。如果不是,则保持 document1 中的元素不变。
我使用转换而不是 BPEL 分配解决了这个问题。在 xsl 中我使用以下语句。该转换获取两个 XML 文档作为输入。 Document1 通过参数 $parameter_referenceDocument1 引用。
我知道它很难看,但解决了问题。如果有人有更好的解决方案,请告诉我。
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:
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
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.
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.
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.
I know its ugly, but solves the problem. If anyone has a better solution, please let me know.
不,BPEL 标准要求引擎在这种情况下抛出选择失败。为了避免这种情况,请确保您已正确初始化变量和/或根据架构验证变量。此外,您还可以使用 if/switch 活动来保护分配活动,以在访问元素之前检查该元素是否存在。您还可以考虑编写一个自定义 XPath 函数,该函数返回默认值,以防变量中不存在所需的元素。但是,我不确定 Oracle BPEL 引擎是否支持该功能。
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.
您可以围绕分配活动创建一个范围,并在该范围上使用异常处理程序来捕获选择失败,然后该项目将进行处理。
如果需要,您可以在异常处理程序中分配默认值。
为了澄清 Vanto 的声明,Oracle BPEL 引擎确实支持自定义 XPath 函数,这允许您执行此操作。
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.
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.