You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Thierry Templier <te...@yahoo.fr> on 2007/08/09 17:15:55 UTC

Embedded Felix in a web application

Hello,

I have problems to embed a felix (version 1.0)
container in a java web application deployed on a
Tomcat server (version 5.5).
In order to start/stop the container, I use a
ServletContext listener as follow:

public class WebAppListener implements
ServletContextListener {
    private OsgiManager osgiManager = new
FelixManager();

    public void contextInitialized(ServletContextEvent
context) {
        osgiManager.initOsgi();
    }

    public void contextDestroyed(ServletContextEvent
context) {
        osgiManager.destroyOsgi();
    }
}

and the code of the initOsgi method is:

public void initOsgi() {
    Map configMap = new StringMap(false);
   
configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP,
"true");
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");
configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP,
"cache");
	
try {
    List activators = new ArrayList();
    initActivator = new InitActivator();
    activators.add(initActivator);

    felixContainer = new Felix(configMap, activators);
    felixContainer.start();	    
} catch(Exception ex) {
    ex.printStackTrace();
}

I have the following error when the webapp starts:

ERROR: Unable to start system bundle.
(java.lang.Error: factory already defined)
java.lang.Error: factory already defined
	at
java.net.URL.setURLStreamHandlerFactory(URL.java:1076)
	at
org.apache.felix.framework.URLHandlers.<init>(URLHandlers.java:95)
	at
org.apache.felix.framework.URLHandlers.registerInstance(URLHandlers.java:283)
	at
org.apache.felix.framework.URLHandlersActivator.start(URLHandlersActivator.java:60)
	at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
	at
org.apache.felix.framework.Felix$SystemBundleActivator.start(Felix.java:3798)
	at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
	at
org.apache.felix.framework.Felix.start(Felix.java:703)

Is there specific configuration to do in order to
embed Felix in a web application?

Thanks a lot for your help?
Thierry

