You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/06/23 17:51:10 UTC

svn commit: r787735 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/converter/jaxp/ main/java/org/apache/camel/impl/ main/java/org/apache/camel/processor/validation/ test/java/org/apache/camel/impl/

Author: davsclaus
Date: Tue Jun 23 15:51:10 2009
New Revision: 787735

URL: http://svn.apache.org/viewvc?rev=787735&view=rev
Log:
CAMEL-1744: ScheduledPollingConsumer do not throw exception on stop that occured during polling. Fixed CS.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/DefaultValidationErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatorErrorHandler.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MockScheduledPollConsumer.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Tue Jun 23 15:51:10 2009
@@ -27,6 +27,7 @@
 import java.lang.reflect.Constructor;
 import java.nio.ByteBuffer;
 import java.util.Properties;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -43,9 +44,6 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.camel.Converter;
-import org.apache.camel.Exchange;
-import org.apache.camel.util.ObjectHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -53,6 +51,9 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * A helper class to transform to and from various JAXB types such as {@link Source} and {@link Document}

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java Tue Jun 23 15:51:10 2009
@@ -38,7 +38,6 @@
 
     private final ScheduledExecutorService executor;
     private ScheduledFuture<?> future;
-    private Exception firstExceptionThrown;
 
     // if adding more options then align with ScheduledPollEndpoint#configureScheduledPollConsumerProperties
     private long initialDelay = 1000;
@@ -80,9 +79,6 @@
             }
         } catch (Exception e) {
             LOG.warn("An exception occurred while polling: " + this.getEndpoint() + ": " + e.getMessage(), e);
-            if (firstExceptionThrown == null) {
-                firstExceptionThrown = e;
-            }
         }
 
         if (LOG.isTraceEnabled()) {
@@ -136,7 +132,6 @@
 
     @Override
     protected void doStart() throws Exception {
-        firstExceptionThrown = null;
         super.doStart();
         if (isUseFixedDelay()) {
             future = executor.scheduleWithFixedDelay(this, getInitialDelay(), getDelay(), getTimeUnit());
@@ -151,9 +146,5 @@
             future.cancel(false);
         }
         super.doStop();
-
-        if (firstExceptionThrown != null) {
-            throw firstExceptionThrown;
-        }
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/DefaultValidationErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/DefaultValidationErrorHandler.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/DefaultValidationErrorHandler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/DefaultValidationErrorHandler.java Tue Jun 23 15:51:10 2009
@@ -22,12 +22,13 @@
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.validation.Schema;
 
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.ValidationException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 
 /**
  * A default error handler which just stores all the errors so they can be reported or transformed.

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java Tue Jun 23 15:51:10 2009
@@ -28,9 +28,10 @@
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
+import org.xml.sax.SAXException;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.xml.sax.SAXException;
 
 /**
  * A processor which validates the XML version of the inbound message body

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatorErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatorErrorHandler.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatorErrorHandler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatorErrorHandler.java Tue Jun 23 15:51:10 2009
@@ -19,9 +19,10 @@
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.validation.Schema;
 
+import org.xml.sax.ErrorHandler;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.ValidationException;
-import org.xml.sax.ErrorHandler;
 
 /**
  * Validator error handler.

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MockScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MockScheduledPollConsumer.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MockScheduledPollConsumer.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MockScheduledPollConsumer.java Tue Jun 23 15:51:10 2009
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.impl;
 
 import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -42,4 +41,7 @@
         }
     }
 
+    public void setExceptionToThrowOnPoll(Exception exceptionToThrowOnPoll) {
+        this.exceptionToThrowOnPoll = exceptionToThrowOnPoll;
+    }
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java?rev=787735&r1=787734&r2=787735&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java Tue Jun 23 15:51:10 2009
@@ -16,46 +16,33 @@
  */
 package org.apache.camel.impl;
 
-import junit.framework.Assert;
 import org.apache.camel.ContextTestSupport;
 
 public class ScheduledPollConsumerTest extends ContextTestSupport {
     
-    public void testExceptionOnPollGetsThrownOnShutdown() throws Exception {
+    public void testExceptionOnPollAndCanStartAgain() throws Exception {
         Exception expectedException = new Exception("Hello, I should be thrown on shutdown only!");
-        Exception actualException = null;
         MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(expectedException);
 
         consumer.start();
-        // exception is caught and saved
-        consumer.run(); 
-        
-        try {
-            // exception should be thrown
-            consumer.stop();           
-        } catch (Exception e) {
-            actualException = e;
-        }
-        
-        // make sure its the right exception!
-        Assert.assertEquals(expectedException, actualException);
+        // poll that throws an exception
+        consumer.run();
+        consumer.stop();
+
+        // prepare for 2nd run but this time it should not thrown an exception on poll
+        consumer.setExceptionToThrowOnPoll(null);
+        // start it again and we should be able to run
+        consumer.start();
+        consumer.run();
+        // should be able to stop with no problem
+        consumer.stop();
     }
     
-    public void testNoExceptionOnPollAndNoneThrownOnShutdown() throws Exception {
-        Exception actualException = null;
+    public void testNoExceptionOnPoll() throws Exception {
         MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(null);
-
         consumer.start();
         consumer.run(); 
-        
-        try {
-            // exception should not be thrown
-            consumer.stop();           
-        } catch (Exception e) {
-            actualException = e;
-        }
-        
-        // make sure no exception was thrown
-        Assert.assertEquals(null, actualException);
+        consumer.stop();
     }
+
 }