You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Wim Vandenhaute <wi...@gmail.com> on 2008/08/19 12:37:53 UTC

Felix embedded in JBoss

Hi,

I am working on embedding felix into jboss. I want to be able to use  
services from OSGI bundles in my java ee container, and also use  
service from my java ee container in my OSGI bundles.
Right now I am trying to setup a simple HelloService that should get  
called from an EJB.

The embedded felix instance is created using a servletcontextlistener.  
The service interface for the HelloService is deployed in my ear and  
also added to the Felix FRAMEWORK_SYSTEMPACKAGES.
Below is the initialization code :

        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,  
org.osgi.util.tracker; version=1.3.1, "
                 + "foo.bar.osgi.service.helloworld; version=1.0.0,");

         configMap.put(AutoActivator.AUTO_START_PROP + ".1",
                 "file:bundle/foo-bar-osgi-helloworld-impl-1.1- 
SNAPSHOT.jar");

         // Explicitly specify the directory to use for caching bundles.
         configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");

         // Create activator,
         OSGIFelixActivator osgiFelixActivator = new  
OSGIFelixActivator();
         List<BundleActivator> baseBundles = new  
ArrayList<BundleActivator>();
         baseBundles.add(osgiFelixActivator);

         // Bind activator
         try {
             EjbUtils.bindComponent(OSGIFelixActivator.JNDI_PATH,  
osgiFelixActivator);
         } catch (NamingException e1) {
             LOG.error("[TODO]", e1);
         }

         // Now create an instance of the framework.
         Felix felix = new Felix(configMap, baseBundles);

         // Now start Felix instance.
         try {
             LOG.debug("Starting Felix OSGI container");
             felix.start();
         } catch (BundleException e) {
             LOG.error("[TODO]", e);
         }

The OSGIFelixActivator is an activator that stores the BundleContext,  
and registeres a ServiceTracker on the HelloService.
This activator is then bound to JNDI to later on use it in my EJB.

My problems are that when felix is initialized, I am getting an  
IOException during initialization of the felix ExtensionManager.

2008-08-19 11:57:20,726 DEBUG  
[org.jboss.mx.loading.UnifiedLoaderRepository3] Failed to update pkgs  
for  
cl 
=org.jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrder=2}
java.io.IOException: Resource does not exist: felix://extensions/
         at  
org 
.apache 
.felix 
.framework 
.URLHandlersBundleURLConnection 
.connect(URLHandlersBundleURLConnection.java:106)
         at  
org 
.apache 
.felix 
.framework 
.URLHandlersBundleURLConnection 
.getInputStream(URLHandlersBundleURLConnection.java:120)
         at java.net.URL.openStream(URL.java:1007)
         at org.jboss.mx.loading.ClassLoaderUtils 
$ClassPathIterator.<init>(ClassLoaderUtils.java:601)
         at  
org 
.jboss 
.mx.loading.ClassLoaderUtils.updatePackageMap(ClassLoaderUtils.java:267)
         at  
org 
.jboss 
.mx 
.loading 
.UnifiedLoaderRepository3 
.updatePackageMap(UnifiedLoaderRepository3.java:838)
         at  
org 
.jboss 
.mx 
.loading 
.UnifiedLoaderRepository3 
.addClassLoaderURL(UnifiedLoaderRepository3.java:737)
         at  
org 
.jboss 
.mx.loading.RepositoryClassLoader.addURL(RepositoryClassLoader.java:714)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at  
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39)
         at  
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at  
org 
.apache 
.felix 
.framework.util.SecureAction.addURLToURLClassLoader(SecureAction.java: 
681)
         at  
org 
.apache 
.felix.framework.ExtensionManager.<clinit>(ExtensionManager.java:95)
         at org.apache.felix.framework.Felix.<init>(Felix.java:276)
         at org.apache.felix.framework.Felix.<init>(Felix.java:125)
...
         at java.lang.Thread.run(Thread.java:613)
2008-08-19 12:15:44,358 DEBUG  
[org.jboss.mx.loading.RepositoryClassLoader] Added url: felix:// 
extensions/, to ucl:  
org.jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrde
r=2}
2008-08-19 12:15:44,371 DEBUG  
[net.link.safeonline.authentication.service.bean.OSGIStartableBean]  
Starting Felix OSGI container

And secondly the OSGI bundle implementing the HelloService never gets  
initialized. I have tried putting the bundle in my ear, or tried to  
specify the full path of the jar but no success.

