You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ke...@chase.com on 2008/11/13 16:35:36 UTC

Filter Init order

Is there a guaranteed way to specify the order that filters get initialized?

Running Tomcat 6.0.14 (on windows right now for testing)
I have also used servlet 2.3 and 2.5 declarations in web.xml
I have 5 filters defined.
- 2 are custom
- 3 are out of the box (SiteMesh, Struts2, Struts2Cleanup)

I need for my 2 custom filters to init first and in a particular order.

I have moved the order of their declaration around in web.xml with frustrating results.
Struts2 filter always inits first (no matter what order its specified in web.xml) and then my custom filters seem to init in reverse order from what is specified in web.xml.

Thanks,
Ken


-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
 If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

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


RE: Filter Init order

Posted by Ke...@chase.com.
Chris,

Thanks for the reply.

I upgraded to tomcat 6.0.16 and peeked at the source.
It appears that the filter elements are being returned from the web.xml in the order they were defined.
They are then placed into a HashMap (which of course has no reliable ordering).
That is where mis-ordering happens.

So I think in the short term I may patch it real quick to provide a LinkedHashMap for the filterDef.
Then long term I think we're gonna look to find something else to do initializations. Thinking that perhaps
a listener (since they, according to the tomcat code, are started before the filters) would be a good place to do most
of the the inits and remove any order-dependencies in the individual filters.

Thanks to all for the replies, I think we can consider the issue resolved.

-ken

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net]
Sent: Thursday, November 13, 2008 12:26 PM
To: Tomcat Users List
Subject: Re: Filter Init order


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ken,

Kenneth.S.Brooks@chase.com wrote:

> However, I can even remove the mapping and just leave the filter declaration and the inits still happen.

The servlet specification doesn't say anything about the ordering of
init calls to filters... only that they are guaranteed to be called
before a request that needs that filter is processed.

This leaves it up to the container implementors to decide what order to
use. Top-down in the deployment descriptor (web.xml) would be a
reasonable expectation, but it is by no means the standard.

If you have filters that depend on each other, you might want to
implement a lazy initialization strategy that actually delays
initialization until after init() has been called on each of the filters.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkcYyQACgkQ9CaO5/Lv0PBVegCfRw0PCZHjAzFbPfWyHdZyn5Vz
XSIAn2exuvviBPbZxWOap7M9U+Ihso/d
=x/k3
-----END PGP SIGNATURE-----

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




-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
 If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

Re: Filter Init order

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ken,

Kenneth.S.Brooks@chase.com wrote:

> However, I can even remove the mapping and just leave the filter declaration and the inits still happen.

The servlet specification doesn't say anything about the ordering of
init calls to filters... only that they are guaranteed to be called
before a request that needs that filter is processed.

This leaves it up to the container implementors to decide what order to
use. Top-down in the deployment descriptor (web.xml) would be a
reasonable expectation, but it is by no means the standard.

If you have filters that depend on each other, you might want to
implement a lazy initialization strategy that actually delays
initialization until after init() has been called on each of the filters.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkcYyQACgkQ9CaO5/Lv0PBVegCfRw0PCZHjAzFbPfWyHdZyn5Vz
XSIAn2exuvviBPbZxWOap7M9U+Ihso/d
=x/k3
-----END PGP SIGNATURE-----

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


RE: Filter Init order

Posted by Ke...@chase.com.
Yes.

However, I can even remove the mapping and just leave the filter declaration and the inits still happen.
So that leads me to believe that the mapping has no bearing on the inits.

Thanks for the suggestion tho. I'll give it another try just to make sure I wasn't sleeping at the wheel last time.

-ken

-----Original Message-----
From: Arash Bizhan zadeh [mailto:arashbi@gmail.com]
Sent: Thursday, November 13, 2008 10:40 AM
To: Tomcat Users List
Subject: Re: Filter Init order


On Thu, Nov 13, 2008 at 10:35 AM, <Ke...@chase.com> wrote:

> Is there a guaranteed way to specify the order that filters get
> initialized?
>
> Running Tomcat 6.0.14 (on windows right now for testing)
> I have also used servlet 2.3 and 2.5 declarations in web.xml
> I have 5 filters defined.
> - 2 are custom
> - 3 are out of the box (SiteMesh, Struts2, Struts2Cleanup)
>
> I need for my 2 custom filters to init first and in a particular order.
>
> I have moved the order of their declaration around in web.xml with
> frustrating results.
> Struts2 filter always inits first (no matter what order its specified in
> web.xml) and then my custom filters seem to init in reverse order from what
> is specified in web.xml.


Did you also rearranged their mapping configuration in web.xml?

>
>
> Thanks,
> Ken
>
>
> -----------------------------------------
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law.  If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED.  Although this transmission and
> any attachments are believed to be free of any virus or other
> defect that might affect any computer system into which it is
> received and opened, it is the responsibility of the recipient to
> ensure that it is virus free and no responsibility is accepted by
> JPMorgan Chase & Co., its subsidiaries and affiliates, as
> applicable, for any loss or damage arising in any way from its use.
>  If you received this transmission in error, please immediately
> contact the sender and destroy the material in its entirety,
> whether in electronic or hard copy format. Thank you.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
The dirtiest book of all is the expurgated book.
----
Walt Whitman


-----------------------------------------
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
 If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

Re: Filter Init order

Posted by Arash Bizhan zadeh <ar...@gmail.com>.
On Thu, Nov 13, 2008 at 10:35 AM, <Ke...@chase.com> wrote:

> Is there a guaranteed way to specify the order that filters get
> initialized?
>
> Running Tomcat 6.0.14 (on windows right now for testing)
> I have also used servlet 2.3 and 2.5 declarations in web.xml
> I have 5 filters defined.
> - 2 are custom
> - 3 are out of the box (SiteMesh, Struts2, Struts2Cleanup)
>
> I need for my 2 custom filters to init first and in a particular order.
>
> I have moved the order of their declaration around in web.xml with
> frustrating results.
> Struts2 filter always inits first (no matter what order its specified in
> web.xml) and then my custom filters seem to init in reverse order from what
> is specified in web.xml.


Did you also rearranged their mapping configuration in web.xml?

>
>
> Thanks,
> Ken
>
>
> -----------------------------------------
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law.  If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED.  Although this transmission and
> any attachments are believed to be free of any virus or other
> defect that might affect any computer system into which it is
> received and opened, it is the responsibility of the recipient to
> ensure that it is virus free and no responsibility is accepted by
> JPMorgan Chase & Co., its subsidiaries and affiliates, as
> applicable, for any loss or damage arising in any way from its use.
>  If you received this transmission in error, please immediately
> contact the sender and destroy the material in its entirety,
> whether in electronic or hard copy format. Thank you.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
The dirtiest book of all is the expurgated book.
----
Walt Whitman