issue 418 - make sure servlet extension works with context paths.  thanks to Henning for provided the patches.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@1529 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java
index aea5220..e09d79d 100755
--- a/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java
+++ b/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java
@@ -156,7 +156,8 @@
       ServletResponse servletResponse, FilterChainInvocation filterChainInvocation)
       throws IOException, ServletException {
 
-    final String path = ((HttpServletRequest) servletRequest).getServletPath();
+    final HttpServletRequest request = (HttpServletRequest) servletRequest;
+    final String path = request.getRequestURI().substring(request.getContextPath().length());
 
     if (shouldFilter(path)) {
       filter.get()
diff --git a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
index c5849d9..56d5d7e 100755
--- a/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
+++ b/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java
@@ -168,7 +168,10 @@
   public boolean service(ServletRequest servletRequest,
       ServletResponse servletResponse) throws IOException, ServletException {
 
-    final boolean serve = shouldServe(((HttpServletRequest) servletRequest).getServletPath());
+    final HttpServletRequest request = (HttpServletRequest) servletRequest;
+    final String path = request.getRequestURI().substring(request.getContextPath().length());
+
+    final boolean serve = shouldServe(path);
 
     //invocations of the chain end at the first matched servlet
     if (serve) {
@@ -186,7 +189,6 @@
    * We need to suppress deprecation coz we use HttpServletRequestWrapper, which implements
    * deprecated API for backwards compatibility.
    */
-  @SuppressWarnings({ "JavaDoc", "deprecation" })
   void doService(final ServletRequest servletRequest, ServletResponse servletResponse)
       throws ServletException, IOException {
 
diff --git a/extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java b/extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java
new file mode 100644
index 0000000..0f1e5f9
--- /dev/null
+++ b/extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java
@@ -0,0 +1,293 @@
+/**
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.inject.servlet;
+
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.expect;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.easymock.IMocksControl;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Scopes;
+import com.google.inject.name.Named;
+import com.google.inject.name.Names;
+
+/** Tests to make sure that servlets with a context path are handled right. */
+public class ContextPathTest extends TestCase {
+
+  @Inject @Named("foo")
+  private TestServlet fooServlet;
+
+  @Inject @Named("bar") 
+  private TestServlet barServlet;
+
+  private IMocksControl globalControl;
+  private Injector injector;
+  private ServletContext servletContext;
+  private FilterConfig filterConfig;
+  private GuiceFilter guiceFilter;
+
+  @Override
+  public final void setUp() throws Exception {
+    injector = Guice.createInjector(new ServletModule() {
+      @Override
+      protected void configureServlets() {
+        bind(TestServlet.class).annotatedWith(Names.named("foo"))
+            .to(TestServlet.class).in(Scopes.SINGLETON);
+        bind(TestServlet.class).annotatedWith(Names.named("bar"))
+            .to(TestServlet.class).in(Scopes.SINGLETON);
+        serve("/foo/*").with(Key.get(TestServlet.class, Names.named("foo")));
+        serve("/bar/*").with(Key.get(TestServlet.class, Names.named("bar")));
+        // TODO: add a filter(..) call and validate it is correct
+      }
+    });
+    injector.injectMembers(this);
+
+    assertNotNull(fooServlet);
+    assertNotNull(barServlet);
+    assertNotSame(fooServlet, barServlet);
+
+    globalControl = createControl();
+    servletContext = globalControl.createMock(ServletContext.class);
+    filterConfig = globalControl.createMock(FilterConfig.class);
+
+    expect(servletContext.getAttribute(GuiceServletContextListener.INJECTOR_NAME))
+        .andReturn(injector).anyTimes();
+    expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
+
+    globalControl.replay();
+
+    guiceFilter = new GuiceFilter();
+    guiceFilter.init(filterConfig);
+  }
+
+  @Override
+  public final void tearDown() {
+    assertNotNull(fooServlet);
+    assertNotNull(barServlet);
+
+    fooServlet = null;
+    barServlet = null;
+
+    guiceFilter.destroy();
+    guiceFilter = null;
+
+    injector = null;
+
+    filterConfig = null;
+    servletContext = null;
+
+    globalControl.verify();
+  }
+
+  public void testSimple() throws Exception {
+    IMocksControl testControl = createControl();
+    TestFilterChain testFilterChain = new TestFilterChain();
+    HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
+    HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
+
+    expect(req.getMethod()).andReturn("GET").anyTimes();
+    expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes();
+    expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
+    expect(req.getContextPath()).andReturn("").anyTimes();
+
+    testControl.replay();
+
+    guiceFilter.doFilter(req, res, testFilterChain);
+
+    assertFalse(testFilterChain.isTriggered());
+    assertFalse(fooServlet.isTriggered());
+    assertTrue(barServlet.isTriggered());
+
+    testControl.verify();
+  }
+
+  //
+  // each of the following "runTest" calls takes three path parameters:
+  //
+  // The value of "getRequestURI()"
+  // The value of "getServletPath()"
+  // The value of "getContextPath()"
+  //
+  // these values have been captured using a filter in Apache Tomcat 6.0.32
+  // and are used for real-world values that a servlet container would send into
+  // the GuiceFilter.
+  //
+  // the remaining three booleans are:
+  //
+  // True if the request gets passed down the filter chain
+  // True if the request hits the "foo" servlet
+  // True if the request hits the "bar" sevlet
+  //
+  // After adjusting the request URI for the web app deployment location, all
+  // calls
+  // should always produce the same result.
+  //
+
+  // ROOT Web app, using Tomcat default servlet
+  public void testRootDefault() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "/", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "/bar/", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "/foo/xxx", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "/xxx", "", true, false, false);
+  }
+
+  // ROOT Web app, using explicit backing servlet mounted at /*
+  public void testRootExplicit() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "", "", true, false, false);
+  }
+
+  // ROOT Web app, using two backing servlets, mounted at /bar/* and /foo/*
+  public void testRootSpecific() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/", "/", "", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/bar/", "/bar", "", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/foo/xxx", "/foo", "", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/xxx", "/xxx", "", true, false, false);
+  }
+
+  // Web app located at /webtest, using Tomcat default servlet
+  public void testWebtestDefault() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/webtest/", "/", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "/bar/", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/webtest/foo/xxx", "/foo/xxx", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "/xxx", "/webtest", true, false, false);
+  }
+
+  // Web app located at /webtest, using explicit backing servlet mounted at /*
+  public void testWebtestExplicit() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and /bar/*).
+    runTest("/webtest/", "", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/webtest/foo/xxx", "", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "", "/webtest", true, false, false);
+  }
+
+  // Web app located at /webtest, using two backing servlets, mounted at /bar/*
+  // and /foo/*
+  public void testWebtestSpecific() throws Exception {
+    // fetching /. Should go up the filter chain (only mappings on /foo/* and
+    // /bar/*).
+    runTest("/webtest/", "/", "/webtest", true, false, false);
+    // fetching /bar/. Should hit the bar servlet
+    runTest("/webtest/bar/", "/bar", "/webtest", false, false, true);
+    // fetching /foo/xxx. Should hit the foo servlet
+    runTest("/webtest/foo/xxx", "/foo", "/webtest", false, true, false);
+    // fetching /xxx. Should go up the chain
+    runTest("/webtest/xxx", "/xxx", "/webtest", true, false, false);
+  }
+
+  private void runTest(final String requestURI, final String servletPath, final String contextPath,
+      final boolean filterResult, final boolean fooResult, final boolean barResult)
+      throws Exception {
+    IMocksControl testControl = createControl();
+
+    barServlet.clear();
+    fooServlet.clear();
+
+    TestFilterChain testFilterChain = new TestFilterChain();
+    HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
+    HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
+
+    expect(req.getMethod()).andReturn("GET").anyTimes();
+    expect(req.getRequestURI()).andReturn(requestURI).anyTimes();
+    expect(req.getServletPath()).andReturn(servletPath).anyTimes();
+    expect(req.getContextPath()).andReturn(contextPath).anyTimes();
+
+    testControl.replay();
+
+    guiceFilter.doFilter(req, res, testFilterChain);
+
+    assertEquals(filterResult, testFilterChain.isTriggered());
+    assertEquals(fooResult, fooServlet.isTriggered());
+    assertEquals(barResult, barServlet.isTriggered());
+
+    testControl.verify();
+  }
+
+  public static class TestServlet extends HttpServlet {
+    private boolean triggered = false;
+
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
+      triggered = true;
+    }
+
+    public boolean isTriggered() {
+      return triggered;
+    }
+
+    public void clear() {
+      triggered = false;
+    }
+  }
+
+  public static class TestFilterChain implements FilterChain {
+    private boolean triggered = false;
+
+    public void doFilter(ServletRequest request, ServletResponse response) throws IOException,
+        ServletException {
+      triggered = true;
+    }
+
+    public boolean isTriggered() {
+      return triggered;
+    }
+
+    public void clear() {
+      triggered = false;
+    }
+  }
+}
diff --git a/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java
index 1e1811c..befb549 100644
--- a/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java
@@ -118,7 +118,10 @@
 
     HttpServletRequest request = createMock(HttpServletRequest.class);
 
-    expect(request.getServletPath()).andReturn("/");
+    expect(request.getRequestURI()).andReturn("/");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
     expect(request.getMethod()).andReturn("GET");
 
     FilterChain filterChain = createMock(FilterChain.class);
@@ -157,7 +160,11 @@
 
     HttpServletRequest request = createMock(HttpServletRequest.class);
 
-    expect(request.getServletPath()).andReturn("/");
+    expect(request.getRequestURI()).andReturn("/");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
+
     expect(request.getMethod()).andReturn("GET");
     FilterChain filterChain = createMock(FilterChain.class);
     
diff --git a/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java b/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java
index 63711c6..f11d84f 100644
--- a/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/FilterDefinitionTest.java
@@ -106,7 +106,10 @@
         .andReturn(mockFilter)
         .anyTimes();
 
-    expect(request.getServletPath()).andReturn("/index.html");
+    expect(request.getRequestURI()).andReturn("/index.html");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     replay(injector, binding, request);
 
@@ -163,7 +166,10 @@
         .andReturn(mockFilter)
         .anyTimes();
 
-    expect(request.getServletPath()).andReturn("/index.html");
+    expect(request.getRequestURI()).andReturn("/index.html");
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     replay(injector, binding, request);
 
diff --git a/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java
index ebd6b08..e6a2b11 100644
--- a/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/FilterDispatchIntegrationTest.java
@@ -72,12 +72,12 @@
     // create ourselves a mock request with test URI
     HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
-            .andReturn("/index.html")
-            .anyTimes();
     expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true);
     requestMock.removeAttribute(REQUEST_DISPATCHER_REQUEST);
@@ -128,9 +128,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.xhtml")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     FilterChain filterChain = control.createMock(FilterChain.class);
@@ -166,9 +169,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = control.createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     // dispatch request
     FilterChain filterChain = control.createMock(FilterChain.class);
@@ -211,7 +217,7 @@
         throws ServletException, IOException {
       String requestUri = httpServletRequest.getRequestURI();
       processedUris.add(requestUri);
-      
+
       // If the client is requesting /index.html then we forward to /forwarded.html
       if (FORWARD_FROM.equals(requestUri)) {
         httpServletRequest.getRequestDispatcher(FORWARD_TO)
diff --git a/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java b/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java
index a9701b3..fbef312 100644
--- a/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/FilterPipelineTest.java
@@ -70,9 +70,12 @@
         .andReturn(servletContext)
         .once();
 
-    expect(request.getServletPath())
+    expect(request.getRequestURI())
         .andReturn("/public/login.jsp")
         .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //at the end, proceed down webapp's normal filter chain
     proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
diff --git a/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java b/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java
index 8ac6343..2d9e3ed 100644
--- a/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/InjectedFilterPipelineTest.java
@@ -85,9 +85,12 @@
         .andReturn(servletContext)
         .once();
 
-    expect(request.getServletPath())
+    expect(request.getRequestURI())
         .andReturn("/non-jsp/login.html") // use a path that will fail in injector2
         .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //at the end, proceed down webapp's normal filter chain
     proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
@@ -109,7 +112,7 @@
 
 
 
-    
+
     // reset mocks and run them against the other injector
     reset(filterConfig, servletContext, request, proceedingFilterChain);
 
@@ -121,14 +124,17 @@
     expect(filterConfig.getServletContext())
         .andReturn(servletContext)
         .once();
-    expect(request.getServletPath())
+    expect(request.getRequestURI())
             .andReturn("/public/login/login.jsp") // use a path that will fail in injector1
             .anyTimes();
+    expect(request.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //at the end, proceed down webapp's normal filter chain
     proceedingFilterChain2.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull());
     expectLastCall().once();
-    
+
     // Never fire on this pipeline
     replay(filterConfig, servletContext, request, proceedingFilterChain2, proceedingFilterChain);
 
@@ -169,4 +175,4 @@
     public void destroy() {
     }
   }
-}
\ No newline at end of file
+}
diff --git a/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java
index 02ddbd5..fac0895 100644
--- a/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java
@@ -72,9 +72,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -105,4 +108,4 @@
       destroys++;
     }
   }
-}
\ No newline at end of file
+}
diff --git a/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java
index 5446472..bf157f8 100644
--- a/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/ServletDispatchIntegrationTest.java
@@ -81,9 +81,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(1);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -125,9 +128,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(2);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -233,9 +239,12 @@
 
     final HttpServletRequest requestMock = createMock(HttpServletRequest.class);
     HttpServletResponse responseMock = createMock(HttpServletResponse.class);
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/")
         .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true);
     expect(requestMock.getAttribute(REQUEST_DISPATCHER_REQUEST)).andReturn(true);
@@ -253,4 +262,4 @@
     assertEquals("Incorrect number of forwards", 1, ForwardedServlet.forwardedTo);
     verify(requestMock, responseMock);
   }
-}
\ No newline at end of file
+}
diff --git a/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java
index 66e56f1..657b59d 100644
--- a/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java
@@ -62,9 +62,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.html")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -98,9 +101,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index.xhtml")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -135,9 +141,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
             .andReturn("/index")
             .anyTimes();
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -168,4 +177,4 @@
       destroys++;
     }
   }
-}
\ No newline at end of file
+}
diff --git a/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java b/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java
index dbe9952..c4eb75b 100644
--- a/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java
+++ b/extensions/servlet/test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java
@@ -75,9 +75,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(1);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -112,9 +115,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(3);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -152,9 +158,12 @@
     //create ourselves a mock request with test URI
     HttpServletRequest requestMock = createMock(HttpServletRequest.class);
 
-    expect(requestMock.getServletPath())
+    expect(requestMock.getRequestURI())
         .andReturn("/index.html")
         .times(2);
+    expect(requestMock.getContextPath())
+        .andReturn("")
+        .anyTimes();
 
     //dispatch request
     replay(requestMock);
@@ -218,4 +227,4 @@
       destroys++;
     }
   }
-}
\ No newline at end of file
+}