Felix bundles failng to load - osgi

I am attempting to run an application on Apache Felix, using the Felix Dependency bundles. The container is, for some reason, not loading my bundles.
I am doing my development using Bndtools in Eclipse. I am using the Amdatu bundles.
The bundles I am concerned about are the bundles that are in my "Run Requirements":
org.apache.felix.dependencymanager
org.apache.felix.dependencymanager.shell
org.apache.felix.dependencymanager.runtime
osgi.core
osgi.cmpn
All of the above bundles are taken from the Amdatu repository.
I have two bundles which I created:
com.test.demo.reader
com.test.demo.listener
And these bundles are built using org.apache.felix.dependencymanager and osgi.core.
When I attempt to run OSGi, I am getting the following failures:
! could not resolve the bundles: [com.test.demo.reader-1.0.0 Unresolved constraint in bundle
com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0))),
com.test.demo.listener-1.0.0 Unresolved constraint in bundle com.test.demo.listener [9]:
Unable to resolve 9.0: missing requirement [9.0] osgi.wiring.package;
(&(osgi.wiring.package=com.test.demo.reader)(version>=1.0.0)(!(version>=2.0.0)))
[caused by: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package;
(&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0)))]]
and
! Failed to start bundle com.test.demo.reader-1.0.0, exception Unresolved constraint in
bundle com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement [8.0]
osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))
and more
! Failed to start bundle com.test.demo.listener-1.0.0, exception Unresolved constraint in
bundle com.test.demo.listener [9]: Unable to resolve 9.0:
missing requirement [9.0] osgi.wiring.package; (&(osgi.wiring.package=com.test.demo.reader)
(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))]
I think I understand what is happening: apparently the org.apache.dm package being used is a version that is somehow incompatible with my bundles. But that doesn't make any sense, because according to the Felix documentation the org.apache.dm package is in the org.apache.felix.dependencymanager bundle. That bundle is from the Amdatu repository and it is the only version of the bundle I am using with my application! How is the version incompatible with my bundles when theirs is the only version that my bundles know about???
Someone please advise. What is causing this failure an how can I fix it?

The problem was the runtime I was running and what appears to be a bug in the Amdatu plugin.
I would not advise using the Amdatu configuration in your OSGi project. Not in its current form.
The various Felix Dependency bundles that I have been using from Amdatu are apparently intended to run under Felix version 5. Unfortunately, the Amdatu environment (the "Amdatu Configuration" that you can select when you choose a configuration template for your project) does not load Version 5. When you select the "Bundle- Hub configuration", your choice of runtime environments includes all Felix environments from Version 4.0.2 to Version 5.2, as well as several versions of Equinox. When you select the "Amdatu Configuration" you only runtime choices are Felix 4.0.2 and Felix 4.2.0.
I was using 4.2.0 Felix, and as a result the dependency bundles were not working.
The Amdatu environment in its current form is unusable in Bndtools. It apparently supplies the right bundles for Version 5 but does not provide that environment for the user.
I did try manually changing the runtime environment io Version 5.2. This did not work because apparently when you select a template, Bndtools puts together whatever runtimes are associated with the template. Because the Amdatu template does not include Felix version 5, the runtime environment is unavailable.
In order to get my application to run, I had to create a new project that used the "Bundle- Hub" template and manually download the dependency bundles from the Felix website and include them in my buil and runtime environments. Unfortunately, neither Bndtools nor Amdatu provides any way to add the Amdatu bundles to project after a template is selected. This means that instead of using the ready- made bundles from Amdatu, you have to go out to the source sites and manually include them.
I will probably ty and find a way to create a new repository that can be included in projects and contains all the Amdatu bundles, then include that repository in the "Bundle- Hub" template. I will also report the problems with environments (as well as seversl other problems I've seen) to the Amdatu folks.
In the meantime, my application runs smoothly now that I have set up the right runtime environment.
Special thanks to earcam, whose questions in the comment above gave me a clue as to what to start looking at to solve this problem...

Related

What is the point of a features.xml if I have to install the bundles in it manually?

I have a features.xml with a few bundles listed. But they all need to be installed apparently. So all that the features.xml does is gather the dependencies in one spot....
Unless I am horribly mistaken. In which case how does one resolve a situation where I have a lot of dependencies in features.xml and they are all not in any order. Right now I am going through the exercise of installing each bundle and starting them up one by one...
Tell me what I am doing wrong- of which there may be several things
Edit:
Features were generated by maven plugin.
When I install feature, I get unresolved error
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=myBundleApp; type=karaf.feature; version="[1.0.0.RC1,1.0.0.RC1]"; filter:="(&(osgi.identity=myBundleApp)(type=karaf.feature)(version>=1.0.0.RC1)(version<=1.0.0.RC1))" [caused by: Unable to resolve myBundleApp/1.0.0.RC1: missing requirement [myBundleApp/1.0.0.RC1] osgi.identity; osgi.identity=org.eclipse.jetty.websocket.server; type=osgi.bundle; version="[9.3.6.v20151106,9.3.6.v20151106]"; resolution:=mandatory [caused by: Unable to resolve org.eclipse.jetty.websocket.server/9.3.6.v20151106: missing requirement [org.eclipse.jetty.websocket.server/9.3.6.v20151106] osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"]]
But the feature.xml already has <bundle>mvn:org.eclipse.jetty.websocket/websocket-server/9.3.6.v20151106</bundle>
The point of features.xml is to define a repository of features that can be used to provision an OSGi application in Apache Karaf. In another words, it's purpose is exactly to NOT have to install bundles manually! As documentation states:
When you install a feature, Apache Karaf installs all resources described in the feature. It means that it will automatically resolves and installs all bundles, configurations, and dependency features described in the feature.
That said, please keep in mind:
this is Karaf specific functionality. It will not work with other OSGi containers
before you can install a feature you need to make Karaf aware of the repository containing it. You can use feature:repo-list command to check what repos Karaf is aware of and feature:repo-add command to add repositories. Please see this documentation for more details.
URLs pointing to bundles, features, configurations, ... inside features.xml have to point to a reasoures Karaf understands and can access
Features (much like bundles) need to be resolved before they be activated.

Karaf bundle doesn't work

I am working with a Core for SDN network and I have fails with Karaf module when I type this command:
feature:install core
Could not start bundle mvn:eu.netide.lib/netip/1.1.0-SNAPSHOT in feature(s) core-api-1.1.0-SNAPSHOT: Unresolved constraint in bundle netip [85]: Unable to resolve 85.0: missing requirement [85.0] osgi.wiring.package; (osgi.wiring.package=org.projectfloodlight.openflow.exceptions)
Somebody can help me?
Thanks
"osgi.wiring.package" errors occur because of the lack of dependency in your feature.xml file. You have to add the dependant bundle "org.projectfloodlight.openflow.exceptions" to the core feature in your feature.xml file which would solve your problem. If not; you have to make sure that your pom.xml dependency for the corresponding floodlight library is not marked as "provided".

OSGi Require-Capability and Tycho

I created an eclipse plugin that requires a certain capability in its manifest:
Require-Capability: osgi.service;filter:="(osgi.service=my.client.SessionService)"
My target platform contains another bundle that provides this capability. When I try to build this with Tycho I'm getting the following exception:
[ERROR] Internal error: java.lang.RuntimeException: org.osgi.framework.BundleException: Bundle my.client.rxp cannot be resolved
[ERROR] Resolution errors:
[ERROR] Bundle my.client.rxp - Missing Constraint: Require-Capability: osgi.service; filter="(osgi.service=my.client.SessionService)"
It seems that Tycho cannot handle OSGi Capabilities. Everything works fine as soon as I add the bundle that provides the capability as a required bundle to my eclipse plugin. But this makes no sense since the eclipse plugin shouldn't have any dependency to another implementation bundle.
How can OSGi Capabilities be used in a Tycho build?
This is most probably caused by a bug in p2:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=313553
which Tycho uses to resolve dependencies.
Thanks to jsievers, who provided the correct eclipse bug entry. Inside the bug entry there is a link to the Customizing p2 Metadata article. To cut a long story short, for p2 to handle capabilities correctly you have to provide capability advices by writing a p2 advice file (p2.inf).
I had to do the following to fix the capability resolution described in my question above. In the bundle that provides the capability there must be a META-INF/p2.inf file with the following contents:
provides.0.namespace = osgi.serviceloader
provides.0.name = my.client.SessionService
In the bundle that requires the capability there must be a META-INF/p2.inf file with the following contents:
requires.0.namespace = osgi.serviceloader
requires.0.name = my.client.SessionService
Much more capability advices options can be found in the article.

equinox jetty NoClassDefFoundError: SslContextFactory

i have a osgi project in indigo ide, which use equinox 3.7.0 + jetty 7.5.1, now i upgrade ide to juno, which contain equinox 3.8.0 + jetty 8.1.3, so,
the tragedy go on:
when compiling, complain accesible restrictation on SslContextFactory's methods, i resolved it by editing it's access rules in build path.
when running, have a error, say
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory
now i have no idea, thanks for ur help.
The access rules are there for a reason.... by hiding the build-time error, you just made the runtime error appear.
The proper solution is to import the package org.eclipse.jetty.util.ssl in your bundle.
If you use a tool such as Bndtools then these Import-Package dependencies will be detected and generated automatically.

Karaf development

Im currently develop bundles for karaf and have some questions...
I wrote a bundle/webservice based on cxf, I try to deploy it in karaf but it could not start that bundle because it could not resolve some packages e.g.
org.osgi.framework.BundleException: Unresolved constraint in bundle org.springframework.aop [56]: Unable to resolve 56.0: missing
requirement [56.0] package; (&(package=org.aopalliance.aop)(version>=1.0.0)(!(version>=2.0.0)))
so here is a question, this package dependency comes from spring-aop (3.1.0.RELEASE), so where is the problem? what dependency is missing? how can I solve such problems?
In that case i did not clearly understand the development process. should i deploy all missing bundles in deploy? because i would like to keep thirdparty libs spereated from my developed bundles. And what bundles i have to deploy? Is it a trial and error process? Is there a common way to let maven do the dependency stuff?
I discovered a folder "system" and read on the docu that it is a repository like maven, is it for the features?
I had for test cases a karaf with some pre deployed bundles and put my webservice bundle into it, but again execeptions...
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
What dependency is missing?
I already read the tutorial about camel and karaf, but it did not explain the deployment stuff, so could anyone suggest me a good tutorial?
Thanks!
Chris
Short answer
Scroll down to the bit referring to "camel-cxf" and run the two commands features:addurl and features:install. I have a feeling this will resolve all your problems.
spring-aop
On Karaf console type:
exports | grep org.aopalliance.aop
I think you'll see lines like:
XX org.aopalliance.aop; version=3.1.0.RELEASE
So while the spring-aop bundle has the right packages they're the wrong version, the range being requested is >=1.0.0 and <2.0.0, so 3.1.0 doesn't satisfy that.
Deploying/Installing
You can drop bundles into ${karaf.home}/deploy or use the console.
You can install maven bundles from the Karaf console with:
install -s mvn:groupId/artifactId/version/packaging/classifier
Where -s starts the bundle and packaging/classifier are optional.
You can find a lot of OSGi ready maven dependencies here http://ebr.springsource.com/repository/app/ - I had a quick look but your spring aop dependency is very old, what version of CXF are you using?
Read up about Karaf features - they're basically XML files that list suites of bundles that can be installed. Very useful for deploying large numbers of bundles and they can be installed into a maven repository.
There are some standard features available in Karaf, try:
features:install war
This will give you a jetty webcontainer and may resolve your ClassNotFoundException: javax.servlet.http.HttpServlet as long as it's the right version
Camel also has a features file which probably sort all your issues, try this:
features:addurl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install camel-cxf
Tutorials
There's quite a bit available, some on http://karaf.apache.org and http://fusesource.com but also take a look at the PDF manual that comes in the Karaf distribution.
Always beware that info may be out-of-date
Please post your MANIFEST.MF file. I think you didn't not mention the tag in maven-bundle-plugin dependency.

Resources