From 6070c4ff6d367b4551267f2c33225f7b2154c895 Mon Sep 17 00:00:00 2001 From: "Donald J. Brown" Date: Tue, 29 Jul 2008 12:53:18 +0000 Subject: [PATCH] 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 --- .../org/apache/struts2/rest/RestActionMapper.java | 9 ++++++++- .../apache/struts2/rest/RestActionMapperTest.java | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java index a0fdda001..c292b9782 100644 --- a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java +++ b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java @@ -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)) { diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java index 87349b18e..4623861d3 100644 --- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java +++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java @@ -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/");