在 JBoss Drools 中评估 XPath 表达式

发布于 2024-11-19 21:07:56 字数 593 浏览 8 评论 0 原文

我正在处理大量 XML 消息的企业架构中工作。最近,我们需要对这些 XML 消息中包含的数据执行一些计算,并在将消息从企业传递到外部消费者之前将一些结果添加到消息头中。我们的架构基于 JBoss SOA-P,我目前正在评估 JBoss Drools 5.2.0 来执行这些消息操作。

我知道我可以简单地从 XML 中提取 POJO,对其执行规则,然后添加适当的结果。但是,如果可能的话,我希望消除对 XML 消息结构的编译时依赖性,因为架构周围存在动态要求,并且在将新编译代码部署到生产环境时存在重大障碍(请参阅:繁文缛节)。理想情况下,我希望对 .drl 规则中的原始 XML 使用 XPath 评估。一些搜索发现了 SXC 项目,这似乎正是我所需要的,但是有关于如何使用它的信息很少,并且自 2007 年以来它似乎处于休眠状态。此外,它是针对 Drools 4.0.4 编译的,我需要使用 5.2.0。

有谁知道在 Drools 规则中根据 XML 评估 XPath 表达式的好方法吗?允许在运行时在 Drools 规则中补偿 XML 结构更改的 XPath 替代方案也很受欢迎。

谢谢!

I am working within a enterprise architecture that is processing a large amount of XML messages. We have recently been given the requirement to perform some calculations on data contained in those XML messages and add some results to the message header before passing the message out of the enterprise to an external consumer. Our architecture is based on the JBoss SOA-P and I am currently evaluating JBoss Drools 5.2.0 for performing these message operations.

I know that I can simply hydrate a POJO from the XML, execute the rules on it, and add the appropriate result. If possible, however, I would like to remove compile-time dependencies on the XML message structure due to dynamic requirements around the schema as well as significant hurdles in deploying new compiled code to our production environment (read: red tape). I would ideally like to use XPath evaluations on the raw XML in the .drl rules. Some searching turned up the SXC project, which appears to be exactly what I need, but there is very little information on how to use it and it seems to be dormant since 2007. Additionally, it has been compiled against Drools 4.0.4 and I am required to use 5.2.0.

Does anyone know of a good way to evaluate XPath expressions against XML in Drools rules? Alternatives to XPath that allow XML structure changes to be compensated for in Drools rules at runtime are also welcome.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2024-11-26 21:07:56

不久前,我们有一位 Drools 专家来访我们公司并了解了 Drools。我正在开发一项服务,其中有很多不断变化的规则,我们考虑使用 Drools。

专家告诉我们使用代理对象来包装 Drools 所需的数据。您可以尝试使用代理对象,将 XML 与一些方法一起放入其中。当 Drools 尝试评估代理对象时,它实际上是在评估您的 XML。
与 Drools 规范相比,这有点脏,因为对象在输入 Drools 工作内存时不会保存数据,而是在被要求时提取数据。

我不是 Drools 方面的专家,但我看到的唯一选择是“水合 POJO”,正如您之前提到的,根据 Drools 规范,这是最好的。

we had an expert on Drools visiting our company and taking about Drools short time ago. I am developing a Service with a lot of rules that are constantly changing and we thought about using Drools.

The expert told us to use Proxy-Objects to wrap the data we needed for Drools. You could try to use a Proxy-Object in which you put the XML along with some methods. When Drools is trying to evaluate the Proxy-Object it is infact evaluating your XML.
This is a littlebit dirty - comparing to Drools specifications - since the Object would not hold the data when entered into the Working-Memory of Drools, but rather extract the data when asked.

I am no expert in Drools, but the only alternative I see, is to "hydrate a POJO" as you mentioned before, which would be best according to Drools specifications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文