New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAppContext UNAVAILABLE when stopping and restarting embedded Jetty with Omnifaces 2.1 #166

Closed
jansohn opened this Issue Sep 16, 2015 · 10 comments

Comments

Projects
None yet
2 participants
@jansohn

jansohn commented Sep 16, 2015

I'm trying to run my integration tests with an embedded Jetty and Omnifaces 2.1. As soon as I try to restart the jetty server the WebAppContext becomes UNAVAILABLE without any other error messages:

+= o.e.j.w.WebAppContext@184013e{/webapp,[file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/omnifaces-2.1.jar!/META-INF/resources, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/javax.faces-2.2.12.jar!/META-INF/resources],UNAVAILABLE} - STARTED
[...]
| | | += default@5c13d641==org.eclipse.jetty.servlet.DefaultServlet,0,false - STOPPED
[...]
| | | += jsp@19c47==org.eclipse.jetty.jsp.JettyJspServlet,0,false - STOPPED
[...]
| | | += Faces Servlet@87ee159b==javax.faces.webapp.FacesServlet,1,false - STOPPED
[...]
| | | += com.test.webapp.servlets.HelloServlet@97f99221==com.test.webapp.servlets.HelloServlet,-1,false - STOPPED
[...]

Switching back to Omnifaces 1.11 gets rid of the problem.

Minimal webapp to reproduce (run as mvn clean verify):
https://github.com/jansohn/jetty-omnifaces

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 21, 2015

Member

Just for your information, I was able to reproduce it. Unfortunately, I also didn't get any informative exceptions/messages as to the root cause. I have locally experimented with removing CDI features one by one and it appears that it works fine once I remove the eager beans feature (@eager and friends).

I will investigate later what exactly in the eager beans feature is causing this.

Member

BalusC commented Sep 21, 2015

Just for your information, I was able to reproduce it. Unfortunately, I also didn't get any informative exceptions/messages as to the root cause. I have locally experimented with removing CDI features one by one and it appears that it works fine once I remove the eager beans feature (@eager and friends).

I will investigate later what exactly in the eager beans feature is causing this.

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 22, 2015

Member

Can you please retry with 2.2-SNAPSHOT?

To my surprise I couldn't reproduce it anymore with current 2.2-SNAPSHOT although I haven't fixed/committed anything related to this yet.

Member

BalusC commented Sep 22, 2015

Can you please retry with 2.2-SNAPSHOT?

To my surprise I couldn't reproduce it anymore with current 2.2-SNAPSHOT although I haven't fixed/committed anything related to this yet.

@jansohn

This comment has been minimized.

Show comment
Hide comment
@jansohn

jansohn Sep 23, 2015

I can still reproduce it with 2.2-SNAPSHOT

+= o.e.j.w.WebAppContext@14a65c6{/webapp,[file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/omnifaces-2.2-SNAPSHOT.jar!/META-INF/resources, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/javax.faces-2.2.12.jar!/META-INF/resources],UNAVAILABLE} - STARTED

jansohn commented Sep 23, 2015

I can still reproduce it with 2.2-SNAPSHOT

