Revision: 342
Author:   tfenne
Date:     2006-07-07 17:12:11 -0700 (Fri, 07 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/stripes/?rev=342&view=rev

Log Message:
-----------
Fix for STS-91: Support for included paths.  The ActionResolver will not detect 
if it is being invoked for an include and use the included path instead.  Due 
to servlet container inconsistencies the ForwardResolution will also perform an 
Include if it's running inside of an include.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/action/ForwardResolution.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
    trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java
Modified: 
trunk/stripes/src/net/sourceforge/stripes/action/ForwardResolution.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/action/ForwardResolution.java     
2006-07-06 15:05:43 UTC (rev 341)
+++ trunk/stripes/src/net/sourceforge/stripes/action/ForwardResolution.java     
2006-07-08 00:12:11 UTC (rev 342)
@@ -14,21 +14,32 @@
  */
 package net.sourceforge.stripes.action;
 
+import net.sourceforge.stripes.controller.StripesConstants;
 import net.sourceforge.stripes.util.Log;
 
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.ServletException;
 import java.io.IOException;
 
 /**
- * Resolution that uses the Servlet API to <em>forward</em> the user to 
another path within the
- * same web application using a server side forward.
+ * <p>Resolution that uses the Servlet API to <em>forward</em> the user to 
another path within the
+ * same web application using a server side forward.</p>
  *
+ * <p>There is one case when this resolution will issue an include instead of 
a forward. The
+ * Servlet specification is ambiguous about what should happen when a forward 
is issued inside
+ * of an include. The behaviour varies widely by container, from outputting 
only the content
+ * of the forward, to only the content prior to the include!  To make this 
behaviour more
+ * consistent the ForwardResolution will automatically determine if it is 
executing inside of
+ * an include, and if that is the case it will <i>include</i> the appropriate 
URL instead of
+ * <i>forwarding</i> to it. This behaviour can be turned off be calling
+ * [EMAIL PROTECTED] autoInclude(false)}.</p>
+ *
  * @see RedirectResolution
  * @author Tim Fennell
  */
 public class ForwardResolution extends OnwardResolution<ForwardResolution> 
implements Resolution {
+    private boolean autoInclude = true;
     private static final Log log = Log.getInstance(ForwardResolution.class);
 
     /**
@@ -63,6 +74,17 @@
     }
 
     /**
+     * If true then the ForwardResolution will automatically detect when it is 
executing
+     * as part of a server-side Include and <i>include</i> the supplied URL 
instead of
+     * forwarding to it.  Defaults to true.
+     *
+     * @param auto whether or not to automatically detect and use includes
+     */
+    public void autoInclude(boolean auto) {
+        this.autoInclude = auto;
+    }
+
+    /**
      * Attempts to forward the user to the specified path.
      * @throws ServletException thrown when the Servlet container encounters 
an error
      * @throws IOException thrown when the Servlet container encounters an 
error
@@ -71,8 +93,15 @@
         throws ServletException, IOException {
 
         String path = getUrl();
-        log.trace("Forwarding to path: ", path);
 
-        request.getRequestDispatcher(path).forward(request, response);
+        // Figure out if we're inside an include, and use an include instead 
of a forward
+        if (autoInclude && 
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH) != null) {
+            log.trace("Including URL: ", path);
+            request.getRequestDispatcher(path).include(request, response);
+        }
+        else {
+            log.trace("Forwarding to URL: ", path);
+            request.getRequestDispatcher(path).forward(request, response);
+        }
     }
 }

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2006-07-06 15:05:43 UTC (rev 341)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2006-07-08 00:12:11 UTC (rev 342)
@@ -269,8 +269,19 @@
      * @return the servlet-context relative path that is being requested
      */
     protected String getRequestedPath(HttpServletRequest request) {
-        String servletPath = request.getServletPath();
-        String pathInfo    = request.getPathInfo();
+        String servletPath = null, pathInfo = null;
+
+        // Check to see if the request is processing an include, and pull the 
path
+        // information from the appropriate source.
+        if (request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH) != 
null) {
+            servletPath = (String) 
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH);
+            pathInfo    = (String) 
request.getAttribute(StripesConstants.REQ_ATTR_INCLUDE_PATH_INFO);
+        }
+        else {
+            servletPath = request.getServletPath();
+            pathInfo    = request.getPathInfo();
+        }
+
         return (servletPath == null ? "" : servletPath) + (pathInfo == null ? 
"" : pathInfo);
     }
 

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java  
2006-07-06 15:05:43 UTC (rev 341)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java  
2006-07-08 00:12:11 UTC (rev 342)
@@ -63,4 +63,16 @@
      */
     String REQ_ATTR_FLASH_SCOPE_LOCATION = "__flash_scopes";
 
+    /**
+     * Request attribute key defined by the servlet spec for storing the 
included servlet
+     * path when processing a server side include.
+     */
+    String REQ_ATTR_INCLUDE_PATH = "javax.servlet.include.servlet_path";
+
+    /**
+     * Request attribute key defined by the servlet spec for storing the 
included path
+     * info when processing a server side include.
+     */
+    String REQ_ATTR_INCLUDE_PATH_INFO = "javax.servlet.include.path_info";
+
 }


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


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
Stripes-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to