Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request filter is skipped for Helidon-provided endpoints and non-existent endpoints; response filter is invoked for all #9445

Open
tjquinno opened this issue Oct 29, 2024 · 1 comment
Assignees
Labels
4.x Version 4.x bug Something isn't working MP webserver

Comments

@tjquinno
Copy link
Member

Environment Details

  • Helidon Version: 4.x
  • Helidon SE or Helidon MP MP
  • JDK version:
  • OS:
  • Docker version (if applicable):

Problem Description

In an MP app, a request filter is skipped for Helidon-provided endpoints such as /metrics, /health, and /openapi. It is also skipped for non-existent endpoints.

A response filter, on the other hand, is invoked for all of the above.

Steps to reproduce

  1. Expand the attached zip file.
  2. Build and run the project which contains a class that implements both ContainerRequestFilter and ContainerResponseFilter.
  3. curl http://localhost:8080/greet. Both filter methods log a message.
  4. curl http://localhost:8080/metrics. The request succeeds but only the response filter is invoked.
  5. curl http://localhost:8080/bad. The request fails with the expected 404; only the response filter is invoked.

MPFilterExample.zip

@tjquinno tjquinno added bug Something isn't working MP webserver 4.x Version 4.x labels Oct 29, 2024
@spericas
Copy link
Member

@tjquinno This is working as designed once the Helidon integration with Jakarta REST is understood. The CustomFilter is a global filter because it has no name binding annotations. All global filters need to be invoked according to the Jakarta REST spec (this enables some filters, for example, to convert a 404 to a 200 if necessary).

  1. curl http://localhost:8080/metrics calls the response filter because /metrics is first tried with Jersey and then with the Helidon WebServer. The status code in the filter will be 404. Once the 404 is processed by the Helidon WebServer, the actual endpoint is found and called (converting the 404 to a 200).
  2. curl http://localhost:8080/bad calls the response filter for the same reason described in (1). However, since /bad is unknown to the WebServer, the result is still a 404.

The existing behavior in (1) and (2) can be altered by name binding the filter with the resource in question (or registering it manually to avoid making it global). That filter will never be called if the resource is not found. See Name Binding.

Could the Helidon WebServer avoid calling '/metrics' when it recognizes the endpoint as valid? This is a question for @tomas-langer: seems like the current approach is to always try Jersey first and the WebServer second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working MP webserver
Projects
Status: Normal priority
Development

No branches or pull requests

2 participants