Take a look at my blog:
http://jroller.com/page/Templth/
(old: http://templth.blogspot.com/)


      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

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


Re: Embedded Felix in a web application

Posted by Thierry Templier <te...@yahoo.fr>.
Thanks Karl and Richard for your help!
It solves my problem. This latter occurs only when I
try to use Felix in an embedded mode in a Eclipse
Dynamic Web Project with Web Tools Platform. I works
correctly in a simple Java project...
Thierry

> Also, we have plans to add support for replacing
> (and delegating) to 
> existing URL handler factories too, but for now you
> will need to disable 
> the framework's factory.
> 
> -> richard
> 
> Karl Pauls wrote:
> > You need to disable the URLHandler by setting the
> > felix.service.urlhandlers property to false in the
> config.properties
> > file.
> >
> > regards,
> >
> > Karl

Take a look at my blog:
http://jroller.com/page/Templth/
(old: http://templth.blogspot.com/)


      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

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


Re: Embedded Felix in a web application

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Also, we have plans to add support for replacing (and delegating) to 
existing URL handler factories too, but for now you will need to disable 
the framework's factory.

-> richard

Karl Pauls wrote:
> You need to disable the URLHandler by setting the
> felix.service.urlhandlers property to false in the config.properties
> file.
>
> regards,
>
> Karl
>
> On 8/9/07, Thierry Templier <te...@yahoo.fr> wrote:
>   
>> Hello,
>>
>> I have problems to embed a felix (version 1.0)
>> container in a java web application deployed on a
>> Tomcat server (version 5.5).
>> In order to start/stop the container, I use a
>> ServletContext listener as follow:
>>
>> public class WebAppListener implements
>> ServletContextListener {
>>     private OsgiManager osgiManager = new
>> FelixManager();
>>
>>     public void contextInitialized(ServletContextEvent
>> context) {
>>         osgiManager.initOsgi();
>>     }
>>
>>     public void contextDestroyed(ServletContextEvent
>> context) {
>>         osgiManager.destroyOsgi();
>>     }
>> }
>>
>> and the code of the initOsgi method is:
>>
>> public void initOsgi() {
>>     Map configMap = new StringMap(false);
>>
>> configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP,
>> "true");
>> 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");
>> configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP,
>> "cache");
>>
>> try {
>>     List activators = new ArrayList();
>>     initActivator = new InitActivator();
>>     activators.add(initActivator);
>>
>>     felixContainer = new Felix(configMap, activators);
>>     felixContainer.start();
>> } catch(Exception ex) {
>>     ex.printStackTrace();
>> }
>>
>> I have the following error when the webapp starts:
>>
>> ERROR: Unable to start system bundle.
>> (java.lang.Error: factory already defined)
>> java.lang.Error: factory already defined
>>         at
>> java.net.URL.setURLStreamHandlerFactory(URL.java:1076)
>>         at
>> org.apache.felix.framework.URLHandlers.<init>(URLHandlers.java:95)
>>         at
>> org.apache.felix.framework.URLHandlers.registerInstance(URLHandlers.java:283)
>>         at
>> org.apache.felix.framework.URLHandlersActivator.start(URLHandlersActivator.java:60)
>>         at
>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>>         at
>> org.apache.felix.framework.Felix$SystemBundleActivator.start(Felix.java:3798)
>>         at
>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>>         at
>> org.apache.felix.framework.Felix.start(Felix.java:703)
>>
>> Is there specific configuration to do in order to
>> embed Felix in a web application?
>>
>> Thanks a lot for your help?
>> Thierry
>>
>> Take a look at my blog:
>> http://jroller.com/page/Templth/
>> (old: http://templth.blogspot.com/)
>>
>>
>>       _____________________________________________________________________________
>> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
>>
>> ---------------------------------------------------------------------
>> 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: Embedded Felix in a web application

Posted by Karl Pauls <ka...@gmail.com>.
You need to disable the URLHandler by setting the
felix.service.urlhandlers property to false in the config.properties
file.

regards,

Karl

On 8/9/07, Thierry Templier <te...@yahoo.fr> wrote:
> Hello,
>
> I have problems to embed a felix (version 1.0)
> container in a java web application deployed on a
> Tomcat server (version 5.5).
> In order to start/stop the container, I use a
> ServletContext listener as follow:
>
> public class WebAppListener implements
> ServletContextListener {
>     private OsgiManager osgiManager = new
> FelixManager();
>
>     public void contextInitialized(ServletContextEvent
> context) {
>         osgiManager.initOsgi();
>     }
>
>     public void contextDestroyed(ServletContextEvent
> context) {
>         osgiManager.destroyOsgi();
>     }
> }
>
> and the code of the initOsgi method is:
>
> public void initOsgi() {
>     Map configMap = new StringMap(false);
>
> configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP,
> "true");
> 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");
> configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP,
> "cache");
>
> try {
>     List activators = new ArrayList();
>     initActivator = new InitActivator();
>     activators.add(initActivator);
>
>     felixContainer = new Felix(configMap, activators);
>     felixContainer.start();
> } catch(Exception ex) {
>     ex.printStackTrace();
> }
>
> I have the following error when the webapp starts:
>
> ERROR: Unable to start system bundle.
> (java.lang.Error: factory already defined)
> java.lang.Error: factory already defined
>         at
> java.net.URL.setURLStreamHandlerFactory(URL.java:1076)
>         at
> org.apache.felix.framework.URLHandlers.<init>(URLHandlers.java:95)
>         at
> org.apache.felix.framework.URLHandlers.registerInstance(URLHandlers.java:283)
>         at
> org.apache.felix.framework.URLHandlersActivator.start(URLHandlersActivator.java:60)
>         at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>         at
> org.apache.felix.framework.Felix$SystemBundleActivator.start(Felix.java:3798)
>         at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:589)
>         at
> org.apache.felix.framework.Felix.start(Felix.java:703)
>
> Is there specific configuration to do in order to
> embed Felix in a web application?
>
> Thanks a lot for your help?
> Thierry
>
> Take a look at my blog:
> http://jroller.com/page/Templth/
> (old: http://templth.blogspot.com/)
>
>
>       _____________________________________________________________________________
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Karl Pauls
karlpauls@gmail.com

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