ops4j / org.ops4j.pax.web

OSGi R7 Http Service, Whiteboard and Web Applications (OSGi CMPN Release chapters 102, 140 and 128) implementation using Jetty 9, Tomcat 9 or Undertow 2.
https://ops4j1.jira.com/wiki/display/paxweb/Pax+Web
Other
144 stars 183 forks source link

JSP-Webapp without JSF-dependencies wont start when MyFaces-Core is installed [PAXWEB-953] #1232

Closed ops4j-issues closed 8 years ago

ops4j-issues commented 8 years ago

Marc Schlegel created PAXWEB-953

I have two webapp-bundles, one uses JSF, the other Struts. The struts-bundle wont start because it cannot find org.apache.myfaces.webapp.StartupServletContextListener

  1. webapp-jsf
  2. webapp-struts
  3. struts-wrapper
  4. myfaces-impl
  5. deps...

Reason: org.ops4j.pax.web.jsp.TldScanner scanns all bundles for Tag-Libraries. The result is mapped to each webapp.
Now myfaces-impl contains myfaces_core.tld which registers a listener org.apache.myfaces.webapp.StartupServletContextListener. This listener is needed for webapp-jsf, but not for webapp-struts. When webapp-struts is trying to add the listener, it fails with ClassNotFoundException, which is correct.

log

17:53:40.226 INFO  [pool-5-thread-1] o.o.p.w.s.j.i.HttpServiceContext - registering JasperInitializer
17:53:40.246 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/c-rt.tld
17:53:40.258 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/c.tld
17:53:40.264 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/fmt-rt.tld
17:53:40.269 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/fmt.tld
17:53:40.272 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/permittedTaglibs.tld
17:53:40.274 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/scriptfree.tld
17:53:40.276 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/sql-rt.tld
17:53:40.278 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/sql.tld
17:53:40.280 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/taglib.tld
17:53:40.281 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-bean-el.tld
17:53:40.284 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-bean.tld
17:53:40.288 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-faces.tld
17:53:40.291 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-html-el.tld
17:53:40.308 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-html.tld
17:53:40.331 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-logic-el.tld
17:53:40.347 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-logic.tld
17:53:40.356 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-nested.tld
17:53:40.368 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-tiles-el.tld
17:53:40.370 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/tld/struts-tiles.tld
17:53:40.372 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/x-rt.tld
17:53:40.374 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://1.0:0/META-INF/x.tld
17:53:40.378 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/c-1_0-rt.tld
17:53:40.380 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/c-1_0.tld
17:53:40.382 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/c.tld
17:53:40.384 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/fmt-1_0-rt.tld
17:53:40.386 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/fmt-1_0.tld
17:53:40.388 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/fmt.tld
17:53:40.390 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/fn.tld
17:53:40.392 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/permittedTaglibs.tld
17:53:40.392 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/scriptfree.tld
17:53:40.393 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/sql-1_0-rt.tld
17:53:40.394 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/sql-1_0.tld
17:53:40.395 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/sql.tld
17:53:40.396 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/x-1_0-rt.tld
17:53:40.398 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/x-1_0.tld
17:53:40.400 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://71.0:0/META-INF/x.tld
17:53:40.402 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://44.0:0/META-INF/myfaces_core.tld
17:53:40.405 INFO  [pool-5-thread-1] org.ops4j.pax.web.jsp.TldScanner - found TLD bundle://44.0:0/META-INF/myfaces_html.tld
17:53:40.420 WARN  [pool-5-thread-1] o.e.j.u.component.AbstractLifeCycle - FAILED HttpServiceContext{httpContext=WebAppHttpContext{de.test.frontend.struts - 8}}: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener not found by de.test.frontend.struts [8]
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener not found by de.test.frontend.struts [8]
    at org.eclipse.jetty.server.handler.ContextHandler$Context.addListener(ContextHandler.java:2221) [na:na]
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.addListener(ServletContextHandler.java:1282) [na:na]
    at org.ops4j.pax.web.jsp.JasperInitializer.onStartup(JasperInitializer.java:110) [na:na]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext$1.call(HttpServiceContext.java:192) [na:na]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext$1.call(HttpServiceContext.java:187) [na:na]
    at org.ops4j.pax.swissbox.core.ContextClassLoaderUtils.doWithClassLoader(ContextClassLoaderUtils.java:60) [na:na]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doStart(HttpServiceContext.java:186) [na:na]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [na:na]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl$1.start(JettyServerImpl.java:259) [na:na]
    at org.ops4j.pax.web.service.internal.HttpServiceStarted.end(HttpServiceStarted.java:1047) [na:na]
    at org.ops4j.pax.web.service.internal.HttpServiceProxy.end(HttpServiceProxy.java:413) [na:na]
    at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.end(RegisterWebAppVisitorWC.java:380) [na:na]
    at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:692) [na:na]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.register(WebAppPublisher.java:237) [na:na]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:182) [na:na]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:135) [na:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:894) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:943) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:794) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:544) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4445) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.Felix.registerService(Felix.java:3431) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:353) [org.apache.felix.framework-4.4.1.jar:na]
    at org.ops4j.pax.web.extender.war.internal.DefaultWebAppDependencyManager$1.serviceChanged(DefaultWebAppDependencyManager.java:64) [na:na]
    at org.ops4j.pax.web.extender.war.internal.DefaultWebAppDependencyManager$1.serviceChanged(DefaultWebAppDependencyManager.java:54) [na:na]
    at org.ops4j.pax.web.extender.war.internal.tracker.ReplaceableService.bind(ReplaceableService.java:71) [na:na]
    at org.ops4j.pax.web.extender.war.internal.tracker.ReplaceableService$Customizer.addingService(ReplaceableService.java:86) [na:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229) [org.apache.felix.framework-4.4.1.jar:na]
    at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:894) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:943) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:794) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:544) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4445) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.Felix.registerService(Felix.java:3431) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346) [org.apache.felix.framework-4.4.1.jar:na]
    at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:356) [na:na]
    at org.ops4j.pax.web.service.internal.Activator$3.run(Activator.java:293) [na:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_66]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_66]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_66]
