OSGi ( Felix ) extra system.bundle exports - java

Simple experiment -
bundle A needs some com.sun.xml.internal.bind classes to be available to it via it's class loader ( jaxb.. )
I googled my way to the theoretical solution of forcing system.bundle to export com.sun.xml.internal.bind by adding the package to "org.osgi.framework.system.packages.extra" ( a standard framework parameter implemented in felix, documented at http://felix.apache.org/site/apache-felix-framework-configuration-properties.html ) and importing it in my bundle.
By doing so the bundle would not resolve anymore..
Unable to resolve 5.0: missing requirement [5.0] osgi.wiring.package; (osgi.wiring.package=com.sun.xml.internal.bind)
( 5 is the jaxb-using bundle ) Setting "org.osgi.framework.bootdelegation" for "com.sun.xml.internal.bind" and not importing it in the dependent bundle worked as documented.
Am i misinterpreting what system.packages.extra should do? Can i just not resolve imports from system.bundle? I tried explicitly setting system.bundle in the import via bnd at the bottom of my Import-Package directive
com.sun.xml.internal.bind;bundle-symbolic-name="system.bundle",\
*
Which resulted in
Unable to resolve 5.0: missing requirement [5.0] osgi.wiring.package; (&(osgi.wiring.package=com.sun.xml.internal.bind)(bundle-symbolic-name=system.bundle))
ps: i'm using bnd and the -runproperties to define these. My bndrun file has:
-runproperties: osgi.console.enable.builtin=true,\
com.mycompany.manager.confDir=./etc,\
org.osgi.framework.system.packages.extra=com.sun.xml.internal.bind,\
org.osgi.service.http.port=8888
the bundle that needs jaxb defines the following import
Import-Package: com.sun.xml.internal.bind,\
*
When trying to resolve dependencies in the bndrun editor, i get
Unable to resolve <<INITIAL>> ver=null: missing requirement (osgi.identity=com.mycompany.configuration.jaxb) [caused by: Unable to resolve com.mycompany.configuration.jaxb ver=0.0.0: missing requirement (osgi.wiring.package=com.sun.xml.internal.bind)]
org.osgi.service.resolver.ResolutionException: Unable to resolve <<INITIAL>> ver=null: missing requirement (osgi.identity=com.mycompany.configuration.jaxb) [caused by: Unable to resolve com.mycompany.configuration.jaxb ver=0.0.0: missing requirement (osgi.wiring.package=com.sun.xml.internal.bind)]
at org.apache.felix.resolver.Candidates.populateResource(Candidates.java:285)
at org.apache.felix.resolver.Candidates.populate(Candidates.java:153)
at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:148)
at biz.aQute.resolve.ResolveProcess.resolveRequired(ResolveProcess.java:34)
at org.bndtools.core.resolve.ResolveOperation.run(ResolveOperation.java:61)
at org.bndtools.core.resolve.ResolveJob.run(ResolveJob.java:43)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

I see you are using Bndtools. Good! We have a special property for setting the system packages from the .bndrun file:
-runsystempackages: com.sun.xml.internal.bind
I'm not sure why it didn't work when you put this inside -runproperties... possibly just a typo though I haven't been able to spot it. Anyway it's better to use -runsystempackages because then the Bndrun resolver also knows to add these packages to the system bundle; then you'll be able to resolve in the bndrun editor as well.

Related

how to fix org.osgi.framework.BundleException

