Jetty
  1. Jetty
  2. JETTY-72

Filters are initialized in wrong order

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      jetty 6.0.0beta17
    • Number of attachments :
      0

      Description

      For a configuration like the following in web.xml :

        <filter>
            <filter-name>myFirstFilter</filter-name>
            <filter-class>com.acme.MyFirstFilter</filter-class>
        </filter>
        <filter>
            <filter-name>mySecondFilter</filter-name>
            <filter-class>com.acme.MySecondFilter</filter-class>
        </filter>
      

      the init methods are called in this order :

      • MySecondFilter.init( FilterConfig filterConfig )
      • MyFirstFilter.init( FilterConfig filterConfig )

      instead of :

      • MyFirstFilter.init( FilterConfig filterConfig )
      • MySecondFilter.init( FilterConfig filterConfig )

        Activity

        Hide
        Tim Vernum added a comment -

        The servlet specification does not define an order for filters to be initialised.
        The only requirement is that the init method be called before the doFilter method is called.

        Jetty currently initialises filters in the reverse order to which they are declared.

        This behaviour may not be desired (and I'm not sure it really makes much sense), but it is not "wrong" according to the spec.

        Any application that relies on the order of filter initialisation is not portable between containers.

        Show
        Tim Vernum added a comment - The servlet specification does not define an order for filters to be initialised. The only requirement is that the init method be called before the doFilter method is called. Jetty currently initialises filters in the reverse order to which they are declared. This behaviour may not be desired (and I'm not sure it really makes much sense), but it is not "wrong" according to the spec. Any application that relies on the order of filter initialisation is not portable between containers.
        Hide
        Emmanuel Venisse added a comment -

        I thought it was in the spec.

        In my app, I checked in the latest filter if all others was loaded so I can verify if web.xml contains all parts required by my app.

        I can certainly do it in an other way.

        Show
        Emmanuel Venisse added a comment - I thought it was in the spec. In my app, I checked in the latest filter if all others was loaded so I can verify if web.xml contains all parts required by my app. I can certainly do it in an other way.
        Hide
        Greg Wilkins added a comment -

        While it may or may not be in the spec.... I see no harm in conforming.
        So I have fixed the order to be the same as the declaration order

        Show
        Greg Wilkins added a comment - While it may or may not be in the spec.... I see no harm in conforming. So I have fixed the order to be the same as the declaration order
        Hide
        Emmanuel Venisse added a comment -

        Thanks Greg

        Show
        Emmanuel Venisse added a comment - Thanks Greg

          People

          • Assignee:
            Unassigned
            Reporter:
            Emmanuel Venisse
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: