You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Expand the attached zip file.
Build and run the project which contains a class that implements both ContainerRequestFilter and ContainerResponseFilter.
curl http://localhost:8080/greet. Both filter methods log a message.
curl http://localhost:8080/metrics. The request succeeds but only the response filter is invoked.
curl http://localhost:8080/bad. The request fails with the expected 404; only the response filter is invoked.
@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).
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).
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.
Environment Details
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
ContainerRequestFilter
andContainerResponseFilter
.curl http://localhost:8080/greet
. Both filter methods log a message.curl http://localhost:8080/metrics
. The request succeeds but only the response filter is invoked.curl http://localhost:8080/bad
. The request fails with the expected 404; only the response filter is invoked.MPFilterExample.zip
The text was updated successfully, but these errors were encountered: