cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdami...@apache.org
Subject svn commit: r1303826 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon: components/treeprocessor/ConcreteTreeProcessor.java environment/wrapper/EnvironmentWrapper.java
Date Thu, 22 Mar 2012 15:12:52 GMT
Author: cdamioli
Date: Thu Mar 22 15:12:51 2012
New Revision: 1303826

URL: http://svn.apache.org/viewvc?rev=1303826&view=rev
Log:
COCOON-2321 Unable to permanently redirect the client (eg. with an HTTP code 301) from inside
a cocoon:// redirection

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=1303826&r1=1303825&r2=1303826&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
Thu Mar 22 15:12:51 2012
@@ -35,6 +35,7 @@ import org.apache.cocoon.components.Coco
 import org.apache.cocoon.components.pipeline.ProcessingPipeline;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ForwardRedirector;
+import org.apache.cocoon.environment.PermanentRedirector;
 import org.apache.cocoon.environment.Redirector;
 import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
 import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
@@ -300,8 +301,15 @@ public class ConcreteTreeProcessor exten
         if ( facade != null ) {
             newEnv = facade.getDelegate();
         }
-        if ( ((ForwardEnvironmentWrapper)newEnv).getRedirectURL() != null ) {
-            environment.redirect( false, ((ForwardEnvironmentWrapper)newEnv).getRedirectURL()
);
+        
+        ForwardEnvironmentWrapper forwardEnv = (ForwardEnvironmentWrapper) newEnv;
+        if (forwardEnv.hasRedirected()) {
+            if (forwardEnv.isPermanentRedirection() && environment instanceof PermanentRedirector)
{
+                ((PermanentRedirector )environment).permanentRedirect(false, forwardEnv.getRedirectURL());
+            }
+            else {
+                environment.redirect( false, forwardEnv.getRedirectURL() );
+            }
         }
         return result;
     }

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java?rev=1303826&r1=1303825&r2=1303826&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
Thu Mar 22 15:12:51 2012
@@ -29,6 +29,8 @@ import org.apache.cocoon.Constants;
 import org.apache.cocoon.environment.AbstractEnvironment;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.PermanentRedirector;
+import org.apache.cocoon.environment.Redirector;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Response;
 import org.apache.cocoon.util.BufferedOutputStream;
@@ -42,7 +44,7 @@ import org.apache.cocoon.util.BufferedOu
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * @version $Id$
  */
-public class EnvironmentWrapper extends AbstractEnvironment {
+public class EnvironmentWrapper extends AbstractEnvironment implements Redirector, PermanentRedirector
{
 
     /** The wrapped environment */
     protected Environment environment;
@@ -52,7 +54,7 @@ public class EnvironmentWrapper extends 
 
     /** The redirect url */
     protected String redirectURL;
-
+    
     /** The request object */
     protected Request request;
 
@@ -63,6 +65,10 @@ public class EnvironmentWrapper extends 
 
     protected boolean internalRedirect = false;
 
+    protected boolean hasRedirected;
+
+    protected boolean permanentRedirection;
+
     /**
      * Constructs an EnvironmentWrapper object from a Request
      * and Response objects
@@ -267,6 +273,7 @@ public class EnvironmentWrapper extends 
     public void redirect(boolean sessionmode, String newURL)
     throws IOException {
         this.redirectURL = newURL;
+        this.hasRedirected = true;
 
         // check if session mode shall be activated
         if (sessionmode) {
@@ -276,6 +283,31 @@ public class EnvironmentWrapper extends 
     }
 
     /**
+     * Permanentlty redirect the client to a new URL is not allowed
+     */
+    public void permanentRedirect(boolean sessionmode, String newURL)
+    throws IOException {
+        this.redirect(sessionmode, newURL);
+        this.permanentRedirection = true;
+    }
+    
+    public boolean hasRedirected() {
+        return this.hasRedirected;
+    }
+    
+    /**
+     * Has a permanent redirection been asked
+     */
+    public boolean isPermanentRedirection() {
+        return this.permanentRedirection;
+    }
+    
+    public void sendStatus(int sc) {
+        this.setStatus(sc);
+        this.hasRedirected = true;
+    }
+
+    /**
      * Redirect in the first non-wrapped environment
      */
     public void globalRedirect(boolean sessionmode, String newURL)



Mime
View raw message