incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1004557 - in /sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter: Processor.java ProcessorManager.java impl/ProcessorManagerImpl.java impl/RewriterResponse.java
Date Tue, 05 Oct 2010 07:50:41 GMT
Author: cziegeler
Date: Tue Oct  5 07:50:41 2010
New Revision: 1004557

URL: http://svn.apache.org/viewvc?rev=1004557&view=rev
Log:
Throw SlingException if pipeline could not be setup. IOExceptions might be swallowed and a
wrong configuration is a hard setup error!

Modified:
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Processor.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessorManager.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Processor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Processor.java?rev=1004557&r1=1004556&r2=1004557&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Processor.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/Processor.java
Tue Oct  5 07:50:41 2010
@@ -30,6 +30,7 @@ public interface Processor {
      * Initialize this component.
      * @param context The invocation context.
      * @param config The configuration for this component.
+     * @throws IOException If an error occurs
      */
     void init(ProcessingContext context,
               ProcessorConfiguration config)

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessorManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessorManager.java?rev=1004557&r1=1004556&r2=1004557&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessorManager.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessorManager.java
Tue Oct  5 07:50:41 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.sling.rewriter;
 
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -32,8 +31,8 @@ public interface ProcessorManager {
 
     /**
      * Return a pipeline for a pipeline configuration.
+     * @throws org.apache.sling.api.SlingException If an error occurs during setup
      */
     Processor getProcessor(ProcessorConfiguration configuration,
-                           ProcessingContext       context)
-    throws IOException;
+                           ProcessingContext       context);
 }

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java?rev=1004557&r1=1004556&r2=1004557&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorManagerImpl.java
Tue Oct  5 07:50:41 2010
@@ -32,6 +32,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.SlingConstants;
+import org.apache.sling.api.SlingException;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -429,8 +430,7 @@ public class ProcessorManagerImpl
      * @see org.apache.sling.rewriter.ProcessorManager#getProcessor(org.apache.sling.rewriter.ProcessorConfiguration,
org.apache.sling.rewriter.ProcessingContext)
      */
     public Processor getProcessor(ProcessorConfiguration configuration,
-                                  ProcessingContext      context)
-    throws IOException {
+                                  ProcessingContext      context) {
         if ( configuration == null ) {
             throw new IllegalArgumentException("Processor configuration is missing.");
         }
@@ -443,14 +443,18 @@ public class ProcessorManagerImpl
         } else {
             isPipeline = configuration instanceof PipelineConfiguration;
         }
-        if ( isPipeline ) {
-            final PipelineImpl pipeline = new PipelineImpl(this.factoryCache);
-            pipeline.init(context, configuration);
-            return pipeline;
-        }
-        final Processor processor = new ProcessorWrapper(configuration, this.factoryCache);
-        processor.init(context, configuration);
-        return processor;
+        try {
+            if ( isPipeline ) {
+                final PipelineImpl pipeline = new PipelineImpl(this.factoryCache);
+                pipeline.init(context, configuration);
+                return pipeline;
+            }
+            final Processor processor = new ProcessorWrapper(configuration, this.factoryCache);
+            processor.init(context, configuration);
+            return processor;
+        } catch (final IOException ioe) {
+            throw new SlingException("Unable to setup processor: " + ioe.getMessage(), ioe);
+        }
     }
 
     /**

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java?rev=1004557&r1=1004556&r2=1004557&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
Tue Oct  5 07:50:41 2010
@@ -141,11 +141,7 @@ class RewriterResponse
      */
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
         if ( type == ContentHandler.class ) {
-            try {
-                this.processor = this.getProcessor();
-            } catch (IOException e) {
-                throw new SlingException("Unable to setup pipeline: " + e.getMessage(), e);
-            }
+            this.processor = this.getProcessor();
             if ( this.processor != null ) {
                 @SuppressWarnings("unchecked")
                 final AdapterType object = (AdapterType)this.processor.getContentHandler();
@@ -158,19 +154,27 @@ class RewriterResponse
     /**
      * Search the first matching processor
      */
-    private Processor getProcessor() throws IOException {
-        this.request.getRequestProgressTracker().log("Searching processor");
+    private Processor getProcessor() {
         final ProcessingContext processorContext = new ServletProcessingContext(this.request,
this, this.getSlingResponse(), this.contentType);
         Processor found = null;
         final List<ProcessorConfiguration> processorConfigs = this.processorManager.getProcessorConfigurations();
         final Iterator<ProcessorConfiguration> i = processorConfigs.iterator();
         while ( found == null && i.hasNext() ) {
             final ProcessorConfiguration config = i.next();
-            this.request.getRequestProgressTracker().log("Checking processor {0}", config);
             if ( config.match(processorContext) ) {
-                this.request.getRequestProgressTracker().log("Settimg up processor {0}",
config);
-                found = this.processorManager.getProcessor(config, processorContext);
-                this.request.getRequestProgressTracker().log("Found processor for post processing
{0}", config);
+                try {
+                    found = this.processorManager.getProcessor(config, processorContext);
+                    this.request.getRequestProgressTracker().log("Found processor for post
processing {0}", config);
+                } catch (final SlingException se) {
+                    // if an exception occurs during setup of the pipeline and we are currently
+                    // already processing an error, we ignore this!
+                    if ( processorContext.getRequest().getAttribute("javax.servlet.error.status_code")
!= null ) {
+                        this.request.getRequestProgressTracker().log("Ignoring found processor
for post processing {0}" +
+                                " as an error occured ({1}) during setup while processing
another error.", config, se);
+                    } else {
+                        throw se;
+                    }
+                }
             }
         }
         return found;



Mime
View raw message