简体   繁体   中英

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. The Camel context's routebuilder has some xquery endpoint URIs such as

"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. So, I created a url expand function that turns

"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). Unfortunately, I can't seem to find a way to make Camel's XQueryComponent use my 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?
  3. Also, is it possible for me to make sure any camel component can understand a 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".

So in the META-INF/MANIFEST.MF which has the OSGi imports|exports. You should have an import for that given package.

And to answer your 3 bullets

  1. No, see above
  2. You would need to extend this component and add your own logic for the "bundle"
  3. No, not really, as you would need to add logic to 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. And you cannot assign the bundle id, that is self assigned by the osgi container.

Thanks to Claus' answer, I was able to realize that my .xq file was not in the right directory in its .jar.

Dir1 resided in root of its .jar file. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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