cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r687706 - in /cocoon/trunk/core: cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/ cocoon-sitemap/cocoon-sitemap-impl/src/ma...
Date Thu, 21 Aug 2008 10:51:10 GMT
Author: gkossakowski
Date: Thu Aug 21 03:51:09 2008
New Revision: 687706

URL: http://svn.apache.org/viewvc?rev=687706&view=rev
Log:
Introduce support servlet: protocol in flow's sendPage function.

The previous behaviour was that if one called sendPage("some/path") it would be translated
into redirection to "cocoon:/some/path" so any custom protocol was disallowed in sendPage
calls.
Now default behaviour is preserved but additionally one can use servlet: protocol explicitly
in sendPage calls.

In order to achieve that some extensions to ForwardRedirector and ConcreteTreeProcessor were
introduced for special handling of "servlet:" protocol.
Current implementation does not really redirect in sense of Cocoon's internals but just makes
a new request using ServletSource and after processing is finished it just copies the response
to current environment.

As consequence of this change, also <map:redirect-to uri="servlet:/some/path"/> is supported.

This change resolves COCOON-2239 issue.

Modified:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java

Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java?rev=687706&r1=687705&r2=687706&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java
(original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java
Thu Aug 21 03:51:09 2008
@@ -32,6 +32,8 @@
  */
 public abstract class ForwardRedirector extends AbstractLogEnabled
                                         implements Redirector, PermanentRedirector {
+	
+	private static final String SERVLET_PROTOCOL = "servlet:";
 
     /**
      * Was there a call to <code>redirect()</code> ?
@@ -60,6 +62,8 @@
 
         if (url.startsWith("cocoon:")) {
             cocoonRedirect(url);
+        } else if (url.startsWith(SERVLET_PROTOCOL)) {
+            servletRedirect(url);
         } else {
             this.doRedirect(sessionMode, url, false, false);
         }
@@ -74,6 +78,8 @@
 
         if (url.startsWith("cocoon:")) {
             cocoonRedirect(url);
+        } else if (url.startsWith(SERVLET_PROTOCOL)) {
+            servletRedirect(url);
         } else {
             this.doRedirect(sessionMode, url, true, false);
         }
@@ -93,6 +99,8 @@
         // FIXME : how to handle global redirect to cocoon: ?
         if (url.startsWith("cocoon:")) {
             cocoonRedirect(url);
+        } else if (url.startsWith(SERVLET_PROTOCOL)) {
+            throw new ProcessingException("Global redirect with servlet: protocol are not
possible!");
         } else {
             this.doRedirect(sessionMode, url, false, true);
         }
@@ -100,6 +108,14 @@
     }
 
     protected abstract void cocoonRedirect(String uri) throws IOException, ProcessingException;
+    
+    /**
+     * Handles rediraction to <code>servlet:</code> protocol URI.
+     * @param uri starting with <code>servlet:</code>
+     * @throws IOException
+     * @throws ProcessingException
+     */
+    protected abstract void servletRedirect(String uri) throws IOException, ProcessingException;
 
     /* (non-Javadoc)
      * @see org.apache.cocoon.environment.Redirector#hasRedirected()

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java?rev=687706&r1=687705&r2=687706&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
Thu Aug 21 03:51:09 2008
@@ -199,6 +199,14 @@
             // this is a hint for the redirector
             objectModel.put("cocoon:forward", "true");
             redirector.redirect(false, uri);
+        } if (SourceUtil.getScheme(uri).equals("servlet")) {
+            if (redirector.hasRedirected()) {
+                throw new IllegalStateException("Pipeline has already been processed for
this request");
+            }
+            final Map objectModel = this.processInfoProvider.getObjectModel();
+            FlowHelper.setWebContinuation(objectModel, newObjectModel, continuation);
+            FlowHelper.setContextObject(objectModel, newObjectModel, bizData);
+            redirector.redirect(false, uri);
         } else {
             throw new Exception("uri is not allowed to contain a scheme (cocoon:/ is always
automatically used)");
         }

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?rev=687706&r1=687705&r2=687706&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
Thu Aug 21 03:51:09 2008
@@ -24,11 +24,8 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.web.context.WebApplicationContext;
-
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.Processor;
 import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
@@ -50,6 +47,11 @@
 import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.cocoon.util.location.Location;
 import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
 
 /**
  * The concrete implementation of {@link Processor}, containing the evaluation tree and associated
@@ -322,6 +324,21 @@
         }
         return result;
     }
+    
+    protected boolean handleServletRedirect(String uri, Environment environment) throws IOException,
ProcessingException {
+        SourceFactory sourceFactory;
+        try {
+            sourceFactory = (SourceFactory) this.manager.lookup("org.apache.excalibur.source.SourceFactory/servlet");
+        } catch (ServiceException e) {
+            throw new ProcessingException("Could not find ServletSourceFactory. Are you trying
to use servlet: source " +
+                    "without using Servlet Service Framework (components)?", e);
+        }
+
+        Source source = sourceFactory.getSource(uri, null);
+        org.apache.commons.io.IOUtils.copy(source.getInputStream(), environment.getOutputStream(0));
+
+        return true;
+    }
 
     /**
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
@@ -374,6 +391,11 @@
                 throw new ProcessingException(e);
             }
         }
+
+        protected void servletRedirect(String uri) throws IOException, ProcessingException
{
+            handleServletRedirect(uri, this.env);
+        }
+
     }
 
     public SourceResolver getSourceResolver() {



Mime
View raw message