tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Delbecq <>
Subject Re: How to inject a webapp listener?
Date Sun, 01 Jul 2007 12:46:07 GMT
Am not sure, but, whatever job your injected contextlistener is supposed
to do, it could perhaps be done in the container listener without
ressorting to context listener, isn't it? (using ADD_CHILD for the
'context initialized' and REMOVE_CHILD for contect destroyed)?
As for calling init on your injected listern, is suppose you will have
to do it yourself.

Juha Laiho a écrit :
> Hello,
> I would like to have the Tomcat container to inject a specific
> ServletContextListener to each loaded webapp on my server - without
> touching the individual web.xml files, and am looking for advise on
> how to achieve this.
> In other words, I'd like to have the container act as if there was
> <listener>
>  <listener-class>MyListenerClass</listener-class>
> </listener>
> section in the web.xml file for each application?
> Currently, I have added a ContainerListener on my Host, which
> is listening on ADD_CHILD messages to discover newly added
> StandardContext instances, and performs the following on each
> new StandardContext (where ctx is a reference to the added context):
>  Object[] listeners = ctx.getApplicationLifecycleListeners();
>  Object[] newListeners = new Object[listeners.length+1];
>  System.arraycopy(listeners,0,newListeners,0,listeners.length);
>  newListeners[newListeners.length-1]=ctxListener;
>  ctx.setApplicationLifecycleListeners(newListeners);
> With this, my listener is already able to capture the contextDestroyed
> events from the webapp - but not the contextInitialized. It looks like
> the
> Context is added to the host only after it has been already initialized.
> What I'm looking for is a way to be able to inject the webapp listener
> in an earlier phase, so that I can also capture the contextInitialized
> messages. Any ideas? Also, if there's an overall better way to inject
> the webapp listener, please let me know -- the above way feels rather
> crude.
> Thanks,

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message