使用Apache骆驼转换器EIP将模块导入xquery [英] Import module into xquery with apache camel transformer EIP

查看:105
本文介绍了使用Apache骆驼转换器EIP将模块导入xquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条非常简单的骆驼路线,除了使用的xquery之外,这就是为什么我将其提取到一个单独的文件中的原因.在我的骆驼路线中,我使用Transformer EIP调用xquery:

I have a camel route which is pretty simple, except for the used xquery which is why I extracted it into a separate file. In my camel route I call the xquery with the Transformer EIP:

.transform().xquery("resource:classpath:xquery/myCoolXQuery.xquery",String.class)

XQuery本身可以正常工作,但是由于一些功能上的变化,我现在想导入另一个XQuery模块,我希望将其用作带有一些帮助功能的库",因为我有很多可以使用它们的XQuery-Files

The XQuery itself works fine, but because of some functional changes I now want to import another XQuery module which I want to use as a "library" with some helping functions, because I have lots of XQuery-Files which could use them.

所以我在XQuery中所做的是:

So what I did in my XQuery is:

xquery version "3.0" encoding "UTF-8";

declare namespace fn = 'http://www.w3.org/2005/xpath-functions';

(: Library of really helpful functions :)
import module namespace lib = "http://handofnod.com/xquery-lib" at "classpath:xquery/lib.xquery";

问题:

如何配置Apache Camel,使StandardModuleURIResolver能够从 classpath 加载导入的模块?

Question:

How can I configure Apache Camel that the StandardModuleURIResolver is able to load the imported module from the classpath?

不幸的是,现在,Apache骆驼在StandardModuleURIResolver中的StandardModuleURIResolver处抛出了NullpointerException:

Unfortunately apache camel now throws a NullpointerException in the StandardModuleURIResolver at:

if ("classpath".equals(absoluteURI.getScheme())) {
    String path = absoluteURI.getPath();
    is = this.config.getDynamicLoader().getResourceAsStream(path);

这是因为absoluteURI(它是"classpath:xquery/lib.xquery")不能正确转换,而变量pathNULL(有很多代码味道,但现在不关我的事).

That's because the absoluteURI (which is "classpath:xquery/lib.xquery") cannot be converted correctly and the variable path is NULL (that's pretty much code smell but not my business now).

absoluteURI无法转换,因为net.sf.saxon.query.XQueryParserthis.env.getStaticBaseURI()中未设置任何值.

The absoluteURI cannot be converted because the net.sf.saxon.query.XQueryParser has no value set in the this.env.getStaticBaseURI().

因此,我在调试过程中尝试将staticBaseURI值设置为classpath,但随后StandardModuleURIResolver还会返回absoluteURI,该absoluteURIgetPath()中具有NULL值,从而导致相同的.

So I tried during debugging to set the staticBaseURI value to classpath but then the StandardModuleURIResolver also returns an absoluteURI which has a NULL value in the getPath() thus resulting in the same NullPointerException.

因此,现在我不知道如何将 Transformer-EIP 与XQuery结合使用,该XQuery使用模块导入来实现一些辅助功能.

So now I don't have any clue how to use the Transformer-EIP with an XQuery which uses a module import for some helper functions.

另一种可能的解决方案是不使用Apache Camel中实现的Transformer-EIP,而是使用ToDefinition,因为可以在URL参数上定义自定义的 Saxon配置,该参数可以使用覆盖的ModuleURIResolver,然后没有问题.

Another possible solution would be to not use the Transformer-EIP implemented in Apache Camel but instead use the ToDefinition because there it is possible to define a custom Saxon Configuration over an URL parameter which can use an overwritten ModuleURIResolver which then hasn't the problem.

此外,请确保我可以使用自定义的Processor实现来实现所需的功能,但这并不是使用提供EIP实现的Camel的目的.

Also, sure I could use a custom Processor implementation to achieve what I want, but that's not the point in using Camel which provides implementation for EIPs.

如果我可以在XQuery中将 Transformer-EIP 与模块导入配合使用,那就太好了.

It would be great if I could use the Transformer-EIP with module import in my XQuery.

  • Spring-Boot 2.1.0.RELEASE
  • Apache Camel 2.22.2
  • 使用Maven构建

有人可以帮助我吗?

我从骆驼(Camel)和撒克逊(Saxon)下载了源代码,以便能够对发生的情况有更多的了解并进行调试:

I downloaded the sources from Camel and Saxon to be able to debug with more understanding what happens and tried some things:

首先,我尝试使用绝对路径:

First I tried to use an absolute path:

.transform().xquery("resource:classpath:/xquery/myCoolXQuery.xquery",String.class)

这样我就不再得到NullPointerException了,因为在getQuerySource处的StandardModuleURIResolver中,路径不再是NULL:

This way I don't get the NullPointerException anymore because in the StandardModuleURIResolver at getQuerySource the path is not NULL anymore:

不幸的是,该文件无法通过以下方式加载 config.getDynamicLoader().getResourceAsStream(path);并返回NULL.

Unfortunately the file cannot be loaded by config.getDynamicLoader().getResourceAsStream(path); and returns NULL.

所以我想我将xquery文件从目录直接移到src\main\resoures下,但这也无济于事,我得到了相同的结果.

So I thought I move the xquery files from the directory directly under src\main\resoures but that also didn't help and I had the same result.

推荐答案

由于似乎无法回答我的问题,因此我进行了越来越多的调试,实际上似乎根本无法以任何方式配置带有XQuery的Transformer-EIP.另外,我也找不到从类路径加载导入的xquery模块的任何方法,所以我更改了代码,现在我通过XQueryEndpoint调用了xquery,它提供了对自定义配置的支持:

Since it seems there is no answer to my question I debugged further and further and it really just seems impossible to configure the Transformer-EIP with XQuery in any way. Also I was not able to find any way to load the imported xquery module from the classpath so I changed my code and now I call my xquery via the XQueryEndpoint which provides support for custom configuration:

.to("xquery:/xquery/myCoolXQuery.xquery?configuration=#saxonConfig&resultsFormat=String")

这样,我的路线有效.但是能够使用transform()本来很好,因为代码将更易于理解.

This way my route works. But it would have been nice to be able to use the transform() because the code would be easier to understand.

这篇关于使用Apache骆驼转换器EIP将模块导入xquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