[ 
https://issues.apache.org/jira/browse/KARAF-7773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17777134#comment-17777134
 ] 

Amichai Rothman commented on KARAF-7773:
----------------------------------------

I didn't dive deep into the tests, but I don't see the rather complex case of a 
context listener being defined in a 'conflicting' wab which manipulates the 
ServletContext (e.g. adding a filter), and then making sure the other 
'conflicting' context does't accidentally also invoke the listener when it 
takes over, which would result in the filter from the first app being applied 
to the second unrealted one (which is what I'm seeing).

btw is there any other specific info you'd like me to hunt for while I'm 
debugging to help you understand what exactly is going on?

> WAB ServletContextListener.contextInitialized invoked multiple times during 
> re-deploy (and with wrong context)
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: KARAF-7773
>                 URL: https://issues.apache.org/jira/browse/KARAF-7773
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf
>    Affects Versions: 4.4.3
>            Reporter: Amichai Rothman
>            Assignee: Grzegorz Grzybek
>            Priority: Major
>         Attachments: paxweb.log
>
>
> When touching a WAB bundle with a context listener as described belower, the 
> undeploy/deploy cycle, instead of just invoking destroy on the old context 
> and initialize on the new one, seems to destroy the old one, re-initialize 
> the old one (with the wrong "whiteboard extender" context), destroy it again, 
> initialize the new one (with correct context), and initialize the old one 
> once more (but without the filter init).
> I'll describe my full scenario, even though it's possible the issue can be 
> reproduced with a simpler setup:
> I have an application consisting of multiple bundles in the karaf deploy 
> folder. One of them is a WAB. It's web.xml only contains display-name and 
> listener-class with a ServletContextListener. The listener contextInitialized 
> implementation instantiates a custom Filter, whose class is imported from a 
> different app bundle:
> {code:java}
> Filter filter = new MyFilter();
> context.addFilter("MyFilter", filter)
>     .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, 
> DispatcherType.FORWARD), true, "/*");
> {code}
> The filter's init method is invoked successfully and all is good.
> Then, I update/touch the WAB bundle in the deploy folder.
> This causes a thread named "paxweb-config-3-thread-1 (undeploy /)" to call 
> the listener's  contextDestroyed method as expected, but then it also 
> immediately calls the contextInitialized method again (still from the 
> undeploy thread, and still the same old listener instance), this time with 
> the servlet context of the pax-web-extender-whiteboard rather than the WAB 
> bundle. It creates another filter instance, whose init method gets invoked 
> with the pax-web-extender-whiteboard context as well (my init implementation 
> throws an exception at this point when the context is wrong, resources aren't 
> found etc.).
> Then a thread named "paxweb-config-3-thread-1 (deploy /)" (notice undeploy 
> changed to deploy) calls contextDestroyed, still with the extender context. 
> Finally, a new listener instance is craeted, contextInitialized is invoked 
> again, this time with the correct WAB context, followed by the filter's init 
> method. In addition, the old listener instance (which should be dead by now) 
> contextInitialized also gets invoked again, but not followed by the filter 
> init (maybe because it previously threw an exception on it? just guessing).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to