Yes, it should be possible to run more than one war with felix inside side
by side without disabling url handlers. 4.0.3 had a bug in this area which
should be fixed in trunk. I'll have a look why it doesn't find the obr
urlhandler in the second instance.

regards,

Karl


On Thu, Jan 3, 2013 at 2:50 PM, itay hindy <[email protected]> wrote:

> Hi Karl,
>
> Attached you can found a sample war that demonstrate the problem. Putting
> this war (test1.war) to tomcat webapps works. Adding it again (with
> different name of course, test2 for example. *btw the only different
> between the wars must be the felix.cache.rootdir property that need to be
> change inside WEB-INF/framework.properties*) cause the problem.
> Some notes/questions:
>
> *1 - Most important: Is it possible to run multiple wars each with
> embedded Felix within? also each will have felix.service.urlhandlers=true?
> *
> 2 - there is not much in the war, just the next relevant lines:
>     public void start(BundleContext context) throws Exception{
>
>      URL url =
>  
> this.servletContext.getResource("/WEB-INF/lib/org.apache.felix.bundlerepository-1.6.6.jar");
>      Bundle bundle = context.installBundle(url.toExternalForm());
>      bundle.start();
>     }
> 3 - The version of felix framework is 4.0.3 (last stable). When you put
> the war in tomcat webapps every thing works. Adding another copy of the war
> to tomcat webapps gives the next error:
> 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:1077)
>         at
> org.apache.felix.framework.URLHandlers.<init>(URLHandlers.java:178)
>         at
> org.apache.felix.framework.URLHandlers.registerFrameworkInstance(URLHandlers.java:559)
>         at
> org.apache.felix.framework.URLHandlersActivator.start(URLHandlersActivator.java:71)
>         at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
>         at
> org.apache.felix.framework.Felix$SystemBundleActivator.start(Felix.java:4475)
>         at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
>         at org.apache.felix.framework.Felix.init(Felix.java:767)
>         at org.apache.felix.framework.Felix.start(Felix.java:816)
>         at
> com.wl.tomcat.http.bridge.FrameworkService.start(FrameworkService.java:25)
>         at
> com.wl.tomcat.http.bridge.StartupListener.contextInitialized(StartupListener.java:14)
>         at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
>         at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
>         at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>         at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
>         at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
>         at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
>         at
> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
>         at
> org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
>         at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>         at java.lang.Thread.run(Thread.java:662)
> java.lang.RuntimeException: Unable to start system bundle.
>         at org.apache.felix.framework.Felix.init(Felix.java:774)
>         at org.apache.felix.framework.Felix.start(Felix.java:816)
>         at
> com.wl.tomcat.http.bridge.FrameworkService.start(FrameworkService.java:25)
>         at
> com.wl.tomcat.http.bridge.StartupListener.contextInitialized(StartupListener.java:14)
>         at
> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
>         at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
>         at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>         at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
>         at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
>         at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
>         at
> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
>         at
> org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
>         at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>         at java.lang.Thread.run(Thread.java:662)
>  Probably because in URLHandlers
>
> try
>  {
>  URL.setURLStreamHandlerFactory(currentFactory);
>    }
>   catch (Exception ex)
>   {
>    // Ignore, this is a best effort (maybe log it or something)
>   }
>
>  and in URL.setURLStreamHandlerFactory
> if (factory != null) {
>  throw new Error("factory already defined");
> }
>
> 4 - When changing felix framework to 4.0.2 no errors but when trying later
> to use bundle.update (not in the attached example war) I get the next
> error: *Unable to update the bundle. (java.net.MalformedURLException:
> Unknown protocol: obr. *This is because inside URLHandlers class the
> m_streamHandlerFactory field is different between the first and second war
> 5 - Version 4.1.0-SNAPSHOTS gives same error as 4.0.2
> 6 - Attached also the java sources in the zip.
>
> Thanks a lot
>
> On Thu, Jan 3, 2013 at 11:00 AM, Karl Pauls <[email protected]> wrote:
>
>> Can you make a simple example of this available to me?
>>
>> regards,
>>
>> Karl
>>
>>
>> On Wed, Jan 2, 2013 at 9:21 AM, itay hindy <[email protected]> wrote:
>>
>> > Sorry, I had some issues and I was not clear enough.
>> >
>> > Let me summarize:
>> > 1 - I manage to run the war with the embedded felix and everything works
>> > great.
>> > 2 - I had to run the below lines in order that the ProxyServlet will
>> pass
>> > requests to my bundle that use a servlet
>> > *     //need it for the dispatcher to work*
>> > *    url =
>> >
>> >
>>  
>> this.servletContext.getResource("/WEB-INF/lib/org.apache.felix.http.bridge-2.2.0.jar");
>> > *
>> > *    bundle = context.installBundle(url.toExternalForm());*
>> > *    bundle.start(); *
>> > 3 - As I said everything works great with one war running in tomcat.
>> When I
>> > try to use 2 wars side by side I get the below exception:
>> > ERROR: Bundle org.apache.felix.http.bridge [2] Error starting
>> >
>> jndi:/localhost/itay/qa/WEB-INF/lib/org.apache.felix.http.bridge-2.2.0.jar
>> > (org.osgi.framework.BundleException: Activator start error in bundle
>> > org.apache.felix.http.bridge [2].)
>> > java.lang.LinkageError: loader constraint violation: when resolving
>> > overridden method
>> >
>> >
>> "org.apache.felix.http.base.internal.listener.AbstractListenerManager.addingService(Lorg/osgi/framework/ServiceReference;)Ljava/lang/Object;"
>> > the class lo
>> > ader (instance of
>> > org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of
>> the
>> > current class,
>> > org/apache/felix/http/base/internal/listener/AbstractListenerManager,
>> and
>> > its superclass loader (instance of org/apache/catalina/loa
>> > der/WebappClassLoader), have different Class objects for the type
>> > org/osgi/framework/ServiceReference used in the signature
>> >         at
>> >
>> >
>> org.apache.felix.http.base.internal.HttpServiceController.<init>(HttpServiceController.java:76)
>> >
>> > Thanks
>> >
>> >
>> > On Tue, Jan 1, 2013 at 4:23 PM, Richard S. Hall <[email protected]
>> > >wrote:
>> >
>> > > On 1/1/13 06:12, itay hindy wrote:
>> > >
>> > >> Ignore my last mail, I figure it out. It was because of activators
>> > order.
>> > >>
>> > >> Another question, I manage now to run the war that used the embedded
>> > >> felix.
>> > >> I try to execute http requests but fail on the the ProxyServlet. The
>> > >> DispatcherTracker has not been initialize so
>> > this.tracker.getDispatcher()
>> > >> returns null.
>> > >>
>> > >> How can I activate it?
>> > >>
>> > >
>> > > Sorry, I don't know what you are talking about.
>> > >
>> > > -> richard
>> > >
>> > >
>> > >> Thanks in advance
>> > >>
>> > >> On Tue, Jan 1, 2013 at 10:10 AM, itay hindy <[email protected]>
>> > wrote:
>> > >>
>> > >>  Thanks Richard, I followed your advice and make it works.
>> > >>> Now I have a new Issue:
>> > >>>
>> > >>> I try to use *bundle.update() *and I get next exception:
>> > >>> *Caused by: java.net.**MalformedURLException: Unknown protocol: obr
>> > >>> *
>> > >>> When I run felix *not *embedded from tomcat everything works.
>> > >>>
>> > >>>
>> > >>> I looked into it and the problem seems to be that when running
>> embedded
>> > >>> felix within tomcat the URLHandlersStreamHandlerProxy class is not
>> > used.
>> > >>>
>> > >>> The next line:
>> > >>> *return new URL(context, "obr:...", handler)*
>> > >>>
>> > >>> for embedded felix just tries to create url while for stand alone
>> felix
>> > >>> it
>> > >>> uses the URLHandlersStreamHandlerProxy.
>> > >>>
>> > >>> Any Idea how to config it?
>> > >>>
>> > >>> On Thu, Dec 27, 2012 at 4:08 PM, Richard S. Hall <
>> [email protected]
>> > >>> >wrote:
>> > >>>
>> > >>>  On 12/27/12 07:25, itay hindy wrote:
>> > >>>>
>> > >>>>  Hi All,
>> > >>>>>
>> > >>>>> I have a question about running embedded felix within tomcat.
>> > >>>>>
>> > >>>>> I had follow the instructions at
>> > >>>>> http://felix.apache.org/site/****apache-felix-framework-**<
>> > http://felix.apache.org/site/**apache-felix-framework-**>
>> > >>>>> launching-and-embedding.html<h**ttp://felix.apache.org/site/**
>> > >>>>> apache-felix-framework-**launching-and-embedding.html<
>> >
>> http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
>> > >
>> > >>>>> >
>> > >>>>>
>> > >>>>>
>> > >>>>> I manage to run felix within tomcat, however I have a problem with
>> > >>>>>  class
>> > >>>>> loaders.
>> > >>>>>
>> > >>>>> Here is the scenario:
>> > >>>>> 1 - My host application needs to use the RepositoryAdmin service
>> > >>>>> from org.apache.felix.****bundlerepository-1.6.6.jar bundle
>> > >>>>> 2 - I add the org.apache.felix.****bundlerepository-1.6.6.jar to
>> my
>> > >>>>> class
>> > >>>>>
>> > >>>>> path
>> > >>>>> so I can access its interfaces
>> > >>>>> 3 - I install this bundle on my host application activator code
>> > >>>>>        URL url =
>> > >>>>>    this.servletContext.****getResource("/WEB-INF/lib/org.****
>> > >>>>> apache.felix.bundlerepository-****1.6.6.jar");
>> > >>>>>       Bundle bundle =
>> > context.installBundle(url.****toExternalForm());
>> > >>>>>
>> > >>>>>       bundle.start();
>> > >>>>> 4 - I have created ServiceTracker for the RepositoryAdmin service
>> > >>>>> 5 - In the ServiceTracker the next bold line fails with class cast
>> > >>>>> exception
>> > >>>>> public Object addingService(ServiceReference reference) {
>> > >>>>>                   Object serviceObject =
>> > super.addingService(reference)
>> > >>>>> ****
>> > >>>>> ;
>> > >>>>>               try {
>> > >>>>>                       *repositoryAdmin = (RepositoryAdmin)**
>> > >>>>>
>> > >>>>> serviceObject*;
>> > >>>>>
>> > >>>>> } catch (Exception e) {
>> > >>>>> e.printStackTrace();
>> > >>>>> }
>> > >>>>>                   return repositoryAdmin;
>> > >>>>>               }
>> > >>>>>
>> > >>>>> The reason seems to be because RepositoryAdmin interface
>> classloader
>> > >>>>>   comes
>> > >>>>> from org.apache.catalina.loader.****WebappClassLoader and the
>> > >>>>>
>> > >>>>> actual RepositoryAdminImpl  object (the *serviceObject*) is coming
>> > from
>> > >>>>> BundleWiringImpl$****BundleClassLoaderJava5
>> > >>>>>
>> > >>>>>  Yes, of course. The bundle doesn't have access to your outer
>> > >>>> repository
>> > >>>> classes and your host doesn't have access to the bundle's
>> repository
>> > >>>> classes.
>> > >>>>
>> > >>>> You will need to try to export the repository packages from your
>> host
>> > >>>> app
>> > >>>> via the system bundle. Of course, this will only work if the
>> > repository
>> > >>>> bundle properly imports AND exports the repository packages. Even
>> if
>> > it
>> > >>>> does, it is tricky and might not work if there are any "uses"
>> > constraint
>> > >>>> issues, but you could try. If that doesn't work, you could look
>> into
>> > >>>> boot
>> > >>>> delegating the packages from your class path, but that is a last
>> > resort.
>> > >>>>
>> > >>>> -> richard
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>>>  Any Idea?
>> > >>>>>
>> > >>>>> Regards,
>> > >>>>> Itay Hindy
>> > >>>>>
>> > >>>>>
>> > >>>>>  ------------------------------****----------------------------**
>> > >>>> --**---------
>> > >>>> To unsubscribe, e-mail: users-unsubscribe@felix.**apac**he.org<
>> > http://apache.org>
>> > >>>> <users-unsubscribe@**felix.apache.org<
>> > [email protected]>
>> > >>>> >
>> > >>>>
>> > >>>> For additional commands, e-mail: [email protected]
>> > >>>>
>> > >>>>
>> > >>>>
>> > >>> --
>> > >>> Regards,
>> > >>>
>> > >>> Itay Hindy
>> > >>> Software Solutions
>> > >>> +972-54-5935042
>> > >>> linkedin: http://www.linkedin.com/in/**itayhindy<
>> > http://www.linkedin.com/in/itayhindy>
>> > >>>
>> > >>>
>> > >>
>> > >>
>> > >
>> > >
>> ------------------------------**------------------------------**---------
>> > > To unsubscribe, e-mail: users-unsubscribe@felix.**apache.org<
>> > [email protected]>
>> > > For additional commands, e-mail: [email protected]
>> > >
>> > >
>> >
>> >
>> > --
>> > Regards,
>> >
>> > Itay Hindy
>> > Software Solutions
>> > +972-54-5935042
>> > linkedin: http://www.linkedin.com/in/itayhindy
>> >
>>
>>
>>
>> --
>> Karl Pauls
>> [email protected]
>> http://twitter.com/karlpauls
>> http://www.linkedin.com/in/karlpauls
>> https://profiles.google.com/karlpauls
>>
>
>
>
> --
> Regards,
>
> Itay Hindy
> Software Solutions
> +972-54-5935042
> linkedin: http://www.linkedin.com/in/itayhindy
>



-- 
Karl Pauls
[email protected]
http://twitter.com/karlpauls
http://www.linkedin.com/in/karlpauls
https://profiles.google.com/karlpauls

Reply via email to