6 Replies Latest reply: Mar 15, 2012 10:35 AM by Lee Smith RSS

Unable to reference a service in a bundle when the Interface it implements is contained in another bundle

Lee Smith Newbie

As part of my investigation into OSGI on JBoss AS 7 I have created four OSGi bundles that are configured using blueprint. 

 

Here is a brief description of each of the bundles

  • an API bundle that contains an interface named Job that has a single method named getName() which retruns a String.
  • an example job bundle that contains a class named ExampleJob that implements the Job interface.
  • a core services bundle that exports an OSGi service which is used by the ExampleJob class
  • and finally a job repository bundle that contains a blueprint reference-list element that should be populated with every service that implements the Job interface.  The reference-list also contains a reference-listener that intercepts jobs being added to the list and calls the getName() method of the Job and logs out the result.

 

The idea is that i would be able to deploy the API, Core, and Repository bundles, and then deploy many Job bundles which would have their Jobs (exported as services) automatically added to the list of Jobs in the Repository bundle.

 

Unfortunately this does not work, the logging from the reference-listener does not get output, instead I see this log line:

 

WARN  [org.jboss.osgi.framework.internal.ServiceState] (pool-7-thread-3) The service's classloader has no visibility of the requested class: com.efstech.demo.osgi.api.model.Job

 

Incidentally when I deploy the bundles in this order:

API -> Core -> Example Job -> Repository

 

The Job correctly gets added to the list, the reference-listener logs the name of the Job and I do not see the warning from the ServiceState class.

 

I have also written the bundles as plain OSGi bundles without any blueprint configuration, just relying only on the bundle activators to glue the bundles together and it works as desired i.e. being able to deploy the bundles in the following order:

API -> Core -> Repository-> Example Job

 

I have been using the Sun JDK on Ubuntu:

java version "1.6.0_26"

Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

 

I have been testing the OSGi/blueprint bundles on JBoss AS 7.0.2 with both the jbosgi-framework-core-1.0.8.CR8.jar that comes with JBoss AS 7.0.2 and jbosgi-framework-core-1.0.1.jar that I downloaded from from the jboss repository.  I also tested the bundles with JBoss 7.1.0.Beta1 (which comes with jbosgi-framework-core-1.1.0.jar) but all with the same result.

 

I will attach the compiled bundles and the source code.  Any help would be much appreciated!

 

Thanks,

Lee

  • 1. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    jye.tucker Newbie

    I've also hit this problem on jboss-as-7.1.0.CR1b in our app, and also with the source attached above.

     

    Although I've been using OSGi with declarative services for a few years, we've just migrated to blueprint and JBoss AS 7 and still getting my head around it. I've checked package visibility on the bundles and it looks correct.

     

    This could be the same issue - https://issues.jboss.org/browse/JBOSGI-485

     

    Did you have any luck resolving or working around?

     

    I'll link this forum post to the issue above as this has better detail, and will keep investigating.

  • 2. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    Lee Smith Newbie

    I haven't had any luck resolving the issue unfortunately.  I have managed to get the same bundles working with Eclipse Virgo though so it seems to be the way in which OSGi is implemented within JBoss that is causing the issue.

  • 3. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    Thomas Diesler Master

    I took a quick look at this in 7.1.0.Final

     

    To enable blueprint, you can use the following configuration

     

    <capabilities>
    <capability name="javax.servlet.api:v25"/>
    <capability name="javax.transaction.api"/>
    <capability name="org.apache.felix.log" startlevel="1"/>
    <capability name="org.jboss.osgi.logging" startlevel="1"/>
    <capability name="org.apache.felix.configadmin" startlevel="1"/>
    <capability name="org.jboss.as.osgi.configadmin" startlevel="1"/>
    <capability name="org.apache.aries:org.apache.aries.util:0.4" startlevel="2"/>
    <capability name="org.apache.aries.proxy:org.apache.aries.proxy:0.4" startlevel="2"/>
    <capability name="org.apache.aries.blueprint:org.apache.aries.blueprint:0.4" startlevel="2"/>
    </capabilities>
    

     

    Your bundles have a dependency on log4j. So you need to setup visibility to that module as well or alternatively deploy a bundle that provides that API

     

    <property name="org.jboss.osgi.system.modules.extra">
    org.apache.log4j
    </property>
    <property name="org.osgi.framework.system.packages.extra">
    org.apache.log4j;version=1.2
    </property>
    

     

     

    Whith this in place, I get an output like this.

     

    16:50:18,106 INFO  [org.jboss.osgi.framework.internal.FrameworkActive] (MSC service thread 1-1) OSGi Framework started
    16:50:18,144 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.0.Final "Thunder" started in 7625ms - Started 135 of 205 services (69 services are passive or on-demand)
    16:50:34,541 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "coreapibundle-1.0-SNAPSHOT.jar"
    16:50:34,730 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: coreapibundle:1.0.0.SNAPSHOT
    16:50:34,745 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-2) Bundle started: coreapibundle:1.0.0.SNAPSHOT
    16:50:34,850 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "coreapibundle-1.0-SNAPSHOT.jar"
    16:50:39,880 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "core-1.0-SNAPSHOT.jar"
    16:50:39,905 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: core:1.0.0.SNAPSHOT
    16:50:39,927 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "core-1.0-SNAPSHOT.jar"
    16:50:39,957 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-3) Bundle started: core:1.0.0.SNAPSHOT
    16:50:39,969 INFO  [com.efstech.demo.osgi.core.CoreServicesActivator] (Blueprint Extender: 2) Started Core Services Bundle
    16:50:49,943 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "repo-1.0-SNAPSHOT.jar"
    16:50:49,961 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: repo:1.0.0.SNAPSHOT
    16:50:49,993 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-1) Bundle started: repo:1.0.0.SNAPSHOT
    16:50:49,994 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "repo-1.0-SNAPSHOT.jar"
    16:50:50,031 INFO  [org.apache.aries.blueprint.container.BlueprintContainerImpl] (Blueprint Extender: 1) Bundle repo is waiting for dependencies [(objectClass=com.efstech.demo.osgi.api.model.Job)]
    16:51:00,010 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "examplejob-1.0-SNAPSHOT.jar"
    16:51:00,029 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: examplejob:1.0.0.SNAPSHOT
    16:51:00,045 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-4) Bundle started: examplejob:1.0.0.SNAPSHOT
    16:51:00,082 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "examplejob-1.0-SNAPSHOT.jar"
    16:51:00,095 INFO  [com.efstech.demo.osgi.examplejob.ExampleJobActivator] (Blueprint Extender: 3) Bundle ExampleJob Installed
    16:51:00,111 INFO  [com.efstech.demo.osgi.core.services.VeryUsefulServiceImpl] (Blueprint Extender: 2) Wow, this is so useful!!
    

     

    I guess, this is all good.

  • 4. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    jye.tucker Newbie

    I've also confirmed this is working in 7.1.0.Final. I have a similar set of capabilities to what Thomas describes above, and a bunch of bundles with blueprint services and it is all working well.

     

    Lee - if you're still having issues after upgrading, let me know and I'd be happy to help.

  • 5. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    Thomas Diesler Master

    In 7.1.0.Final it is sufficient to define an extra system module like this

     

    <property name="org.jboss.osgi.system.modules.extra">
        org.apache.log4j
    </property> 
    
  • 6. Re: Unable to reference a service in a bundle when the Interface it implements is contained in another bundle
    Lee Smith Newbie

    Thanks very much for your help guys I will give 7.1.0.Final a try when I next get a chance.