how do you underploy/redeploy? this catch just hides a real issue if
it is undeployed/deployed normally I think


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-09-23 14:32 GMT+02:00 Berner Martin <[email protected]>:
> Hi Romain
> Just downloaded the Trunc. No news since Revision 1620375 which is fixing the 
> NPE when webcontext isn't present at startup of a deployed Webapplication. 
> But If you undeploy and redeploy ore even newly deploy  such a Webapplication 
> on a running TomEE I get the NPE shown in my fist post. I simply catch this 
> and return null so on third time I Pass the code (stop) @ starting up ??? the 
> bean can be referenced and it works the same as it was "cold deployed" or 
> starting with already deployed App.
>
> It's with a tomee 1.7.1 (JAX-RS) not en embedded one.
>
> Martin
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Romain Manni-Bucau [mailto:[email protected]]
> Gesendet: Dienstag, 23. September 2014 13:55
> An: [email protected]
> Betreff: Re: LazyRealm and CDI dosent work correctly under 1.7.1
>
>> Is it Possible to let this fix get into trunk? Or some other solution of the 
>> Problem? Maybe by analysing LifecycleState?
>>
>
> Isn't it already the case?
>
> In which context do you get it? normal tomee or embedded
>
>> Best Regards
>> Berner Martin
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Berner Martin [mailto:[email protected]]
>> Gesendet: Montag, 22. September 2014 10:51
>> An: [email protected]
>> Betreff: LazyRealm and CDI dosent work correctly under 1.7.1
>>
>> Hi,
>> Don't know if this is a Bug und if, where to place.
>> I Use the LazyRealm with CDI to use a Realm from the CDI context of the 
>> Application.
>> Romain made a Fix to the LazyRealm to address the Situation, where CDI 
>> context isn't present at startup. (thanks @Romain) Now it's possible to 
>> start a TomEE with App deployed. Starting up works correct.
>> I'm a bit surprised that I reach the "instanc" Function of LazyRealm tree 
>> times.
>>
>> First time:
>> LazyRealm.instance() line: 106
>> LazyRealm.initInternal() line: 134
>> LazyRealm(LifecycleBase).init() line: 102
>> LazyRealm(LifecycleBase).start() line: 139
>>
>> è WebBeansContext is Null
>>
>> Second time:
>> LazyRealm.instance() line: 106
>> LazyRealm.startInternal() line: 142
>> LazyRealm(LifecycleBase).start() line: 150
>>
>> è WebBeansContext still Null
>>
>> third time:
>> LazyRealm.instance() line: 106
>> LazyRealm.stopInternal() line: 150
>> LazyRealm(LifecycleBase).stop() line: 232
>>
>> è WebBeansContext isn't null and bm.getReference returns the correct Bean 
>> from CDI context.
>>
>>
>> But When TomEE is running and I deploy my webapp then  webBeansContext is 
>> not null at first time. Problem is, that bm.getRefereance throws a 
>> NullPointerException than:
>> org.apache.catalina.LifecycleException: Failed to start component 
>> [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/MSheepWeb]]
>>         at 
>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
>>         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:649)
>>         at 
>> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
>>         at 
>> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:553)
>>         at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1671)
>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>         at 
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>         at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>         at java.lang.reflect.Method.invoke(Method.java:606)
>>         at 
>> org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
>>         at 
>> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
>>         at 
>> com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
>>         at 
>> org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1485)
>>         at 
>> org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:286)
>>         at 
>> org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:206)
>>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
>>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>>         at 
>> org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>>         at 
>> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>>         at 
>> org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>>         at 
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>>         at 
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
>>         at 
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
>>         at 
>> org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
>>         at 
>> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
>>         at 
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
>>         at 
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
>>         at 
>> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
>>         at 
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
>>         at 
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
>>         at 
>> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
>>         at 
>> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
>>         at 
>> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
>>         at 
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>>         at 
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>>         at 
>> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>>         at java.lang.Thread.run(Thread.java:745)
>> Caused by: org.apache.catalina.LifecycleException: Failed to initialize 
>> component [org.apache.tomee.catalina.realm.LazyRealm@3f6b9abb]
>>         at 
>> org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
>>         at 
>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
>>         at 
>> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5373)
>>         at 
>> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
>>         ... 45 more
>> Caused by: java.lang.NullPointerException: bean parameter can not be null
>>         at org.apache.webbeans.util.Asserts.assertNotNull(Asserts.java:50)
>>         at 
>> org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:682)
>>         at 
>> org.apache.tomee.catalina.realm.LazyRealm.instance(LazyRealm.java:114)
>>         at 
>> org.apache.tomee.catalina.realm.LazyRealm.initInternal(LazyRealm.java:134)
>>         at 
>> org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
>>         ... 48 more
>>
>> I compile my Own LazyRealm simple catch the NPE from bm.getReference and 
>> returning null witch solves the Problem for the Moment:
>>
>>                     } else {
>>                         final WebBeansContext webBeansContext = 
>> WebBeansContext.currentInstance();
>>                         if (webBeansContext == null) {
>>                             return null; // too early to have a cdi bean, 
>> skip these methods - mainly init() but @PostConstruct works then
>>                         }
>>                         final BeanManager bm = 
>> webBeansContext.getBeanManagerImpl();
>>                         final Set<Bean<?>> beans = bm.getBeans(clazz);
>>                         final Bean<?> bean = bm.resolve(beans);
>>                         creationalContext = bm.createCreationalContext(null);
>>                         try {
>>                            instance = bm.getReference(bean, clazz, 
>> creationalContext);
>>                         } catch (NullPointerException npe) {
>>                            return null;
>>                         }
>>                     }
>>
>>
>> Best Regards
>> Martin Berner

Reply via email to