I'm running ONOS and when I want to add my module to its core I get this exception.
that was OK before but when I changed my OS, I get this error.
I've tried lots of ways but none of them fits my problem.
I also have no POM file to add dependency.
any other suggestions would be appreciated
ERROR: Bundle sdn.FANA.optical.optical [178] Error starting mvn:sdn.FANA.optical/optical/1.0 (org.osgi.framework.BundleException: Unresolved constraint in bundle sdn.FANA.optical.optical [178]: Unable to resolve 178.0: missing requirement [178.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.karaf.shell.api.action)(version>=4.2.0)(!(version>=5.0.0))))
org.osgi.framework.BundleException: Unresolved constraint in bundle sdn.FANA.optical.optical [178]: Unable to resolve 178.0: missing requirement [178.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.karaf.shell.api.action)(version>=4.2.0)(!(version>=5.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
at java.lang.Thread.run(Thread.java:748)
This error message says that your bundle depends on the package org.apache.karaf.shell.api.action, version range [4.2.0, 5.0.0).
Whenever a bundle has an import, it must be matched by a corresponding export from another bundle. So you need to install the bundle that exports the package org.apache.karaf.shell.api.action, with version at least 4.2.0 and less than 5.0.0.

feature-install results in missing requirement message in karaf 4.0.7

This is a simple feature.xml(v1.4.0) and all I did was specify
feature:install my-feature
Hence the error:
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=my-feature; type=karaf.feature; version="[2.0.0,2.0.0]"; filter:="(&(osgi.identity=my-feature)(type=karaf.feature)(version>=2.0.0)(version<=2.0.0))" [caused by: Unable to resolve my-feature/2.0.0: missing requirement [my-feature/2.0.0] osgi.identity; osgi.identity=vertx-auth-common; type=osgi.bundle; version="[3.3.3,3.3.3]"; resolution:=mandatory [caused by: Unable to resolve vertx-auth-common [52](R 52.0): missing requirement [vertx-auth-common [52](R 52.0)] osgi.wiring.package; (&(osgi.wiring.package=io.vertx.core.buffer)(version>=3.3.0)(!(version>=4.0.0))) [caused by: Unable to resolve io.vertx.core [53](R 53.0): missing requirement [io.vertx.core [53](R 53.0)] osgi.wiring.package; (&(osgi.wiring.package=io.netty.handler.codec)(version>=4.1.0)(!(version>=5.0.0)))]]]
I was under the impression that specifying my bundles in a feature and installing would pull them all into karaf.
How do I resolve this?
Since Karaf 4.0, Karaf features are validated prior installation. So one of the Imports for your own bundle can't be located in the feature you provided and also in none of which is already installed. Therefore you have this error.
Btw. regarding Karaf and vertx features, might want to take a look at the following Project (still WIP)
There you'll also will find a working feature descriptor for Vert.X on Karaf.

how to fix missing requirement while the deployment of an OSGI bundle

I am trying to deploy a simple OSGI bundle (hello world) in glassfish 4.1.1 but I got the following error:
Infos: org.osgi.framework.BundleException:
Unresolved constraint in bundle com.mycompany.MavenHelloServiceImpl [324]:
Unable to resolve 324.0: missing requirement [324.0]
osgi.wiring.package; (osgi.wiring.package=com.mycompany.mavenhelloserviceapi)
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
I don't know how to fix the missing package , I already defined "com.mycompany.mavenhelloserviceapi" as a dependency in the bundle MavenHelloServiceImpl and it is present in the dependencies folder in the bundle MavenHelloServiceImpl
Any idea how to fix this error ?!
Having com.mycompany.mavenhelloserviceapi as a dependency in your pom.xml is not enough : the pom is about compile-time dependencies. you see here an issue about a runtime dependency missing.
You should install com.mycompany.mavenhelloserviceapi in your container.
You should modify the project that contains com.mycompany.mavenhelloserviceapi as a bundle project and explicitly export this package. now deploy this bundle alongwith your hello world bundle.
Alternatively ,you can use Pax Wrap to deploy the jar that contains com.mycompany.mavenhelloserviceapi to glassfish without modifying the project.

Access Drools Guvnor from OSGI bundle

I am using following code to access Drools Guvnor:
KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("drools/change-set.xml"));
StatefulKnowledgeSession ksession = kagent.getKnowledgeBase().newStatefulKnowledgeSession();
Unfortunately KnowledgeAgentFactory class does not seem to be OSGI ready as it uses Class.forName() to load agent provider. KnowledgeAgentFactory resides in knowledge-api bundle, and provider implementation in drools-core bundle. Obviously knowledge-api doesn't see drools-core in OSGI container. As a result I get following exception:
Caused by: java.lang.RuntimeException: Provider org.drools.agent.impl.KnowledgeAgentProviderImpl could not be set.
at org.drools.agent.KnowledgeAgentFactory.loadProvider(KnowledgeAgentFactory.java:191)[162:org.drools.api:5.5.0.Final]
at org.drools.agent.KnowledgeAgentFactory.getKnowledgeAgentProvider(KnowledgeAgentFactory.java:178)[162:org.drools.api:5.5.0.Final]
at org.drools.agent.KnowledgeAgentFactory.newKnowledgeAgentConfiguration(KnowledgeAgentFactory.java:129)[162:org.drools.api:5.5.0.Final]
Is there workaround for this issue?
You might help yourself with a require-bundle manifest entry since it doesn't seem to work correctly with those imports and I'd say at that point it's probably the best to get it working that way.
Require-Bundle as defined in the osgi wiki

Package uses conflict: Import-Package: de.foo.bar; version="0.0.0"

I try to install a bundle in an OSGi environment (FUSE ESB) but do not manage to get it resolved. The error message is:
The bundle could not be resolved. Reason: Package uses conflict: Import-Package: de.foo.bar; version="0.0.0"
My bundle imports the package de.foo.bar.
The bundle which exports the package de.foo.bar does this with a 'uses' directive.
Export-Package = de.foo.bar;uses:="{other packages}";version="2.4.0"
As I understood I have to ensure that my bundle must import all other packages mentioned in the 'uses' directive of the de.foo.bar package (in the right version).
I checked this and also tried several version changes (0.0.0 and the real version numbers) but can not get it to work.
So, what does the error message realy means (maybe I understood it wrong)? What do I have to check?
Thanks for any help
Klaus
System Information:
FUSE ESB 4.2.0 (based on servicemix)
using maven-bundle-plugin 2.1.0 to generate OSGi MANIFEST header
I finally found what was wrong.
My bundle is a Spring Dynamic Module bundle and I did a mistake in the spring bean configuration (use a 'ref' instead a 'value' in a constructor-arg). Normally spring configuration errors are reported as such - I do not know why the current error resulted in the misleading message.
EDIT:
The faulty Spring configuration does not cause the uses conflict. It finally was the import of the package org.apache.log4j which is exported by different bundles (in my FUSE ESB container) and apparently was different wired to the bundles I tried to install.
Trying to solve my problem I found the article Diagnosing OSGi uses conflicts which I found helpfull to understand the problem.

Categories

Resources