Bug 66533 - Wrapping Requests or Responses in Valves is not possible
Summary: Wrapping Requests or Responses in Valves is not possible
Status: NEW
Alias: None
Product: Tomcat 11
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: -------
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2023-03-17 16:32 UTC by Wolfgang Illmeyer
Modified: 2023-03-17 17:15 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Illmeyer 2023-03-17 16:32:59 UTC
The javadoc of org.apache.catalina.Valve.invoke(Request, Response) states:

> An individual Valve MAY perform the following actions, in the specified order:
> […]
> Examine the properties of the specified Request and Response, wrap either or
> both of these objects to supplement their functionality, and pass them on.

Due to the fact that that said method receives org.apache.catalina.connector.Request and org.apache.catalina.connector.Response, neither of which are interfaces, i don't see how it would be possible to actually wrap either request or response (at least without the developer resorting to ugly black-magic-type measures).

In fact, the argument classes implement HttpServletRequest and HttpServletResponse, respectively, which would be much better suited for creating wrappers (indeed javax.servlet.http.HttpServletRequestWrapper and so on already exist)

I therefore suggest that, with Tomcat 11, the time has finally come to stop mocking developers trying to implement actual functionality in Valves and change the signature of Valve.invoke() to something like:

void invoke(HttpServletRequest, HttpServletResponse)

If I'm missing something from the Request and Response classes, that is currently needed by the included Valves, maybe it could be passed as a third argument of some new type ValveContext or similar. Another possibility would be to extend HttpServletRequest and HttpServletResponse for those purposes, use the resulting interfaces as argument types for the invoke() method and also provide corresponding wrapper base classes.
Comment 1 Mark Thomas 2023-03-17 17:15:29 UTC
See bug 45014

I suspect that this request will get closed for the same reason. Tomcat's internal architecture hasn't changed that much since that bug.