tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Ploski <>
Subject Altering the request URI in a filter through HttpServletRequestWrapper
Date Wed, 22 Jan 2003 21:04:19 GMT

I would like to alter the request URI in my ServletFilter to intercept
requests to resources that should only be available to logged in users.

I have found a solution in the archive:

which basically suggests to terminate the doFilter method with

request.getRequestDispatcher(/* where to */).forward(request, response);

and don't invoke chain.doFilter as the last step.

It seems to me that it should not be done this way -- what if there
are other legitimate filters that should process the request?
Also, I am not sure about the semantics of calling "forward" from
"doFilter" -- is it officially supported or maybe a "grey area" of
the spec, and it works just by chance?

Anyway, I thought that I could achieve the same by using
a HttpServletRequestWrapper, like below:

    request = new HttpServletRequestWrapper(request) {
        public String getRequestURI() {
            return "/solonline/page/nosession.jsp"; }
        public StringBuffer getRequestURL() {
            return new StringBuffer(
                ""); }
        public String getServletPath() {
            return "/page/nosession.jsp"; }

    chain.doFilter(request, response);

Unfortunately, the result is an error page:

HTTP Status 400 - Invalid path /page/nosession was requested

type Status report

message Invalid path /page/nosession was requested

description The request sent by the client was syntactically incorrect
(Invalid path /page/nosession was requested).

Note the ".jsp" stripped from my URI in this error message (?)

I am using Apache Tomcat/4.1.18-LE-jdk14.

Can someone explain why it does not work as expected? So far I have
not found a single example of HttpServletRequestWrapper's usage.

Best regards -
Jan Ploski

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message