Created
July 7, 2014 18:21
-
-
Save gissuebot/f12e9712bdd7a1809863 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 418, comment 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/VarargsFilterDispatchIntegrationTest.java (working copy) | |
@@ -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 | |
+} | |
Index: test/com/google/inject/servlet/ServletDispatchIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/ServletDispatchIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/ServletDispatchIntegrationTest.java (working copy) | |
@@ -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 | |
+} | |
Index: test/com/google/inject/servlet/FilterDispatchIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/FilterDispatchIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/FilterDispatchIntegrationTest.java (working copy) | |
@@ -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) | |
Index: test/com/google/inject/servlet/FilterPipelineTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/FilterPipelineTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/FilterPipelineTest.java (working copy) | |
@@ -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()); | |
Index: test/com/google/inject/servlet/InjectedFilterPipelineTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/InjectedFilterPipelineTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/InjectedFilterPipelineTest.java (working copy) | |
@@ -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 | |
+} | |
Index: test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/MultiModuleDispatchIntegrationTest.java (working copy) | |
@@ -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 | |
+} | |
Index: test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java (working copy) | |
@@ -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); | |
Index: test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/VarargsServletDispatchIntegrationTest.java (working copy) | |
@@ -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 | |
+} | |
Index: test/com/google/inject/servlet/FilterDefinitionTest.java | |
=================================================================== | |
--- test/com/google/inject/servlet/FilterDefinitionTest.java (revision 1528) | |
+++ test/com/google/inject/servlet/FilterDefinitionTest.java (working copy) | |
@@ -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); | |
Index: src/com/google/inject/servlet/ServletDefinition.java | |
=================================================================== | |
--- src/com/google/inject/servlet/ServletDefinition.java (revision 1528) | |
+++ src/com/google/inject/servlet/ServletDefinition.java (working copy) | |
@@ -168,8 +168,11 @@ | |
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) { | |
doService(servletRequest, servletResponse); | |
Index: src/com/google/inject/servlet/FilterDefinition.java | |
=================================================================== | |
--- src/com/google/inject/servlet/FilterDefinition.java (revision 1528) | |
+++ src/com/google/inject/servlet/FilterDefinition.java (working copy) | |
@@ -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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment