Hi,

 

I am attempting to embed Felix in both JBoss and OC4J and while I am
able to get it to work, I am a little confused as to why and I certainly
do not like my current solution.

 

public class FelixOSGiProvider extends OSGiProvider {

      

      /**

       * Default Constructor.

       */

      protected FelixOSGiProvider(){}

      /**

       * Method to start the underlying OSGi runtime.

       * @throws Exception for startup exceptions.

       */

      public void start() throws Exception {

            System.out.println("---Starting up Felix OSGi Container
18---");

            // Create a case-insensitive configuration property map.

            Map configMap = new StringMap(false);

            // Configure the Felix instance to be embedded.

            configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP,
"true");

            configMap.put(FelixConstants.SERVICE_URLHANDLERS_PROP,
"false");

            // Add the host provided service interface package and the
core OSGi

            // packages to be exported from the class path via the
system bundle.

            configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,

                        "org.osgi.framework; version=1.3.0,"

                        + "org.osgi.service.packageadmin;
version=1.2.0,"

                        + "org.osgi.service.startlevel; version=1.0.0,"

                        + "org.osgi.service.url; version=1.0.0,"

                        + "com.leica.osgi.services; version=1.0.0,"

                        + "com.leica.osgi.entity; version=1.0.0");

            configMap.put(FelixConstants.AUTO_START_PROP + 

 
".1","file:///C:\\workspace\\Leica-OSGi-ServiceImpl-Bundle\\build\\com.l
eica.osgi.serviceImpl.jar ");

                configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP,
"c:\\OSGiBundles\\Leica-OSGi-Bundles");

            //Put the default Activator,

            List<BundleActivator> baseBundles = new ArrayList
<BundleActivator>();

            baseBundles.add(this.getActivator());

            // Now create an instance of the framework.

            Felix felix = new Felix();

            felix.start(new MutablePropertyResolverImpl(configMap), 

                        baseBundles);

      }

}

 

I have an EAR that contains the following .jars:

 

    com.leica.osgi.services.jar (Contains the ServiceAPI - interfaces)

    com.leica.osgi.entity.jar (Contains Entities)

    framework.jar  (contains class to bootstrap felix)

    leica.war (contains a Servlet that creates an instance of the Felix
framework by using classes in framework.jar)

 

The only way I could get this to work was to include the
"com.leica.osgi.services" and "com.leica.osgi.entity" packages in the
FRAMEWORK_SYSTEMPACKAGES property.  The bundle loaded by felix below,
com.leica.osgi.serviceImpl.jar, provides an implementation of a simple
OSGi Bundle that provides a simple service to getAllUsers().  

 

When the application is deployed, the embedded Felix instance is created
by the StartupServlet which binds the BaseBundleActivator to the JNDI
tree.  When an EJB is called that is dependent on an OSGi service, it
looks up the BaseBundleActivator from the JNDI tree and invokes the
appropriate method; in this case, getAllUsers().

 

The OSGi service, is dependent on importing packages from
com.leica.osgi.services and com.leica.osgi.entity, which are located in
the .ear file.  This has me a bit confused, since these packages are
deployed by the .ear how am I finding the classes in my Service?  Should
I not get a ClassNotFoundException or some other error?  

 

I really to not want to have to include all the packages of the system
as part of the FRAMEWORK_SYSTEMPACKAGES.  Ideally, I would prefer that
the entities, serviceAPI and ServiceImpl are all bundles and deployed
inside the embedded Felix instance and allow the EJB's to access them
similar to the above.

 

So I guess my first question is why does this work? 

 

Is it possible to remove the additional packages form the
FRAMEWORK_SYSTEMPACKAGES and still gain access to them from within the
EJB container?  Do I need a custom class loader to support this?

 

Is this even possible?

 

I tried adding the com.leica.* to the FRAMEWORK_BOOTDELEGATION packages
and removed the reference to them from the FRAMEWORK_SYSTEMPACKAGES, but
then I got an error that the bundle could not find a required import,
com.leica.osgi.entity.  

 

Thanks is advance for your assistance.

 

Regards,

 

Todd 

 

Reply via email to