Revision: 975
          http://stripes.svn.sourceforge.net/stripes/?rev=975&view=rev
Author:   bengunter
Date:     2008-10-17 03:28:56 +0000 (Fri, 17 Oct 2008)

Log Message:
-----------
Fixed STS-575. Replaced all calls to HttpServletRequest.getRequestURI() with a 
call to HttpUtil.getRequestedPath(HttpServletRequest), which returns the 
servlet path + path info. This led to the addition of a new HttpUtil class and 
the deprecation of a couple of methods in DynamicMappingFilter and 
AnnotatedClassActionResolver that the new utility method replaces.

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
    trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherServlet.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/DynamicMappingFilter.java
    trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java
    trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java

Added Paths:
-----------
    trunk/stripes/src/net/sourceforge/stripes/util/HttpUtil.java

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2008-10-14 20:52:30 UTC (rev 974)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2008-10-17 03:28:56 UTC (rev 975)
@@ -24,6 +24,7 @@
 import net.sourceforge.stripes.exception.ActionBeanNotFoundException;
 import net.sourceforge.stripes.exception.StripesRuntimeException;
 import net.sourceforge.stripes.exception.StripesServletException;
+import net.sourceforge.stripes.util.HttpUtil;
 import net.sourceforge.stripes.util.Log;
 import net.sourceforge.stripes.util.ResolverUtil;
 import net.sourceforge.stripes.util.StringUtil;
@@ -275,7 +276,7 @@
     public ActionBean getActionBean(ActionBeanContext context) throws 
StripesServletException {
         HttpServletRequest request = context.getRequest();
         UrlBinding binding = 
UrlBindingFactory.getInstance().getBindingPrototype(request);
-        String path = binding == null ? getRequestedPath(request) : 
binding.getPath();
+        String path = binding == null ? HttpUtil.getRequestedPath(request) : 
binding.getPath();
         ActionBean bean = getActionBean(context, path);
         request.setAttribute(RESOLVED_ACTION, getUrlBindingFromPath(path));
         return bean;
@@ -287,7 +288,9 @@
      *
      * @param request the current HttpServletRequest
      * @return the servlet-context relative path that is being requested
+     * @deprecated Use [EMAIL PROTECTED] 
HttpUtil#getRequestedPath(HttpServletRequest)} instead.
      */
+    @Deprecated
     protected String getRequestedPath(HttpServletRequest request) {
         String servletPath = null, pathInfo = null;
 
@@ -520,7 +523,7 @@
     protected String getEventNameFromPath(Class<? extends ActionBean> bean,
                                           ActionBeanContext context) {
         Map<String,Method> mappings = this.eventMappings.get(bean);
-        String path = getRequestedPath(context.getRequest());
+        String path = HttpUtil.getRequestedPath(context.getRequest());
         String binding = getUrlBindingFromPath(path);
 
         if (binding != null && path.length() != binding.length()) {

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherServlet.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherServlet.java 
2008-10-14 20:52:30 UTC (rev 974)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherServlet.java 
2008-10-17 03:28:56 UTC (rev 975)
@@ -19,6 +19,7 @@
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.config.Configuration;
 import net.sourceforge.stripes.exception.StripesServletException;
+import net.sourceforge.stripes.util.HttpUtil;
 import net.sourceforge.stripes.util.Log;
 import net.sourceforge.stripes.validation.BooleanTypeConverter;
 import net.sourceforge.stripes.validation.expression.ExpressionValidator;
@@ -90,7 +91,7 @@
         ///////////////////////////////////////////////////////////////////////
         // Here beings the real processing of the request!
         ///////////////////////////////////////////////////////////////////////
-        log.trace("Dispatching request to URL: ", request.getRequestURI());
+        log.trace("Dispatching request to URL: ", 
HttpUtil.getRequestedPath(request));
 
         PageContext pageContext = null;
         final ExecutionContext ctx = new ExecutionContext();

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DynamicMappingFilter.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/DynamicMappingFilter.java  
    2008-10-14 20:52:30 UTC (rev 974)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/DynamicMappingFilter.java  
    2008-10-17 03:28:56 UTC (rev 975)
@@ -35,6 +35,7 @@
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.config.Configuration;
 import net.sourceforge.stripes.exception.StripesServletException;
+import net.sourceforge.stripes.util.HttpUtil;
 import net.sourceforge.stripes.util.Log;
 
 /**
@@ -341,7 +342,7 @@
         // Wrap the response in a wrapper that catches errors (but not 
exceptions)
         final ErrorTrappingResponseWrapper wrapper = new 
ErrorTrappingResponseWrapper(
                 (HttpServletResponse) response);
-        
wrapper.setInclude(request.getAttribute("javax.servlet.include.request_uri") != 
null);
+        
wrapper.setInclude(request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH) 
!= null);
         chain.doFilter(request, wrapper);
 
         // If a SC_NOT_FOUND error occurred, then try to match an ActionBean 
to the URL
@@ -351,7 +352,7 @@
                 public void doFilter(ServletRequest request, ServletResponse 
response)
                         throws IOException, ServletException {
                     // Look for an ActionBean that is mapped to the URI
-                    String uri = getRequestURI((HttpServletRequest) request);
+                    String uri = 
HttpUtil.getRequestedPath((HttpServletRequest) request);
                     Class<? extends ActionBean> beanType = 
StripesFilter.getConfiguration()
                             .getActionResolver().getActionBeanType(uri);
 
@@ -384,7 +385,12 @@
         initialized = true;
     }
 
-    /** Get the context-relative URI of the current include, forward or 
request. */
+    /**
+     * Get the context-relative URI of the current include, forward or request.
+     * 
+     * @deprecated Use [EMAIL PROTECTED] 
HttpUtil#getRequestedPath(HttpServletRequest)} instead.
+     */
+    @Deprecated
     protected String getRequestURI(HttpServletRequest request) {
         // Check for an include
         String uri = (String) 
request.getAttribute("javax.servlet.include.request_uri");

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java     
2008-10-14 20:52:30 UTC (rev 974)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/StripesFilter.java     
2008-10-17 03:28:56 UTC (rev 975)
@@ -19,6 +19,7 @@
 import net.sourceforge.stripes.config.RuntimeConfiguration;
 import net.sourceforge.stripes.exception.StripesRuntimeException;
 import net.sourceforge.stripes.exception.StripesServletException;
+import net.sourceforge.stripes.util.HttpUtil;
 import net.sourceforge.stripes.util.Log;
 
 import javax.servlet.Filter;
@@ -203,7 +204,7 @@
         // Wrap pretty much everything in a try/catch so that we can funnel 
even the most
         // bizarre or unexpected exceptions into the exception handler
         try {
-            log.trace("Intercepting request to URL: ", 
httpRequest.getRequestURI());
+            log.trace("Intercepting request to URL: ", 
HttpUtil.getRequestedPath(httpRequest));
 
             if (initial) {
                 // Pop the configuration into thread local

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java 
2008-10-14 20:52:30 UTC (rev 974)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/UrlBindingFactory.java 
2008-10-17 03:28:56 UTC (rev 975)
@@ -31,6 +31,7 @@
 
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.exception.StripesRuntimeException;
+import net.sourceforge.stripes.util.HttpUtil;
 import net.sourceforge.stripes.util.bean.ParseException;
 
 /**
@@ -111,7 +112,7 @@
     }
 
     /**
-     * Examines a URI (as might be returned by [EMAIL PROTECTED] 
HttpServletRequest#getRequestURI()}) and
+     * Examines a URI (as returned by [EMAIL PROTECTED] 
HttpUtil#getRequestedPath(HttpServletRequest)}) and
      * returns the associated binding prototype, if any. No attempt is made to 
extract parameter
      * values from the URI. This is intended as a fast means to get static 
information associated
      * with a given request URI.
@@ -145,11 +146,11 @@
      * @return a binding prototype, or null if the request URI does not match
      */
     public UrlBinding getBindingPrototype(HttpServletRequest request) {
-        return getBindingPrototype(trimContextPath(request));
+        return getBindingPrototype(HttpUtil.getRequestedPath(request));
     }
 
     /**
-     * Examines a URI (as might be returned by [EMAIL PROTECTED] 
HttpServletRequest#getRequestURI()}) and
+     * Examines a URI (as returned by [EMAIL PROTECTED] 
HttpUtil#getRequestedPath(HttpServletRequest)}) and
      * returns the associated binding, if any. Parameters will be extracted 
from the URI, and the
      * [EMAIL PROTECTED] UrlBindingParameter} objects returned by [EMAIL 
PROTECTED] UrlBinding#getParameters()} will
      * contain the values that are present in the URI.
@@ -241,7 +242,7 @@
      *         binding. Otherwise, this method should return null.
      */
     public UrlBinding getBinding(HttpServletRequest request) {
-        return getBinding(trimContextPath(request));
+        return getBinding(HttpUtil.getRequestedPath(request));
     }
 
     /**
@@ -424,7 +425,9 @@
      * 
      * @param request a servlet request
      * @return the context-relative request URI
+     * @deprecated Use [EMAIL PROTECTED] 
HttpUtil#getRequestedPath(HttpServletRequest)} instead.
      */
+    @Deprecated
     protected String trimContextPath(HttpServletRequest request) {
         // Trim context path from beginning of URI
         String uri = request.getRequestURI();

Added: trunk/stripes/src/net/sourceforge/stripes/util/HttpUtil.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/HttpUtil.java                
                (rev 0)
+++ trunk/stripes/src/net/sourceforge/stripes/util/HttpUtil.java        
2008-10-17 03:28:56 UTC (rev 975)
@@ -0,0 +1,67 @@
+/* Copyright 2008 Ben Gunter
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sourceforge.stripes.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import net.sourceforge.stripes.controller.StripesConstants;
+
+/**
+ * Provides helper methods for working with HTTP requests and responses.
+ * 
+ * @author Ben Gunter
+ * @since Stripes 1.5.1
+ */
+public class HttpUtil {
+    /**
+     * <p>
+     * Get the path from the given request. This method is different from
+     * [EMAIL PROTECTED] HttpServletRequest#getRequestURI()} in that it 
concatenates and returns the servlet
+     * path plus the path info from the request. These are usually the same, 
but in some cases they
+     * are not.
+     * </p>
+     * <p>
+     * One case where they are known to differ is when a request for a 
directory is forwarded by the
+     * servlet container to a welcome file. In that case, [EMAIL PROTECTED] 
HttpServletRequest#getRequestURI()}
+     * returns the path that was actually requested (e.g., [EMAIL PROTECTED] 
"/"}), whereas the servlet path
+     * plus path info is the path to the welcome file (e.g. [EMAIL PROTECTED] 
"/index.jsp"}).
+     * </p>
+     */
+    public static String getRequestedPath(HttpServletRequest request) {
+        String servletPath, pathInfo;
+
+        // Check to see if the request is processing an include, and pull the 
path
+        // information from the appropriate source.
+        servletPath = (String) 
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH);
+        if (servletPath != null) {
+            pathInfo = (String) 
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH_INFO);
+        }
+        else {
+            servletPath = request.getServletPath();
+            pathInfo = request.getPathInfo();
+        }
+
+        if (servletPath == null)
+            return pathInfo == null ? "" : pathInfo;
+        else if (pathInfo == null)
+            return servletPath;
+        else
+            return servletPath + pathInfo;
+    }
+
+    /** No instances */
+    private HttpUtil() {
+    }
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to