struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amashche...@apache.org
Subject [2/2] struts git commit: WW-4585 Struts2 Rest plugin doesn't handle JSESSIONID with DMI
Date Thu, 14 Jan 2016 18:09:00 GMT
WW-4585 Struts2 Rest plugin doesn't handle JSESSIONID with DMI


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/ff4cdd96
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/ff4cdd96
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/ff4cdd96

Branch: refs/heads/support-2-3
Commit: ff4cdd967031ed21740ee555d9e0c58b2033aa0c
Parents: 7c4bb7e
Author: Aleksandr Mashchenko <amashchenko@apache.org>
Authored: Thu Jan 14 20:08:21 2016 +0200
Committer: Aleksandr Mashchenko <amashchenko@apache.org>
Committed: Thu Jan 14 20:08:21 2016 +0200

----------------------------------------------------------------------
 .../apache/struts2/rest/RestActionMapper.java   | 15 ++++++++--
 .../struts2/rest/RestActionMapperTest.java      | 29 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/ff4cdd96/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
----------------------------------------------------------------------
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 c4fd827..840ddfe 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
@@ -299,9 +299,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);
             }

http://git-wip-us.apache.org/repos/asf/struts/blob/ff4cdd96/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
----------------------------------------------------------------------
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 8d39cc1..9903265 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
@@ -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/");


Mime
View raw message