Has anyone had more success ? I saw a post using the same approach on  
the dev list ( http://markmail.org/message/qu5ehtye3rn4wmwb#query: 
+page:1+mid:w22e3ucvztgiaqiw+state:results )

Re: Felix embedded in JBoss

Posted by drozzy <dr...@gmail.com>.
Hi Wim,
Any chance I can reach you somehow by email?

I am working on the same problem as you were.
Thanks
-- 
View this message in context: http://old.nabble.com/Felix-embedded-in-JBoss-tp19047890p31451216.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Felix embedded in JBoss

Posted by Wim Vandenhaute <wi...@gmail.com>.
I am using 1.0.4.

The problem was indeed forgetting to add the AutoActivator.
Regarding the exception, I tried both enabling and disabling the URL  
Handlers and both gave the same error.
I looked a bit deeper in the code as to what is happening and it can  
be safely ignored, its just a debug message, the url is added to the  
jboss classloader afterwards.

regards,
Wim.

On 19 Aug 2008, at 14:30, Karl Pauls wrote:

> What version of felix are you using?
>
> Furthermore, you need to add a special activator to the felix
> constructor (via the same list you already use to add yours) to make
> the autostart property work. Have a look at:
>
> http://svn.apache.org/repos/asf/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
>
> to see how it is done (the activator is
> org.apache.felix.main.AutoActivator). Otherwise your bundle will not
> be started.
>
> Alternatively, you could do something like the following:
>
> Felix felix = new Felix(configMap, new ArrayList());
>
> felix.start();
>
> felix.getBundleContext().installBundle("file:bundle/foo-bar-osgi- 
> helloworld-impl-1.1-SNAPSHOT.jar").start();
>
> In regard to the exception you see, try to enable/disable URLHandlers
> (your code looks like you disable it but then the stacktrace doesn't
> look like you do) and see whether that makes it go away. If not, you
> can just ignore it (it shouldn't matter).
>
> regards,
>
> Karl
>
> On Tue, Aug 19, 2008 at 12:37 PM, Wim Vandenhaute
> <wi...@gmail.com> wrote:
>> Hi,
>>
>> I am working on embedding felix into jboss. I want to be able to use
>> services from OSGI bundles in my java ee container, and also use  
>> service
>> from my java ee container in my OSGI bundles.
>> Right now I am trying to setup a simple HelloService that should  
>> get called
>> from an EJB.
>>
>> The embedded felix instance is created using a  
>> servletcontextlistener. The
>> service interface for the HelloService is deployed in my ear and  
>> also added
>> to the Felix FRAMEWORK_SYSTEMPACKAGES.
>> Below is the initialization code :
>>
>>      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,
>> org.osgi.util.tracker; version=1.3.1, "
>>               + "foo.bar.osgi.service.helloworld; version=1.0.0,");
>>
>>       configMap.put(AutoActivator.AUTO_START_PROP + ".1",
>>               "file:bundle/foo-bar-osgi-helloworld-impl-1.1- 
>> SNAPSHOT.jar");
>>
>>       // Explicitly specify the directory to use for caching bundles.
>>       configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");
>>
>>       // Create activator,
>>       OSGIFelixActivator osgiFelixActivator = new  
>> OSGIFelixActivator();
>>       List<BundleActivator> baseBundles = new  
>> ArrayList<BundleActivator>();
>>       baseBundles.add(osgiFelixActivator);
>>
>>       // Bind activator
>>       try {
>>           EjbUtils.bindComponent(OSGIFelixActivator.JNDI_PATH,
>> osgiFelixActivator);
>>       } catch (NamingException e1) {
>>           LOG.error("[TODO]", e1);
>>       }
>>
>>       // Now create an instance of the framework.
>>       Felix felix = new Felix(configMap, baseBundles);
>>
>>       // Now start Felix instance.
>>       try {
>>           LOG.debug("Starting Felix OSGI container");
>>           felix.start();
>>       } catch (BundleException e) {
>>           LOG.error("[TODO]", e);
>>       }
>>
>> The OSGIFelixActivator is an activator that stores the  
>> BundleContext, and
>> registeres a ServiceTracker on the HelloService.
>> This activator is then bound to JNDI to later on use it in my EJB.
>>
>> My problems are that when felix is initialized, I am getting an  
>> IOException
>> during initialization of the felix ExtensionManager.
>>
>> 2008-08-19 11:57:20,726 DEBUG
>> [org.jboss.mx.loading.UnifiedLoaderRepository3] Failed to update  
>> pkgs for
>> cl 
>> = 
>> org 
>> .jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrder=2}
>> java.io.IOException: Resource does not exist: felix://extensions/
>>       at
>> org 
>> .apache 
>> .felix 
>> .framework 
>> .URLHandlersBundleURLConnection 
>> .connect(URLHandlersBundleURLConnection.java:106)
>>       at
>> org 
>> .apache 
>> .felix 
>> .framework 
>> .URLHandlersBundleURLConnection 
>> .getInputStream(URLHandlersBundleURLConnection.java:120)
>>       at java.net.URL.openStream(URL.java:1007)
>>       at
>> org.jboss.mx.loading.ClassLoaderUtils 
>> $ClassPathIterator.<init>(ClassLoaderUtils.java:601)
>>       at
>> org 
>> .jboss 
>> .mx.loading.ClassLoaderUtils.updatePackageMap(ClassLoaderUtils.java: 
>> 267)
>>       at
>> org 
>> .jboss 
>> .mx 
>> .loading 
>> .UnifiedLoaderRepository3 
>> .updatePackageMap(UnifiedLoaderRepository3.java:838)
>>       at
>> org 
>> .jboss 
>> .mx 
>> .loading 
>> .UnifiedLoaderRepository3 
>> .addClassLoaderURL(UnifiedLoaderRepository3.java:737)
>>       at
>> org 
>> .jboss 
>> .mx.loading.RepositoryClassLoader.addURL(RepositoryClassLoader.java: 
>> 714)
>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>       at
>> sun 
>> .reflect 
>> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>       at
>> sun 
>> .reflect 
>> .DelegatingMethodAccessorImpl 
>> .invoke(DelegatingMethodAccessorImpl.java:25)
>>       at java.lang.reflect.Method.invoke(Method.java:585)
>>       at
>> org 
>> .apache 
>> .felix 
>> .framework 
>> .util.SecureAction.addURLToURLClassLoader(SecureAction.java:681)
>>       at
>> org 
>> .apache 
>> .felix.framework.ExtensionManager.<clinit>(ExtensionManager.java:95)
>>       at org.apache.felix.framework.Felix.<init>(Felix.java:276)
>>       at org.apache.felix.framework.Felix.<init>(Felix.java:125)
>> ...
>>       at java.lang.Thread.run(Thread.java:613)
>> 2008-08-19 12:15:44,358 DEBUG  
>> [org.jboss.mx.loading.RepositoryClassLoader]
>> Added url: felix://extensions/, to ucl:
>> org.jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrde
>> r=2}
>> 2008-08-19 12:15:44,371 DEBUG
>> [net.link.safeonline.authentication.service.bean.OSGIStartableBean]  
>> Starting
>> Felix OSGI container
>>
>> And secondly the OSGI bundle implementing the HelloService never gets
>> initialized. I have tried putting the bundle in my ear, or tried to  
>> specify
>> the full path of the jar but no success.
>>
>> Has anyone had more success ? I saw a post using the same approach  
>> on the
>> dev list (
>> http://markmail.org/message/qu5ehtye3rn4wmwb#query:+page:1+mid:w22e3ucvztgiaqiw+state:results
>> )
>
>
>
> -- 
> Karl Pauls
> karlpauls@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Felix embedded in JBoss

