cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r669178 - /cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
Date Wed, 18 Jun 2008 14:22:26 GMT
Author: reinhard
Date: Wed Jun 18 07:22:26 2008
New Revision: 669178

URL: http://svn.apache.org/viewvc?rev=669178&view=rev
Log:
. special support of servlet: URIs in redirect-to elements

Modified:
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java?rev=669178&r1=669177&r2=669178&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/component/RedirectorComponent.java
Wed Jun 18 07:22:26 2008
@@ -19,7 +19,9 @@
 package org.apache.cocoon.corona.servlet.component;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URL;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
@@ -27,11 +29,16 @@
 import org.apache.cocoon.corona.pipeline.component.Finisher;
 import org.apache.cocoon.corona.pipeline.component.Starter;
 import org.apache.cocoon.corona.servlet.util.HttpContextHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class RedirectorComponent implements Starter, Finisher {
 
+    private final Log logger = LogFactory.getLog(this.getClass());
+
     private Map<String, Object> parameters;
     private String uri;
+    private OutputStream outputStream;
 
     /**
      * {@inheritDoc}
@@ -42,9 +49,24 @@
         HttpServletResponse response = HttpContextHelper.getResponse(this.parameters);
 
         try {
-            String location = response.encodeRedirectURL(this.uri);
-            response.sendRedirect(location);
+            if (this.uri.startsWith("servlet:")) {
+                InputStream inputStream = new URL(this.uri).openStream();
+                byte[] data = new byte[1024];
+                while (true) {
+                    int bytesRead = inputStream.read(data, 0, data.length);
+
+                    if (bytesRead == -1) {
+                        break;
+                    }
+
+                    this.outputStream.write(data, 0, bytesRead);
+                }
+            } else {
+                String location = response.encodeRedirectURL(this.uri);
+                response.sendRedirect(location);
+            }
         } catch (IOException e) {
+            this.logger.error("Can't redirect to " + this.uri, e);
             throw new RuntimeException(e);
         }
     }
@@ -72,6 +94,7 @@
      * @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
      */
     public void setOutputStream(OutputStream outputStream) {
+        this.outputStream = outputStream;
     }
 
     /**



Mime
View raw message