You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rob Gregory <Ro...@ibsolutions.com> on 2010/11/24 16:38:14 UTC

Starup Order [Filters --> Servlets --> Context]

Hi Guys,

 

Am I correct in my assumption that servlet filters are started before
servlets and that the context listeners are not fired until both the
filters and servlets have been initialised? What I am trying to do is
run some code before the context is started which is actually going to
copy a mycontext.xml into another mysecondcontext.xml (using
docBase="single_webapp_location"). which would then get auto deployed
into Tomcat creating the 2nd context. As part of this process I also
need to copy some files from a 'location' into the docBase and suspect
that this will cause Tomcat to reload both contexts. Is there any entry
point during Tomcat startup where I can do some work before either
contexts are started? 

 

Tomcat is 6.0.29 under JDK 1.6

 

Thanks for any assistance. 

Rob

 


Re: Starup Order [Filters --> Servlets --> Context]

Posted by Pid <pi...@pidster.com>.
On 24/11/2010 17:15, Rob Gregory wrote:
> Thanks Pid, see my comment below:-
> 
>> -----Original Message-----
>> From: Pid [mailto:pid@pidster.com]
>> Sent: 24 November 2010 17:05
>> To: Tomcat Users List
>> Subject: Re: Starup Order [Filters --> Servlets --> Context]
>>
>> On 24/11/2010 15:38, Rob Gregory wrote:
>>> Hi Guys,
>>>
>>> Am I correct in my assumption that servlet filters are started
> before
>>> servlets and that the context listeners are not fired until both the
>>> filters and servlets have been initialised?
>>
>> ServletContextListeners first, before Filters & Servlets.
> 
> Ah, I was confusing the events being fired to the actual initialisation
> of the ServletContextListeners.
> 
>>> What I am trying to do is
>>> run some code before the context is started which is actually going
> to
>>> copy a mycontext.xml into another mysecondcontext.xml (using
>>> docBase="single_webapp_location"). which would then get auto
> deployed
>>> into Tomcat creating the 2nd context.
>>
>> I'm not sure that's such a good idea.
> 
> Is there a specific reason why not? How is doing this any different to
> manually creating the two context.xml files if I can create them before
> the contexts are initialised?

The deployment cycle is single threaded, the SCLs execute sequentially
in order of definition in each application.

If the SCL throws an uncaught exception, then the app won't start up at all.

Does it need to happen in an SCL?


>>> As part of this process I also
>>> need to copy some files from a 'location' into the docBase and
> suspect
>>> that this will cause Tomcat to reload both contexts.
>>
>> Depends how you're configured.  It might.
> 
> I have a number of watched resources so I think it will unless I can
> copy the files before the contexts are initialised.

If you're watching the file that gets copied, then yes, it'll cause a
redeployment of app1, & consequently of app2.

Are you watching that file?


p


>>> Is there any entry point during Tomcat startup where I can do some
>>> work before either contexts are started?
>>
>> LifecycleListener?
>> Look for examples at the beginning of server.xml.
> 
> Thanks for the pointer Pid. Most helpful. 
> 
>>
>>
>> p
>>
>>> Tomcat is 6.0.29 under JDK 1.6
>>>
>>>
>>>
>>> Thanks for any assistance.
>>>
>>> Rob
>>>
>>>
>>>
>>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


RE: Starup Order [Filters --> Servlets --> Context]

Posted by Rob Gregory <Ro...@ibsolutions.com>.
Thanks Pid, see my comment below:-

> -----Original Message-----
> From: Pid [mailto:pid@pidster.com]
> Sent: 24 November 2010 17:05
> To: Tomcat Users List
> Subject: Re: Starup Order [Filters --> Servlets --> Context]
> 
> On 24/11/2010 15:38, Rob Gregory wrote:
> > Hi Guys,
> >
> >
> >
> > Am I correct in my assumption that servlet filters are started
before
> > servlets and that the context listeners are not fired until both the
> > filters and servlets have been initialised?
> 
> ServletContextListeners first, before Filters & Servlets.

Ah, I was confusing the events being fired to the actual initialisation
of the ServletContextListeners.

> 
> 
> > What I am trying to do is
> > run some code before the context is started which is actually going
to
> > copy a mycontext.xml into another mysecondcontext.xml (using
> > docBase="single_webapp_location"). which would then get auto
deployed
> > into Tomcat creating the 2nd context.
> 
> I'm not sure that's such a good idea.

Is there a specific reason why not? How is doing this any different to
manually creating the two context.xml files if I can create them before
the contexts are initialised?

> 
> > As part of this process I also
> > need to copy some files from a 'location' into the docBase and
suspect
> > that this will cause Tomcat to reload both contexts.
> 
> Depends how you're configured.  It might.

I have a number of watched resources so I think it will unless I can
copy the files before the contexts are initialised.

> 
> > Is there any entry point during Tomcat startup where I can do some
> > work before either contexts are started?
> 
> LifecycleListener?
> Look for examples at the beginning of server.xml.

Thanks for the pointer Pid. Most helpful. 

> 
> 
> p
> 
> > Tomcat is 6.0.29 under JDK 1.6
> >
> >
> >
> > Thanks for any assistance.
> >
> > Rob
> >
> >
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Starup Order [Filters --> Servlets --> Context]

Posted by Pid <pi...@pidster.com>.
On 24/11/2010 15:38, Rob Gregory wrote:
> Hi Guys,
> 
>  
> 
> Am I correct in my assumption that servlet filters are started before
> servlets and that the context listeners are not fired until both the
> filters and servlets have been initialised?

ServletContextListeners first, before Filters & Servlets.


> What I am trying to do is
> run some code before the context is started which is actually going to
> copy a mycontext.xml into another mysecondcontext.xml (using
> docBase="single_webapp_location"). which would then get auto deployed
> into Tomcat creating the 2nd context. 

I'm not sure that's such a good idea.

> As part of this process I also
> need to copy some files from a 'location' into the docBase and suspect
> that this will cause Tomcat to reload both contexts. 

Depends how you're configured.  It might.

> Is there any entry point during Tomcat startup where I can do some work before either
> contexts are started? 

LifecycleListener?
Look for examples at the beginning of server.xml.


p

> Tomcat is 6.0.29 under JDK 1.6
> 
>  
> 
> Thanks for any assistance. 
> 
> Rob
> 
>  
> 
>