SPR-6649 - Request mapping incorrectly receiving all dispatches for a controller
This commit is contained in:
parent
2f840b1097
commit
ead5df4546
|
|
@ -596,7 +596,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String bestMatchingPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
String bestMatchingPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||||
if (StringUtils.hasText(bestMatchingPattern)) {
|
if (StringUtils.hasText(bestMatchingPattern) && bestMatchingPattern.endsWith("*")) {
|
||||||
String combinedPattern = pathMatcher.combine(bestMatchingPattern, methodLevelPattern);
|
String combinedPattern = pathMatcher.combine(bestMatchingPattern, methodLevelPattern);
|
||||||
if (!combinedPattern.equals(bestMatchingPattern) &&
|
if (!combinedPattern.equals(bestMatchingPattern) &&
|
||||||
(isPathMatchInternal(combinedPattern, lookupPath))) {
|
(isPathMatchInternal(combinedPattern, lookupPath))) {
|
||||||
|
|
|
||||||
|
|
@ -204,8 +204,20 @@ public class ServletAnnotationControllerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultExpressionParameters() throws Exception {
|
public void defaultExpressionParameters() throws Exception {
|
||||||
initServlet(DefaultExpressionValueParamController.class);
|
servlet = new DispatcherServlet() {
|
||||||
|
@Override
|
||||||
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
|
||||||
|
GenericWebApplicationContext wac = new GenericWebApplicationContext();
|
||||||
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(DefaultExpressionValueParamController.class));
|
||||||
|
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
|
||||||
|
ppc.getPropertyValues().add("properties", "myKey=foo");
|
||||||
|
wac.registerBeanDefinition("ppc", ppc);
|
||||||
|
wac.refresh();
|
||||||
|
return wac;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
servlet.init(new MockServletConfig());
|
||||||
|
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
|
||||||
request.setContextPath("/myApp");
|
request.setContextPath("/myApp");
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
@ -344,9 +356,6 @@ public class ServletAnnotationControllerTests {
|
||||||
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
|
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
|
||||||
GenericWebApplicationContext wac = new GenericWebApplicationContext();
|
GenericWebApplicationContext wac = new GenericWebApplicationContext();
|
||||||
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
|
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
|
||||||
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
|
|
||||||
ppc.getPropertyValues().add("properties", "myKey=foo");
|
|
||||||
wac.registerBeanDefinition("ppc", ppc);
|
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
return wac;
|
return wac;
|
||||||
}
|
}
|
||||||
|
|
@ -1279,6 +1288,16 @@ public class ServletAnnotationControllerTests {
|
||||||
assertEquals("handle", response.getContentAsString());
|
assertEquals("handle", response.getContentAsString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void trailingSlash() throws Exception {
|
||||||
|
initServlet(TrailingSlashController.class);
|
||||||
|
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertEquals("templatePath", response.getContentAsString());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controllers
|
* Controllers
|
||||||
|
|
@ -2206,5 +2225,19 @@ public class ServletAnnotationControllerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public static class TrailingSlashController {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||||
|
public void root(Writer writer) throws IOException {
|
||||||
|
writer.write("root");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{templatePath}/", method = RequestMethod.GET)
|
||||||
|
public void templatePath(Writer writer) throws IOException {
|
||||||
|
writer.write("templatePath");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue