简体   繁体   English

使用OSGi捆绑uri的Camel xquery端点

[英]Camel xquery endpoint with OSGi bundle uri

I have an OSGi bundle (deployed into Karaf 2.2.4) that starts a Camel (2.10.0) context. 我有一个OSGi包(部署到Karaf 2.2.4),启动Camel(2.10.0)上下文。 The Camel context's routebuilder has some xquery endpoint URIs such as Camel上下文的routebuilder有一些xquery端点URI,例如

"xquery:classpath:Dir1/Dir2/example.xq"

When the context tried to resolve that URI, it failed since the Camel bundle is not in the same classpath as where the .xq file resides. 当上下文尝试解析该URI时,它失败了,因为Camel包与.xq文件所在的类路径不在同一个类路径中。 So, I created a url expand function that turns 所以,我创建了一个url expand函数

"xquery:classpath:..."

into

"xquery:bundle://42.0:6/..."

since I had dealt with bundle URIs and the OsgiBundleResourcePatternResolver earlier in my project when dealing with a ClassPathScanningCandidateComponentProvider (Spring 3.1.1). 因为在处理ClassPathScanningCandidateComponentProvider (Spring 3.1.1)时,我在项目的早期处理过bundle URI和OsgiBundleResourcePatternResolver Unfortunately, I can't seem to find a way to make Camel's XQueryComponent use my OsgiBundleResourcePatternResolver . 不幸的是,我似乎找不到让Camel的XQueryComponent使用我的OsgiBundleResourcePatternResolver

  1. Am I going about this the right way? 我是以正确的方式来做这件事的吗? Is there an easier way to do this? 有更简单的方法吗?
  2. If I am, how can I make sure the XQueryComponent can understand a bundle: URI? 如果是的话,我怎样才能确保XQueryComponent能够理解bundle: URI?
  3. Also, is it possible for me to make sure any camel component can understand a bundle: URI? 另外,我是否可以确保任何camel组件都能理解bundle: URI?

You application that has the Camel route with the above xquery endpoint, would need to import the package where the xq file is located, eg the package that represents "Dir1.Dir2". 具有上述xquery端点的Camel路由的应用程序需要导入xq文件所在的包,例如代表“Dir1.Dir2”的包。

So in the META-INF/MANIFEST.MF which has the OSGi imports|exports. 所以在META-INF / MANIFEST.MF中有OSGi导入|导出。 You should have an import for that given package. 您应该具有该给定包的导入。

And to answer your 3 bullets 并回答你的3发子弹

  1. No, see above 不,见上文
  2. You would need to extend this component and add your own logic for the "bundle" 你需要扩展这个组件并为“bundle”添加你自己的逻辑
  3. No, not really, as you would need to add logic to camel-core/camel-core-osgi. 不,不是真的,因为你需要为camel-core / camel-core-osgi添加逻辑。

Also the bundle id of an application can change, so its not advised to refer to a bundle by its id. 此外,应用程序的bundle id可以更改,因此不建议不要通过其id引用bundle。 And you cannot assign the bundle id, that is self assigned by the osgi container. 并且您无法分配由osgi容器自行分配的包ID。

Thanks to Claus' answer, I was able to realize that my .xq file was not in the right directory in its .jar. 感谢Claus的回答,我能够意识到我的.xq文件不在其.jar中的正确目录中。

Dir1 resided in root of its .jar file. Dir1驻留在.jar文件的根目录中。 While running the application in a non-OSGi web container worked fine, Karaf appears to be more strict regarding where resources should be in my .war file. 虽然在非OSGi Web容器中运行应用程序运行良好,但Karaf似乎对我的.war文件中的资源应该更加严格。 I moved the .xq files to WEB-INF/classes/Dir1/... and now am no longer receiving FileNotFoundExceptions when the code uses xquery:classpath:Dir1/Dir2/example.xq 我将.xq文件移动到WEB-INF/classes/Dir1/...现在,当代码使用xquery:classpath:Dir1/Dir2/example.xq时,我不再接收FileNotFoundExceptions xquery:classpath:Dir1/Dir2/example.xq

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM