You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2008/07/29 14:53:19 UTC

svn commit: r680686 - in /struts/struts2/trunk/plugins/rest/src: main/java/org/apache/struts2/rest/RestActionMapper.java test/java/org/apache/struts2/rest/RestActionMapperTest.java

Author: mrdon
Date: Tue Jul 29 05:53:18 2008
New Revision: 680686

URL: http://svn.apache.org/viewvc?rev=680686&view=rev
Log:
Better handle ;jsessionid in rest plugin
WW-2328

Modified:
    struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
    struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java

Modified: struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java?rev=680686&r1=680685&r2=680686&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java (original)
+++ struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java Tue Jul 29 05:53:18 2008
@@ -183,6 +183,13 @@
         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 @@
                     }
                 }
             }
-            
+
             // cut off the id parameter, even if a method is specified
             if (id != null) {
                 if (!"new".equals(id)) {

Modified: struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java?rev=680686&r1=680685&r2=680686&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java (original)
+++ struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java Tue Jul 29 05:53:18 2008
@@ -156,6 +156,19 @@
         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/");