Filter's doFilter() method is getting invoked before servlet's init()

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7.0.0
    • 7.1.0

Issue

In JBoss Web (EAP 6), the code is executed in the following order at the first request.

  1. Filter.init()
  2. Servet.init()
  3. Filter.doFilter()
  4. Servlet.service()

While on Undertow (EAP 7) the order is as follows.

  1. Filter.init()
  2. Filter.doFilter()
  3. Servet.init()
  4. Servlet.service()

Resolution

Upgrade to the future version of EAP, provably 7.2.0 as of July 2017.

Root Cause

Both behaviours are compliant to the servlet specification but an effort has been implemented1 in the upstream to align the behaviour.

Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.