tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Altering the request URI in a filter through HttpServletRequestWrapper
Date Thu, 23 Jan 2003 06:24:26 GMT


On Wed, 22 Jan 2003, Bill Barker wrote:

> Date: Wed, 22 Jan 2003 22:27:54 -0800
> From: Bill Barker <wbarker@wilshire.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Altering the request URI in a filter through
>     HttpServletRequestWrapper
>
> I haven't looked to see why you are getting this particular error message,
> but the basic idea shouldn't work.  Before your Filters are invoked, Tomcat
> has already decided on which Servlet should handle the request at the end of
> the pipeline.  Changing the requestURI and servletPath at this stage
> shouldn't change the mapping.
>

That's correct -- if you want your filter to change which servlet is
actually invoked, using a RequestDispatcher.forward() is the way to go.

Craig


> "Jan Ploski" <jpljpl@gmx.de> wrote in message
> news:13799530.1043269459692.JavaMail.jpl@remotejava...
> > Hello,
> >
> > 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:
> >
> > http://www.mail-archive.com/tomcat-user@jakarta.apache.org/msg64446.html
> >
> > 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(
> >                 "http://192.168.0.1:6080/solonline/page/nosession.jsp"); }
> >         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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message