Caused by: java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener not found by de.test.frontend.struts [8]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993) [org.apache.felix.framework-4.4.1.jar:na]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [na:1.8.0_66]
    at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1853) [org.apache.felix.framework-4.4.1.jar:na]
    at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:958) [org.apache.felix.framework-4.4.1.jar:na]
    at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176) [na:na]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) [na:1.8.0_66]
    at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192) [na:na]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [na:1.8.0_66]
    at org.eclipse.jetty.server.handler.ContextHandler$Context.addListener(ContextHandler.java:2216) [na:na]
    ... 49 common frames omitted

This issue should be reproducible without Struts. All it takes is a valid jsf-webapp and a simple jsp-webapp.


Affects: 4.2.4 Fixed in: 4.2.5, 6.0.0 Votes: 0, Watches: 2

ops4j-issues commented 8 years ago

Marc Schlegel commented

Wrapping the call to context.addListener(listener) with a try-catch makes webapp-struts available because the deployment now does not fail.

JasperInitializer line 108

        // add any listeners defined in TLDs
        for (String listener : scanner.getListeners()) {
            try {
                context.addListener(listener);
            }catch(RuntimeException e){
                if(e.getCause() instanceof ClassNotFoundException){
                    log.error("Could not add listener to context: {}", e.getMessage());
                }else{
                    throw e;
                }
            }
        }

But that's just solving the symptom. The problem is that the generic solution with the TLDs does not take classes into account that might not be imported/wired.

A possible solution might be the osgi-capability-model: only when a webapp requires the capability "jsf" it gets the tld added from the bundle providing the capability "jsf". But this would require that the providers must enhance their metadata with a "standard" capability...

ops4j-issues commented 8 years ago

Marc Schlegel commented

org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC#visit also skips ClassNotFoundExceptions and continues. So the above solution might be reasonable.

ops4j-issues commented 8 years ago

Marc Schlegel commented

Fix was commited in brach PAXWEB-953 .

Achim Nierbeck If there are no objections to the fix, I would like to merge this to master and 4.x

ops4j-issues commented 8 years ago

Achim Nierbeck commented

Marc Schlegel, looks fine with me.

ops4j-issues commented 8 years ago

Marc Schlegel commented

merged in master and 4.2.x

Note: I forgot to merge 4.2.x from the branch before I deleted it. So now the commit in 4.2.x has another ID than the one in master :-/