Return-Path: X-Original-To: apmail-cocoon-cvs-archive@www.apache.org Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CDB1495B2 for ; Thu, 22 Mar 2012 15:13:13 +0000 (UTC) Received: (qmail 56326 invoked by uid 500); 22 Mar 2012 15:13:13 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 56275 invoked by uid 500); 22 Mar 2012 15:13:13 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 56268 invoked by uid 99); 22 Mar 2012 15:13:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2012 15:13:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2012 15:13:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 28DD02388847 for ; Thu, 22 Mar 2012 15:12:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cvs@cocoon.apache.org From: cdamioli@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120322151252.28DD02388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Carsten Ziegeler * @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)