Author: scottbw
Date: Thu Feb 23 22:24:10 2012
New Revision: 1292994

URL: http://svn.apache.org/viewvc?rev=1292994&view=rev
Log:
Ensure that we get the correct resource part of the URL in controller methods 
even when using a percent-encoded URL as a path element, as in /widgets/{url}

Modified:
    incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java
    
incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetsController.java

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java?rev=1292994&r1=1292993&r2=1292994&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java Thu 
Feb 23 22:24:10 2012
@@ -211,10 +211,6 @@ public abstract class Controller extends
                if (path.startsWith("/")) {
                        path = path.substring(1);
                }
-               int p = path.indexOf('/');
-               if (p > 0) {
-                       path = path.substring(0, p); // name isolated
-               }
                if (path != null)
                        path = path.trim();
                return path;

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetsController.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetsController.java?rev=1292994&r1=1292993&r2=1292994&view=diff
==============================================================================
--- 
incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetsController.java 
(original)
+++ 
incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetsController.java 
Thu Feb 23 22:24:10 2012
@@ -16,8 +16,6 @@ package org.apache.wookie.controller;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.List;
 
 import javax.servlet.ServletException;
@@ -84,8 +82,10 @@ public class WidgetsController extends C
                        index(resourceId, request, response);
                        return;
                }
+               
+               System.out.println("ResourceID:"+resourceId);
                IPersistenceManager persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
-               IWidget widget = 
persistenceManager.findWidgetByGuid(parseForGuid(request));
+               IWidget widget = 
persistenceManager.findWidgetByGuid(resourceId);
                // attempt to get specific widget by id
                if (widget == null) {
                  persistenceManager = 
PersistenceManagerFactory.getPersistenceManager();
@@ -234,24 +234,5 @@ public class WidgetsController extends C
            return false;
          }
        }
-       
-       /**
-        * Tries to obtain the guid of a widget from the path given
-        * by stripping out the '/wookie/widgets/' string at the beginning
-        * @param request
-        * @return a string guid or null if not found
-        */
-       private String parseForGuid(HttpServletRequest request){
-         try {
-           String path = URLDecoder.decode(request.getRequestURI(), "UTF-8");
-           // note the context name may not always be /wookie, so we check the 
context path
-           if(path != null && path.length() > 
request.getContextPath().length() + 9){
-             return path.substring(request.getContextPath().length() + 9, 
path.length());
-           }
-         } catch (UnsupportedEncodingException e) {
-           throw new RuntimeException("Server must support UTF-8 encoding", e);
-         }
-         return null;
-       }
     
 }


Reply via email to