WW-4589 do not overwrite explicit method name

Conflicts:
	plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
This commit is contained in:
petersr
2016-01-19 14:02:57 -08:00
committed by Lukasz Lenart
parent c6750c110c
commit 1d160f4d5f
2 changed files with 70 additions and 1 deletions
@@ -215,7 +215,8 @@ public class RestActionMapper extends DefaultActionMapper {
// fun trickery to parse 'actionName/id/methodName' in the case of 'animals/dog/edit'
int prevSlashPos = fullName.lastIndexOf('/', lastSlashPos - 1);
if (prevSlashPos > -1) {
//WW-4589 do not overwrite explicit method name
if (prevSlashPos > -1 && mapping.getMethod() == null) {
mapping.setMethod(fullName.substring(lastSlashPos + 1));
fullName = fullName.substring(0, lastSlashPos);
lastSlashPos = prevSlashPos;
@@ -179,6 +179,74 @@ public class RestActionMapperTest extends TestCase {
assertEquals("show", mapping.getMethod());
}
public void testGetJsessionIdSemicolonMappingWithMethod() throws Exception {
req.setRequestURI("/myapp/animals/dog/fido!update;jsessionid=29fefpv23do1g");
req.setServletPath("/animals/dog/fido");
req.setMethod("GET");
ActionMapping mapping = mapper.getMapping(req, configManager);
assertEquals("/animals", mapping.getNamespace());
assertEquals("dog", mapping.getName());
assertEquals("fido", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("show", mapping.getMethod());
}
public void testGetJsessionIdSemicolonMappingWithMethodAllowDMI() throws Exception {
req.setRequestURI("/myapp/animals/dog/fido!update;jsessionid=29fefpv23do1g");
req.setServletPath("/animals/dog/fido");
req.setMethod("GET");
// allow DMI
mapper.setAllowDynamicMethodCalls("true");
ActionMapping mapping = mapper.getMapping(req, configManager);
assertEquals("/animals", mapping.getNamespace());
assertEquals("dog", mapping.getName());
assertEquals("fido", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("update", mapping.getMethod());
}
public void testMappingWithMethodAndId() throws Exception {
req.setRequestURI("/myapp/animals/dog/fido/test/some-id!create;jsessionid=29fefpv23do1g");
req.setServletPath("/animals/dog/fido/test/some-id");
req.setMethod("GET");
mapper.setAllowDynamicMethodCalls("true");
ActionMapping mapping = mapper.getMapping(req, configManager);
assertEquals("/animals", mapping.getNamespace());
assertEquals("dog/fido/test", mapping.getName());
assertEquals("some-id", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("create", mapping.getMethod());
}
public void testMappingForStaticFiles() throws Exception {
req.setRequestURI("/myApp/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image!iframe");
req.setServletPath("/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image");
req.setMethod("GET");
mapper.setAllowDynamicMethodCalls("true");
final ActionMapping mapping = mapper.getMapping(req, configManager);
assertEquals("", mapping.getNamespace());
assertEquals("custom/menu/Yosemite/Vernal_Fall", mapping.getName());
assertEquals("Vernal_Fall_Image", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("iframe", mapping.getMethod());
}
public void testMappingForStaticFilesWithJsessionId() throws Exception {
req.setRequestURI("/myApp/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image!iframe;jsessionid=29fefpv23do1g");
req.setServletPath("/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image");
req.setMethod("GET");
mapper.setAllowDynamicMethodCalls("true");
final ActionMapping mapping = mapper.getMapping(req, configManager);
assertEquals("", mapping.getNamespace());
assertEquals("custom/menu/Yosemite/Vernal_Fall", mapping.getName());
assertEquals("Vernal_Fall_Image", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("iframe", mapping.getMethod());
}
public void testParseNameAndNamespace() {
tryUri("/foo/23", "", "foo/23");
tryUri("/foo/", "", "foo/");