Better handle ;jsessionid in rest plugin

WW-2328


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@680686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2008-07-29 12:53:18 +00:00
parent abef0ef66f
commit 6070c4ff6d
2 changed files with 21 additions and 1 deletions
@@ -183,6 +183,13 @@ public class RestActionMapper extends DefaultActionMapper {
String fullName = mapping.getName();
// Only try something if the action name is specified
if (fullName != null && fullName.length() > 0) {
// cut off any ;jsessionid= type appendix but allow the rails-like ;edit
int scPos = fullName.indexOf(';');
if (scPos > -1 && !"edit".equals(fullName.substring(scPos+1))) {
fullName = fullName.substring(0, scPos);
}
int lastSlashPos = fullName.lastIndexOf('/');
String id = null;
if (lastSlashPos > -1) {
@@ -240,7 +247,7 @@ public class RestActionMapper extends DefaultActionMapper {
}
}
}
// cut off the id parameter, even if a method is specified
if (id != null) {
if (!"new".equals(id)) {
@@ -156,6 +156,19 @@ public class RestActionMapperTest extends TestCase {
assertEquals("edit", mapping.getMethod());
}
public void testGetJsessionIdSemicolonMapping() throws Exception {
req.setRequestURI("/myapp/animals/dog/fido;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 testParseNameAndNamespace() {
tryUri("/foo/23", "", "foo/23");
tryUri("/foo/", "", "foo/");