+= o.e.j.w.WebAppContext@14a65c6{/webapp,[file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/omnifaces-2.2-SNAPSHOT.jar!/META-INF/resources, jar:file:///C:/Users/test/git/jetty-omnifaces/target/testwebapp-1.0.0/WEB-INF/lib/javax.faces-2.2.12.jar!/META-INF/resources],UNAVAILABLE} - STARTED

BalusC added a commit that referenced this issue Sep 27, 2015

#166: Explicitly log any failures during contextInitialized.
It appears that e.g. Jetty swallows them.
@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 27, 2015

Member

It appears that Jetty swallows any exceptions thrown from ServletContextListener#contextInitialized(). I added logging to the ApplicationInitializer and I now got a clue:

org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.ApplicationScoped

Member

BalusC commented Sep 27, 2015

It appears that Jetty swallows any exceptions thrown from ServletContextListener#contextInitialized(). I added logging to the ApplicationInitializer and I now got a clue:

org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.ApplicationScoped

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 27, 2015

Member

Upon inspecting the logs, I noticed another clue:

INFO: WELD-ENV-001200: Jetty 7.2+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners should work on Jetty 9.1.1 and newer.

It says "should", not "must".

Member

BalusC commented Sep 27, 2015

Upon inspecting the logs, I noticed another clue:

INFO: WELD-ENV-001200: Jetty 7.2+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners should work on Jetty 9.1.1 and newer.

It says "should", not "must".

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 27, 2015

Member

Well, CDI is available, but @ApplicationScoped is simply not available in a ServletContextListener in Jetty. You'd best take up this with Jetty guys.

Best what we could do is to fail silently with only a WARNING log instead of blocking the deployment.

Member

BalusC commented Sep 27, 2015

Well, CDI is available, but @ApplicationScoped is simply not available in a ServletContextListener in Jetty. You'd best take up this with Jetty guys.

Best what we could do is to fail silently with only a WARNING log instead of blocking the deployment.

@BalusC BalusC closed this in 6154a31 Sep 27, 2015

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 27, 2015

Member

Your test works fine with today's 2.2-SNAPSHOT. You'll only see a WARNING being logged that eager application scope is not available (for some reason I'm seeing it logged 4 times instead of 1, but that's beyond my control).

Thank you for reporting and improving OmniFaces!

Member

BalusC commented Sep 27, 2015

Your test works fine with today's 2.2-SNAPSHOT. You'll only see a WARNING being logged that eager application scope is not available (for some reason I'm seeing it logged 4 times instead of 1, but that's beyond my control).

Thank you for reporting and improving OmniFaces!

@jansohn

This comment has been minimized.

Show comment
Hide comment
@jansohn

jansohn Sep 28, 2015

Unfortunately the test still fails for me? I get the warning you mention first

Sep 28, 2015 9:05:25 AM org.omnifaces.cdi.eager.EagerBeansRepository instantiateApplicationScopedAndRegisterListener
WARNUNG: Could not instantiate eager application scoped beans. Possibly the CDI application scope is not active. This is known to be the case in certain Tomcat and Jetty based configurations.

and afterwards

Sep 28, 2015 9:05:25 AM org.omnifaces.ApplicationListener contextInitialized
SCHWERWIEGEND: OmniFaces failed to initialize! Report an issue to OmniFaces.
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.ApplicationScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:689)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:124)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99)
at org.omnifaces.cdi.eager.EagerBeansRepository$Proxy$_$$_WeldClientProxy.hasAnySessionOrRequestScopedBeans(Unknown Source)
at org.omnifaces.cdi.eager.EagerBeansRepository.instantiateApplicationScopedAndRegisterListener(EagerBeansRepository.java:75)
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:62)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1368)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1335)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:735)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:511)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:405)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:372)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at webapp.BaseIntegrationTestClass.startJettyServer(BaseIntegrationTestClass.java:83)
at webapp.BaseIntegrationTestClass.setupClass(BaseIntegrationTestClass.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Using SNAPSHOT version omnifaces-2.2-20150927.153734-28.jar...

jansohn commented Sep 28, 2015

Unfortunately the test still fails for me? I get the warning you mention first

Sep 28, 2015 9:05:25 AM org.omnifaces.cdi.eager.EagerBeansRepository instantiateApplicationScopedAndRegisterListener
WARNUNG: Could not instantiate eager application scoped beans. Possibly the CDI application scope is not active. This is known to be the case in certain Tomcat and Jetty based configurations.

and afterwards

Sep 28, 2015 9:05:25 AM org.omnifaces.ApplicationListener contextInitialized
SCHWERWIEGEND: OmniFaces failed to initialize! Report an issue to OmniFaces.
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.ApplicationScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:689)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:124)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99)
at org.omnifaces.cdi.eager.EagerBeansRepository$Proxy$_$$_WeldClientProxy.hasAnySessionOrRequestScopedBeans(Unknown Source)
at org.omnifaces.cdi.eager.EagerBeansRepository.instantiateApplicationScopedAndRegisterListener(EagerBeansRepository.java:75)
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:62)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1368)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1335)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:735)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:511)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:405)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:372)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at webapp.BaseIntegrationTestClass.startJettyServer(BaseIntegrationTestClass.java:83)
at webapp.BaseIntegrationTestClass.setupClass(BaseIntegrationTestClass.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

Using SNAPSHOT version omnifaces-2.2-20150927.153734-28.jar...

BalusC added a commit that referenced this issue Sep 28, 2015

@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Sep 28, 2015

Member

Right, I spotted the mistake which I introduced afterwards. Can you retry with today's snapshot?

Member

BalusC commented Sep 28, 2015

Right, I spotted the mistake which I introduced afterwards. Can you retry with today's snapshot?

@jansohn

This comment has been minimized.

Show comment
Hide comment
@jansohn

jansohn Sep 28, 2015

Now the test case succeeds. Thank you very much!

jansohn commented Sep 28, 2015

Now the test case succeeds. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment