SPR-6978 - Dispatcher fails to invoke handler method when request method conflicts with request path
This commit is contained in:
parent
b07d02f1bf
commit
4c0744ee54
|
|
@ -637,8 +637,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||||
|
|
||||||
Map<String, String> variables =
|
Map<String, String> variables =
|
||||||
(Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
(Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
||||||
|
|
||||||
|
int patternVariableCount = StringUtils.countOccurrencesOf(mappedPattern, "{");
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(variables) && pathMatcher.match(mappedPattern, lookupPath)) {
|
if ( (variables == null || patternVariableCount != variables.size())
|
||||||
|
&& pathMatcher.match(mappedPattern, lookupPath)) {
|
||||||
variables = pathMatcher.extractUriTemplateVariables(mappedPattern, lookupPath);
|
variables = pathMatcher.extractUriTemplateVariables(mappedPattern, lookupPath);
|
||||||
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, variables);
|
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, variables);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -376,6 +376,36 @@ public class UriTemplateServletAnnotationControllerTests {
|
||||||
assertEquals("plain-bar", response.getContentAsString());
|
assertEquals("plain-bar", response.getContentAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* See SPR-6978
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void doIt() throws Exception {
|
||||||
|
initServlet(Spr6978Controller.class);
|
||||||
|
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/100");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertEquals("loadEntity:foo:100", response.getContentAsString());
|
||||||
|
|
||||||
|
request = new MockHttpServletRequest("POST", "/foo/100");
|
||||||
|
response = new MockHttpServletResponse();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertEquals("publish:foo:100", response.getContentAsString());
|
||||||
|
|
||||||
|
request = new MockHttpServletRequest("GET", "/module/100");
|
||||||
|
response = new MockHttpServletResponse();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertEquals("loadModule:100", response.getContentAsString());
|
||||||
|
|
||||||
|
request = new MockHttpServletRequest("POST", "/module/100");
|
||||||
|
response = new MockHttpServletResponse();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertEquals("publish:module:100", response.getContentAsString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controllers
|
* Controllers
|
||||||
|
|
@ -625,5 +655,26 @@ public class UriTemplateServletAnnotationControllerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public static class Spr6978Controller {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET)
|
||||||
|
public void loadEntity(@PathVariable final String type, @PathVariable final long id, Writer writer)
|
||||||
|
throws IOException {
|
||||||
|
writer.write("loadEntity:" + type + ":" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/module/{id}", method = RequestMethod.GET)
|
||||||
|
public void loadModule(@PathVariable final long id, Writer writer) throws IOException {
|
||||||
|
writer.write("loadModule:" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/{type}/{id}", method = RequestMethod.POST)
|
||||||
|
public void publish(@PathVariable final String type, @PathVariable final long id, Writer writer)
|
||||||
|
throws IOException {
|
||||||
|
writer.write("publish:" + type + ":" + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue