google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

invalid getRequestURL() after getRequestDispatcher().forward( ... ) #413

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have a filter like so:

public class F implements Filter {
 // ...
 public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
 {
   request.getRequestDispatcher("/foo/bar.txt").forward(request, response);
 }
}

Then this servlet:

public class S extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
  {
     final PrintWriter out = response.getWriter();
     out.println("Hello from " + request.getRequestURL());
  }
}

If this is configured through web.xml like so:

 <filter>
   <filter-name>f</filter-name>
   <filter-class>guice.test.F</filter-class>
 </filter>
 <filter-mapping>
   <filter-name>f</filter-name>
   <url-pattern>/bug</url-pattern>
 </filter-mapping>

 <servlet>
   <servlet-name>s</servlet-name>
   <servlet-class>guice.test.S</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>s</servlet-name>
   <url-pattern>*.txt</url-pattern>
 </servlet-mapping>

When I request http://localhost:8080/guice.test/bug, I get:

 Hello from http://localhost:8080/guice.test/foo/bar.txt

If I configure the same thing through guiceFilter, I get

 Hello from http://localhost:8080/guice.test/bug

That is incorrect, see
http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http
/HttpServletRequest.html#getRequestURL()

In particular:

If this request has been forwarded using
RequestDispatcher.forward(javax.servlet.ServletRequest,
javax.servlet.ServletResponse), the server path in the reconstructed URL
must reflect the path used to obtain the RequestDispatcher, and not the
server path specified by the client.

Can you fix this? Or tell me where to fix it... ?

Original issue reported on code.google.com by jelleher...@gmail.com on 14 Aug 2009 at 4:21

GoogleCodeExporter commented 9 years ago
While trying to fix this, I see this is already fixed in r1015

http://code.google.com/p/google-guice/source/browse/trunk/servlet/src/com/google
/inject/servlet/ManagedServletPipeline.java?r=1015#116

Thanks

Original comment by jelleher...@gmail.com on 14 Aug 2009 at 4:50

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 22 Feb 2011 at 1:42