Posted by Karl Pauls <ka...@gmail.com>.
What version of felix are you using?

Furthermore, you need to add a special activator to the felix
constructor (via the same list you already use to add yours) to make
the autostart property work. Have a look at:

http://svn.apache.org/repos/asf/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java

to see how it is done (the activator is
org.apache.felix.main.AutoActivator). Otherwise your bundle will not
be started.

Alternatively, you could do something like the following:

Felix felix = new Felix(configMap, new ArrayList());

felix.start();

felix.getBundleContext().installBundle("file:bundle/foo-bar-osgi-helloworld-impl-1.1-SNAPSHOT.jar").start();

In regard to the exception you see, try to enable/disable URLHandlers
(your code looks like you disable it but then the stacktrace doesn't
look like you do) and see whether that makes it go away. If not, you
can just ignore it (it shouldn't matter).

regards,

Karl

On Tue, Aug 19, 2008 at 12:37 PM, Wim Vandenhaute
<wi...@gmail.com> wrote:
> Hi,
>
> I am working on embedding felix into jboss. I want to be able to use
> services from OSGI bundles in my java ee container, and also use service
> from my java ee container in my OSGI bundles.
> Right now I am trying to setup a simple HelloService that should get called
> from an EJB.
>
> The embedded felix instance is created using a servletcontextlistener. The
> service interface for the HelloService is deployed in my ear and also added
> to the Felix FRAMEWORK_SYSTEMPACKAGES.
> Below is the initialization code :
>
>       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,
> org.osgi.util.tracker; version=1.3.1, "
>                + "foo.bar.osgi.service.helloworld; version=1.0.0,");
>
>        configMap.put(AutoActivator.AUTO_START_PROP + ".1",
>                "file:bundle/foo-bar-osgi-helloworld-impl-1.1-SNAPSHOT.jar");
>
>        // Explicitly specify the directory to use for caching bundles.
>        configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");
>
>        // Create activator,
>        OSGIFelixActivator osgiFelixActivator = new OSGIFelixActivator();
>        List<BundleActivator> baseBundles = new ArrayList<BundleActivator>();
>        baseBundles.add(osgiFelixActivator);
>
>        // Bind activator
>        try {
>            EjbUtils.bindComponent(OSGIFelixActivator.JNDI_PATH,
> osgiFelixActivator);
>        } catch (NamingException e1) {
>            LOG.error("[TODO]", e1);
>        }
>
>        // Now create an instance of the framework.
>        Felix felix = new Felix(configMap, baseBundles);
>
>        // Now start Felix instance.
>        try {
>            LOG.debug("Starting Felix OSGI container");
>            felix.start();
>        } catch (BundleException e) {
>            LOG.error("[TODO]", e);
>        }
>
> The OSGIFelixActivator is an activator that stores the BundleContext, and
> registeres a ServiceTracker on the HelloService.
> This activator is then bound to JNDI to later on use it in my EJB.
>
> My problems are that when felix is initialized, I am getting an IOException
> during initialization of the felix ExtensionManager.
>
> 2008-08-19 11:57:20,726 DEBUG
> [org.jboss.mx.loading.UnifiedLoaderRepository3] Failed to update pkgs for
> cl=org.jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrder=2}
> java.io.IOException: Resource does not exist: felix://extensions/
>        at
> org.apache.felix.framework.URLHandlersBundleURLConnection.connect(URLHandlersBundleURLConnection.java:106)
>        at
> org.apache.felix.framework.URLHandlersBundleURLConnection.getInputStream(URLHandlersBundleURLConnection.java:120)
>        at java.net.URL.openStream(URL.java:1007)
>        at
> org.jboss.mx.loading.ClassLoaderUtils$ClassPathIterator.<init>(ClassLoaderUtils.java:601)
>        at
> org.jboss.mx.loading.ClassLoaderUtils.updatePackageMap(ClassLoaderUtils.java:267)
>        at
> org.jboss.mx.loading.UnifiedLoaderRepository3.updatePackageMap(UnifiedLoaderRepository3.java:838)
>        at
> org.jboss.mx.loading.UnifiedLoaderRepository3.addClassLoaderURL(UnifiedLoaderRepository3.java:737)
>        at
> org.jboss.mx.loading.RepositoryClassLoader.addURL(RepositoryClassLoader.java:714)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
> org.apache.felix.framework.util.SecureAction.addURLToURLClassLoader(SecureAction.java:681)
>        at
> org.apache.felix.framework.ExtensionManager.<clinit>(ExtensionManager.java:95)
>        at org.apache.felix.framework.Felix.<init>(Felix.java:276)
>        at org.apache.felix.framework.Felix.<init>(Felix.java:125)
> ...
>        at java.lang.Thread.run(Thread.java:613)
> 2008-08-19 12:15:44,358 DEBUG [org.jboss.mx.loading.RepositoryClassLoader]
> Added url: felix://extensions/, to ucl:
> org.jboss.mx.loading.UnifiedClassLoader3@bbdb8{ url=null ,addedOrde
> r=2}
> 2008-08-19 12:15:44,371 DEBUG
> [net.link.safeonline.authentication.service.bean.OSGIStartableBean] Starting
> Felix OSGI container
>
> And secondly the OSGI bundle implementing the HelloService never gets
> initialized. I have tried putting the bundle in my ear, or tried to specify
> the full path of the jar but no success.
>
> Has anyone had more success ? I saw a post using the same approach on the
> dev list (
> http://markmail.org/message/qu5ehtye3rn4wmwb#query:+page:1+mid:w22e3ucvztgiaqiw+state:results
> )



-- 
Karl Pauls
karlpauls@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org