WW-4585 Struts2 Rest plugin doesn't handle JSESSIONID with DMI

This commit is contained in:
Aleksandr Mashchenko
2016-01-14 20:01:57 +02:00
committed by Lukasz Lenart
parent dd849e82f3
commit 5eaef08e52
2 changed files with 42 additions and 2 deletions
@@ -308,9 +308,20 @@ public class RestActionMapper extends DefaultActionMapper {
private void handleDynamicMethodInvocation(ActionMapping mapping, String name) {
int exclamation = name.lastIndexOf("!");
if (exclamation != -1) {
mapping.setName(name.substring(0, exclamation));
String actionName = name.substring(0, exclamation);
String actionMethod = name.substring(exclamation + 1);
// WW-4585
// add any ; appendix to name, it will be handled later in getMapping method
int scPos = actionMethod.indexOf(';');
if (scPos != -1) {
actionName = actionName + actionMethod.substring(scPos);
actionMethod = actionMethod.substring(0, scPos);
}
mapping.setName(actionName);
if (allowDynamicMethodCalls) {
mapping.setMethod(name.substring(exclamation + 1));
mapping.setMethod(actionMethod);
} else {
mapping.setMethod(null);
}
@@ -179,6 +179,35 @@ 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 testParseNameAndNamespace() {
tryUri("/foo/23", "", "foo/23");
tryUri("/foo/", "", "foo/");