Skip to content

Comments

test: #900 - Add TCK tests to verify filter processing after upgrade#974

Open
omatheusmesmo wants to merge 7 commits intojakartaee:mainfrom
omatheusmesmo:test/900-filter-processing-after-upgrade
Open

test: #900 - Add TCK tests to verify filter processing after upgrade#974
omatheusmesmo wants to merge 7 commits intojakartaee:mainfrom
omatheusmesmo:test/900-filter-processing-after-upgrade

Conversation

@omatheusmesmo
Copy link

Problem

The Jakarta Servlet specification requires that Filters are processed after HttpServletRequest.upgrade() is called but before the HttpUpgradeHandler.init() method is invoked. Currently, there are insufficient TCK tests to verify this specific order of execution, leading to potential non-compliance in implementations.

Solution

This PR adds new TCK tests and modifies existing test artifacts to validate the correct execution order of filters during the upgrade process.

  • New Filter: Creates TestUpgradeFilter which sets response headers (X-Filter-Before-Upgrade, X-Filter-After-Upgrade) to prove filter invocation.
  • Handler Update: Modifies TCKHttpUpgradeHandler to capture and verify these filter headers during initialization.
  • Servlet Update: Updates TestServlet to pass the captured filter header values to the handler for verification.
  • Verification: Ensures that HttpUpgradeHandler.init() is called only after the filter chain has processed the request.

Related Issue

Fixes #900

Verification Results

  • Code follows project formatting (2-space indentation)
  • Commits follow Eclipse Foundation guidelines and Conventional Commits

Matheus Oliveira added 3 commits February 1, 2026 16:50
Creates TestUpgradeFilter to set response headers proving filter invocation.
This ensures that Filters are processed after HttpServletRequest.upgrade()
is called.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
…headers

Modifies TCKHttpUpgradeHandler to capture and verify filter headers.
Ensures that the handler can validate if the filter was invoked before
initialization.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
Updates TestServlet to pass filter header values to the handler.
This allows the handler to verify that the filter execution occurred
as expected during the upgrade process.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
@markt-asf
Copy link
Contributor

I feel I must be missing something obvious. Where is the validation that the header is set at the correct point? How/why does the test fail if it isn't?

Matheus Oliveira added 3 commits February 7, 2026 13:13
…atus

Updates TestUpgradeFilter to set a request attribute indicating it has
been invoked. This allows servlets to verify filter execution before
proceeding with protocol upgrades.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
Updates TestServlet to check for the filter invocation attribute before
executing the upgrade. Also adds support for verifying filters that only
process the request before the upgrade call.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
Enhances HttpUpgradeHandlerTests to include TestUpgradeFilter in the
deployment and verify that the filter was correctly processed during
the upgrade lifecycle.

Fixes jakartaee#900

Signed-off-by: Matheus Oliveira <hi@omatheusmesmo.dev>
@omatheusmesmo omatheusmesmo force-pushed the test/900-filter-processing-after-upgrade branch from 7eb1e08 to 73e33c2 Compare February 7, 2026 16:28
@omatheusmesmo
Copy link
Author

I feel I must be missing something obvious. Where is the validation that the header is set at the correct point? How/why does the test fail if it isn't?

@markt-asf Great catch! You're absolutely right that the validation needed to be more explicit. I've updated the implementation to make the Filter timing validation much tighter.

Here's how it now ensures the correct execution order:

The Validation Chain

  1. Filter → Sets state at both points
    Sets a request attribute and a header before chain.doFilter(), then another header after.

    httpResponse.setHeader("X-Filter-Before-Upgrade", "invoked");
    request.setAttribute("filter.invoked.before.upgrade", true);
    chain.doFilter(request, response);
    httpResponse.setHeader("X-Filter-After-Upgrade", "processed");
  2. Servlet → Guard & Fail Fast
    Explicitly checks for the attribute before calling request.upgrade().

    Boolean filterInvoked = (Boolean) request.getAttribute("filter.invoked.before.upgrade");
    if (filterInvoked == null || !filterInvoked) {
      response.sendError(500, "Filter was not invoked before upgrade");
      return; // Test fails here ✗
    }
  3. Test → Assertion
    The test now looks for the specific output from the handler that confirms the Filter's header was captured:

    String EXPECTED_RESPONSE4 = "Filter-Header: invoked";
    // ...
    if (!passed4) {
      throw new Exception("Test Failed. Filter was not processed correctly before upgrade.");
    }

Why It Fails if Timing is Wrong

What Goes Wrong Where It Fails Outcome
Filter not registered TestServlet HTTP 500 (Upgrade never happens)
Filter runs after upgrade TestServlet Attribute is null -> HTTP 500
Header not captured Handler No "Filter-Header" output -> passed4 is false

Local Verification (Curl)

Running it manually shows the exact sequence:

$ curl -v -X POST http://localhost:8080/test-upgrade/TestServlet \
  -H "Upgrade: YES" -H "Connection: Upgrade" --data "Hello"

< HTTP/1.1 101 
< X-Filter-Before-Upgrade: invoked   ✓ Proves Filter ran BEFORE Servlet
< Upgrade: YES
< X-Filter-After-Upgrade: processed  ✓ Proves Filter wrapped the call
...
===============TCKHttpUpgradeHandler.init
===============Filter-Header: invoked  ✓ Validation passed!

The combination of the Servlet guard and the Handler's output for the TCK assertion ensures we are validating the "correct point" as requested.

Does this address your concerns?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TCK should have additional tests for httpupgradehandler to ensure that Filters are processed after calling upgrade()

2 participants