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/03/23 07:22:34 UTC

svn commit: r757326 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/main/...

Author: davsclaus
Date: Mon Mar 23 06:22:33 2009
New Revision: 757326

URL: http://svn.apache.org/viewvc?rev=757326&view=rev
Log:
CAMEL-1478, CAMEL-1477: Added rollback DSL. Fixed RouteBuildrRef in Spring DSL. Removed autowireRouteBuilders option.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RollbackDefinition.java
      - copied, changed from r757142, camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java   (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRollbackTest.java
      - copied, changed from r757142, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDelayerTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/rollback.xml
      - copied, changed from r757142, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java
      - copied, changed from r757142, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpWithRollbackRoute.java
      - copied, changed from r757142, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest-context.xml
      - copied, changed from r757142, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml
Removed:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AutoRegisteredRouteBuilderTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/autoRegisteredRouteBuilder.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/PollingConsumerSupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
    camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/routeBuilderRef.xml
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Mon Mar 23 06:22:33 2009
@@ -68,6 +68,7 @@
     String TIMER_TIME = "CamelTimerTime";
 
     String TRANSACTED = "CamelTransacted";
+    String ROLLBACK_ONLY = "CamelRollbackOnly";
 
     /**
      * Returns the {@link ExchangePattern} (MEP) of this exchange.
@@ -216,6 +217,11 @@
     boolean isTransacted();
 
     /**
+     * Returns true if this exchange is marked for rollback
+     */
+    boolean isRollbackOnly();
+
+    /**
      * Returns the container so that a processor can resolve endpoints from URIs
      *
      * @return the container which owns this exchange

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java?rev=757326&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java Mon Mar 23 06:22:33 2009
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel;
+
+/**
+ * Exception used for forcing an Exchange to be rolled back.
+ *
+ * @version $Revision$
+ */
+public class RollbackExchangeException extends Exception {
+
+    public RollbackExchangeException(Exchange exchange) {
+        super("Intended rollback on exchange: " + exchange);
+    }
+
+    public RollbackExchangeException(Exchange exchange, Throwable cause) {
+        super("Intended rollback on exchange: " + exchange, cause);
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/RollbackExchangeException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Mon Mar 23 06:22:33 2009
@@ -29,7 +29,6 @@
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.UuidGenerator;
-import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
 
 /**
  * A default implementation of {@link Exchange}
@@ -248,19 +247,6 @@
         this.fromEndpoint = fromEndpoint;
     }
 
-    public void throwException() throws Exception {
-        if (exception == null) {
-            return;
-        }
-        if (exception instanceof RuntimeException) {
-            throw (RuntimeException)exception;
-        }
-        if (exception instanceof Exception) {
-            throw (Exception)exception;
-        }
-        throw wrapRuntimeCamelException(exception);
-    }
-
     public Message getFault() {
         return getFault(true);
     }
@@ -305,6 +291,11 @@
         return transacted != null && transacted;
     }
 
+    public boolean isRollbackOnly() {
+        Boolean rollback = getProperty(ROLLBACK_ONLY, Boolean.class);
+        return rollback != null && rollback;
+    }
+
     public UnitOfWork getUnitOfWork() {
         return unitOfWork;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/LoggingExceptionHandler.java Mon Mar 23 06:22:33 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.impl;
 
 import org.apache.camel.LoggingLevel;
+import org.apache.camel.RollbackExchangeException;
 import org.apache.camel.processor.Logger;
 import org.apache.camel.spi.ExceptionHandler;
 import org.apache.commons.logging.LogFactory;
@@ -39,6 +40,11 @@
     }
 
     public void handleException(Throwable exception) {
-        logger.log(exception.getMessage(), exception);
+        if (exception instanceof RollbackExchangeException) {
+            // do not log stacktrace for intended rollbacks
+            logger.log(exception.getMessage());
+        } else {
+            logger.log(exception.getMessage(), exception);
+        }
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/PollingConsumerSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/PollingConsumerSupport.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/PollingConsumerSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/PollingConsumerSupport.java Mon Mar 23 06:22:33 2009
@@ -35,7 +35,7 @@
 
     @Override
     public String toString() {
-        return "PullConsumer on " + endpoint;
+        return "PollingConsumer on " + endpoint;
     }
 
     public Endpoint getEndpoint() {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Mon Mar 23 06:22:33 2009
@@ -1070,6 +1070,21 @@
     }
 
     /**
+     * Marks the exchange for rollback only.
+     * <p/>
+     * This is done by setting a {@link org.apache.camel.RollbackExchangeException} on the Exchange
+     * and mark it for rollback.
+     *
+     * @return the builder
+     */
+    @SuppressWarnings("unchecked")
+    public Type rollback() {
+        RollbackDefinition answer = new RollbackDefinition();
+        addOutput(answer);
+        return (Type) this;
+    }
+
+    /**
      * <a href="http://camel.apache.org/wiretap.html">WireTap EIP:</a>
      * Sends messages to all its child outputs; so that each processor and
      * destination gets a copy of the original message to avoid the processors

Copied: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RollbackDefinition.java (from r757142, camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultDefinition.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RollbackDefinition.java?p2=camel/trunk/camel-core/src/main/java/org/apache/camel/model/RollbackDefinition.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultDefinition.java&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ThrowFaultDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RollbackDefinition.java Mon Mar 23 06:22:33 2009
@@ -28,67 +28,32 @@
 import org.apache.camel.CamelException;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.ThrowFaultProcessor;
+import org.apache.camel.processor.RollbackProcessor;
 import org.apache.camel.spi.RouteContext;
 
 /**
- * Represents an XML &lt;throwFault/&gt; element
+ * Represents an XML &lt;rollback/&gt; element
  */
-@XmlRootElement(name = "throwFault")
+@XmlRootElement(name = "rollback")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class ThrowFaultDefinition extends ProcessorDefinition<ThrowFaultDefinition> {
-    @XmlTransient
-    private Throwable fault;
-    @XmlTransient
-    private Processor processor;
-    @XmlAttribute (required = true)
-    private String faultRef;
+public class RollbackDefinition extends ProcessorDefinition<RollbackDefinition> {
 
-    public ThrowFaultDefinition() {
+    public RollbackDefinition() {
     }
 
     @Override
     public String getShortName() {
-        return "throwFault";
+        return "rollback";
     }
 
     @Override
     public String toString() {
-        if (faultRef != null) {
-            return "ThrowFault[ref: " + faultRef + "]";
-        } else {
-            return "ThrowFault[" + fault.getClass().getCanonicalName();
-        }
-    }
-
-    public void setFault(Throwable fault) {
-        this.fault = fault;
-    }
-
-    public Throwable getFault() {
-        return fault;
-    }
-
-    public void setFaultRef(String ref) {
-        this.faultRef = ref;
-    }
-
-    public String getFaultRef() {
-        return faultRef;
+        return "Rollback";
     }
 
     @Override
     public Processor createProcessor(RouteContext routeContext) {
-        if (processor == null) {
-            if (fault == null) {
-                fault = routeContext.lookup(faultRef, Throwable.class);
-                if (fault == null) {
-                    // can't find the fault instance, create a new one
-                    fault = new CamelException(faultRef);
-                }
-            }
-            processor = new ThrowFaultProcessor(fault);
-        }
-        return processor;
+        return new RollbackProcessor();
     }
 
     @Override
@@ -96,4 +61,4 @@
     public List<ProcessorDefinition> getOutputs() {
         return Collections.EMPTY_LIST;
     }
-}
+}
\ No newline at end of file

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DeadLetterChannel.java Mon Mar 23 06:22:33 2009
@@ -185,13 +185,7 @@
 
             // if we are redelivering then sleep before trying again
             if (data.redeliveryCounter > 0) {
-                // okay we will give it another go so clear the exception so we can try again
-                if (exchange.getException() != null) {
-                    exchange.setException(null);
-                }
-
-                // reset cached streams so they can be read again
-                MessageHelper.resetStreamCache(exchange.getIn());
+                prepareExchangeForRedelivery(exchange);
 
                 // wait until we should redeliver
                 try {
@@ -272,10 +266,8 @@
         // process the next try
         // if we are redelivering then sleep before trying again
         if (data.redeliveryCounter > 0) {
-            // okay we will give it another go so clear the exception so we can try again
-            if (exchange.getException() != null) {
-                exchange.setException(null);
-            }
+            prepareExchangeForRedelivery(exchange);
+
             // wait until we should redeliver using a timer to avoid thread blocking
             data.redeliveryDelay = data.currentRedeliveryPolicy.calculateRedeliveryDelay(data.redeliveryDelay, data.redeliveryCounter);
             REDELIVER_TIMER.schedule(new RedeliverTimerTask(exchange, callback, data), data.redeliveryDelay);
@@ -284,7 +276,64 @@
             deliverToRedeliveryProcessor(exchange, callback, data);
         }
     }
-    
+
+    // Properties
+    // -------------------------------------------------------------------------
+
+    /**
+     * Returns the output processor
+     */
+    public Processor getOutput() {
+        return output;
+    }
+
+    /**
+     * Returns the dead letter that message exchanges will be sent to if the
+     * redelivery attempts fail
+     */
+    public Processor getDeadLetter() {
+        return deadLetter;
+    }
+
+    public RedeliveryPolicy getRedeliveryPolicy() {
+        return redeliveryPolicy;
+    }
+
+    /**
+     * Sets the redelivery policy
+     */
+    public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) {
+        this.redeliveryPolicy = redeliveryPolicy;
+    }
+
+    public Logger getLogger() {
+        return logger;
+    }
+
+    /**
+     * Sets the logger strategy; which {@link Log} to use and which
+     * {@link LoggingLevel} to use
+     */
+    public void setLogger(Logger logger) {
+        this.logger = logger;
+    }
+
+    // Implementation methods
+    // -------------------------------------------------------------------------
+
+    private void prepareExchangeForRedelivery(Exchange exchange) {
+        // okay we will give it another go so clear the exception so we can try again
+        if (exchange.getException() != null) {
+            exchange.setException(null);
+        }
+
+        // clear rollback flags
+        exchange.setProperty(Exchange.ROLLBACK_ONLY, null);
+
+        // reset cached streams so they can be read again
+        MessageHelper.resetStreamCache(exchange.getIn());
+    }
+
     private void handleException(Exchange exchange, RedeliveryData data) {
         Throwable e = exchange.getException();
 
@@ -340,7 +389,10 @@
             }
         });
     }
-    
+
+    /**
+     * All redelivery attempts failed so move the exchange to the fault processor (eg the dead letter queue)
+     */
     private boolean deliverToFaultProcessor(final Exchange exchange, final AsyncCallback callback,
                                             final RedeliveryData data) {
         // we did not success with the redelivery so now we let the failure processor handle it
@@ -353,7 +405,7 @@
         boolean sync = afp.process(exchange, new AsyncCallback() {
             public void done(boolean sync) {
                 LOG.trace("Fault processor done");
-                restoreExceptionOnExchange(exchange, data.handledPredicate);
+                prepareExchangeForFailure(exchange, data.handledPredicate);
                 callback.done(data.sync);
             }
         });
@@ -365,52 +417,7 @@
         return sync;
     }
 
-    // Properties
-    // -------------------------------------------------------------------------
-
-    /**
-     * Returns the output processor
-     */
-    public Processor getOutput() {
-        return output;
-    }
-
-    /**
-     * Returns the dead letter that message exchanges will be sent to if the
-     * redelivery attempts fail
-     */
-    public Processor getDeadLetter() {
-        return deadLetter;
-    }
-
-    public RedeliveryPolicy getRedeliveryPolicy() {
-        return redeliveryPolicy;
-    }
-
-    /**
-     * Sets the redelivery policy
-     */
-    public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) {
-        this.redeliveryPolicy = redeliveryPolicy;
-    }
-
-    public Logger getLogger() {
-        return logger;
-    }
-
-    /**
-     * Sets the logger strategy; which {@link Log} to use and which
-     * {@link LoggingLevel} to use
-     */
-    public void setLogger(Logger logger) {
-        this.logger = logger;
-    }
-
-    // Implementation methods
-
-    // -------------------------------------------------------------------------
-
-    protected static void restoreExceptionOnExchange(Exchange exchange, Predicate handledPredicate) {
+    private void prepareExchangeForFailure(Exchange exchange, Predicate handledPredicate) {
         if (handledPredicate == null || !handledPredicate.matches(exchange)) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("This exchange is not handled so its marked as failed: " + exchange);
@@ -432,7 +439,10 @@
         } else {
             newLogLevel = data.currentRedeliveryPolicy.getRetriesExhaustedLogLevel();
         }
-        if (data.currentRedeliveryPolicy.isLogStackTrace() && e != null) {
+        if (exchange.isRollbackOnly()) {
+            // log intented rollback on WARN level
+            logger.log("Intended rollback on exchange: " + exchange, LoggingLevel.WARN);
+        } else if (data.currentRedeliveryPolicy.isLogStackTrace() && e != null) {
             logger.log(message, e, newLogLevel);
         } else {
             logger.log(message, newLogLevel);
@@ -447,7 +457,7 @@
      * Increments the redelivery counter and adds the redelivered flag if the
      * message has been redelivered
      */
-    protected int incrementRedeliveryCounter(Exchange exchange, Throwable e) {
+    private int incrementRedeliveryCounter(Exchange exchange, Throwable e) {
         Message in = exchange.getIn();
         Integer counter = in.getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
         int next = 1;

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java?rev=757326&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java Mon Mar 23 06:22:33 2009
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RollbackExchangeException;
+
+/**
+ * Processor for marking an {@link org.apache.camel.Exchange} to rollback.
+ *
+ * @version $Revision$
+ */
+public class RollbackProcessor implements Processor {
+
+    public void process(Exchange exchange) throws Exception {
+        // mark the exchange for rollback
+        exchange.setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE);
+        exchange.setException(new RollbackExchangeException(exchange));
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RollbackProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index Mon Mar 23 06:22:33 2009
@@ -14,6 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ------------------------------------------------------------------------
+AbstractInterceptorDefinition
 AggregateDefinition
 BeanDefinition
 CatchDefinition
@@ -22,7 +23,6 @@
 DelayDefinition
 DescriptionDefinition
 EnrichDefinition
-OnExceptionDefinition
 ExpressionSubElementDefinition
 FilterDefinition
 FinallyDefinition
@@ -31,13 +31,13 @@
 IdempotentConsumerDefinition
 InOnlyDefinition
 InOutDefinition
-AbstractInterceptorDefinition
 InterceptorDefinition
 InterceptDefinition
 LoadBalanceDefinition
 LoopDefinition
 MarshalDefinition
 MulticastDefinition
+OnExceptionDefinition
 OptionalIdentifiedType
 OtherwiseDefinition
 PipelineDefinition
@@ -49,6 +49,7 @@
 RemoveHeaderDefinition
 RemovePropertyDefinition
 ResequenceDefinition
+RollbackDefinition
 RouteBuilderDefinition
 RouteDefinition
 RoutesDefinition

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java?rev=757326&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java Mon Mar 23 06:22:33 2009
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RollbackExchangeException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class RollbackTest extends ContextTestSupport {
+
+    public void testOk() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.requestBody("direct:start", "ok");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testRollback() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:dead");
+        mock.expectedMessageCount(1);
+
+        getMockEndpoint("mock:rollback").expectedMessageCount(2);
+
+        try {
+            template.requestBody("direct:start", "bad");
+            fail("Should have thrown a RollbackExchangeException");
+        } catch (RuntimeCamelException e) {
+            assertTrue(e.getCause() instanceof RollbackExchangeException);
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testRollbackWithExchange() throws Exception {
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        MockEndpoint mock = getMockEndpoint("mock:rollback");
+        mock.expectedMessageCount(2);
+
+        Exchange out = template.request("direct:start", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("bad");
+            }
+        });
+        assertMockEndpointsSatisfied();
+
+        assertNotNull(out.getException());
+        assertIsInstanceOf(RollbackExchangeException.class, out.getException());
+        assertEquals("Should be marked as rollback", true, out.isRollbackOnly());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(1).delay(0));
+
+                from("direct:start")
+                    .choice()
+                        .when(body().isNotEqualTo("ok"))
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                assertFalse("Rollback flag should have been cleared on redelivery", exchange.isRollbackOnly());
+                            }
+                        })
+                        .to("mock:rollback")
+                        .rollback()
+                    .otherwise()
+                        .to("mock:result")
+                    .end();
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RollbackTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Mar 23 06:22:33 2009
@@ -82,8 +82,6 @@
     private static final Log LOG = LogFactory.getLog(CamelContextFactoryBean.class);
 
     @XmlAttribute(required = false)
-    private Boolean autowireRouteBuilders = Boolean.TRUE;
-    @XmlAttribute(required = false)
     private Boolean trace;
     @XmlAttribute(required = false)
     private Long delay;
@@ -457,14 +455,6 @@
         this.builderRefs = builderRefs;
     }
 
-    /**
-     * If enabled this will force all {@link RouteBuilder} classes configured in the Spring
-     * {@link ApplicationContext} to be registered automatically with this CamelContext.
-     */
-    public void setAutowireRouteBuilders(Boolean autowireRouteBuilders) {
-        this.autowireRouteBuilders = autowireRouteBuilders;
-    }
-
     public String getErrorHandlerRef() {
         return errorHandlerRef;
     }
@@ -519,28 +509,34 @@
     /**
      * Strategy to install all available routes into the context
      */
+    @SuppressWarnings("unchecked")
     protected void installRoutes() throws Exception {
-        if (autowireRouteBuilders != null && autowireRouteBuilders) {
-            Map builders = getApplicationContext().getBeansOfType(RouteBuilder.class, true, true);
-            if (builders != null) {
-                for (Object builder : builders.values()) {
-                    getContext().addRoutes((RouteBuilder) builder);
-                }
-            }
-        }
-        for (Routes routeBuilder : additionalBuilders) {
-            getContext().addRoutes(routeBuilder);
-        }
+        List<RouteBuilder> builders = new ArrayList<RouteBuilder>();
+
         if (routeBuilder != null) {
-            getContext().addRoutes(routeBuilder);
+            builders.add(routeBuilder);
         }
 
         // lets add route builders added from references
         if (builderRefs != null) {
             for (RouteBuilderDefinition builderRef : builderRefs) {
                 RouteBuilder builder = builderRef.createRouteBuilder(getContext());
-                getContext().addRoutes(builder);
+                builders.add(builder);
+            }
+        }
+
+        // install already configured routes
+        for (Routes routeBuilder : additionalBuilders) {
+            getContext().addRoutes(routeBuilder);
+        }
+
+        // install builders
+        for (RouteBuilder builder : builders) {
+            if (beanPostProcessor != null) {
+                // Inject the annotated resource
+                beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString());
             }
+            getContext().addRoutes(builder);
         }
     }
 
@@ -548,7 +544,7 @@
      * Strategy method to try find {@link RouteBuilder} instances on the
      * classpath
      */
-    protected void findRouteBuilders() throws Exception, InstantiationException {
+    protected void findRouteBuilders() throws Exception {
         if (getPackages() != null && getPackages().length > 0) {
             RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), getPackages(), getContextClassLoaderOnStart(),
                     getBeanPostProcessor(), getContext().getPackageScanClassResolver());

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionInterceptor.java Mon Mar 23 06:22:33 2009
@@ -108,15 +108,23 @@
                     rce = wrapRuntimeCamelException(e);
                 }
 
-                // rethrow exception if the exchange failed
-                if (rce != null) {
-                    // an exception occured so please sleep before we rethrow the exception
+                // rollback if exception occured or marked as rollback
+                if (rce != null || exchange.isRollbackOnly()) {
                     delayBeforeRedelivery();
                     if (activeTx) {
                         status.setRollbackOnly();
-                        LOG.debug("Setting transaction to rollbackOnly due to exception being thrown: " + rce.getMessage());
+                        if (LOG.isDebugEnabled()) {
+                            if (rce != null) {
+                                LOG.debug("Setting transaction to rollbackOnly due to exception being thrown: " + rce.getMessage());
+                            } else {
+                                LOG.debug("Setting transaction to rollbackOnly as Exchange was marked as rollback only");
+                            }
+                        }
+                    }
+                    // rethrow if an exception occured
+                    if (rce != null) {
+                        throw rce;
                     }
-                    throw rce;
                 }
             }
         });
@@ -141,6 +149,7 @@
                 }
                 Thread.sleep(delay);
             } catch (InterruptedException e) {
+                // TODO: As DLC we need a timer task, eg something in Util to help us
                 Thread.currentThread().interrupt();
             }
         }

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java?rev=757326&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java Mon Mar 23 06:22:33 2009
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.interceptor;
+
+import javax.sql.DataSource;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.camel.spring.spi.SpringTransactionPolicy;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.RollbackExchangeException;
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Transactional client test with rollback in the DSL.
+ *
+ * @version $Revision$
+ */
+public class TransactionalClientWithRollbackTest extends SpringTestSupport {
+
+    protected JdbcTemplate jdbc;
+    protected boolean useTransactionErrorHandler = true;
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("/org/apache/camel/spring/interceptor/transactionalClientDataSource.xml");
+    }
+
+    protected int getExpectedRouteCount() {
+        return 0;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        final DataSource ds = getMandatoryBean(DataSource.class, "dataSource");
+        jdbc = new JdbcTemplate(ds);
+        jdbc.execute("create table books (title varchar(50))");
+        jdbc.update("insert into books (title) values (?)", new Object[] {"Camel in Action"});
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        jdbc.execute("drop table books");
+    }
+
+    public void testTransactionSuccess() throws Exception {
+        template.sendBody("direct:okay", "Hello World");
+
+        int count = jdbc.queryForInt("select count(*) from books");
+        assertEquals("Number of books", 3, count);
+    }
+
+    public void testTransactionRollback() throws Exception {
+        try {
+            template.sendBody("direct:fail", "Hello World");
+            fail("Should have thrown a RollbackExchangeException");
+        } catch (RuntimeCamelException e) {
+            assertTrue(e.getCause() instanceof RollbackExchangeException);
+        }
+
+        int count = jdbc.queryForInt("select count(*) from books");
+        assertEquals("Number of books", 1, count);
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+         // Notice that we use the SpringRouteBuilder that has a few more features than
+         // the standard RouteBuilder
+         return new SpringRouteBuilder() {
+             public void configure() throws Exception {
+                 // setup the transaction policy
+                 SpringTransactionPolicy required = context.getRegistry()
+                     .lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
+
+                 // use transaction error handler
+                 errorHandler(transactionErrorHandler(required));
+
+                 // must setup policy for each route
+                 // TODO: CAMEL-1475 should fix this
+                 from("direct:okay").policy(required)
+                     .setBody(constant("Tiger in Action")).beanRef("bookService")
+                     .setBody(constant("Elephant in Action")).beanRef("bookService");
+
+                 // must setup policy for each route
+                 // TODO: CAMEL-1475 should fix this
+                 from("direct:fail").policy(required)
+                     .setBody(constant("Tiger in Action")).beanRef("bookService")
+                     // force a rollback
+                     .rollback();
+             }
+         };
+     }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientWithRollbackTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRollbackTest.java (from r757142, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDelayerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRollbackTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRollbackTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDelayerTest.java&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDelayerTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRollbackTest.java Mon Mar 23 06:22:33 2009
@@ -17,12 +17,13 @@
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.DelayerTest;
+import org.apache.camel.processor.RollbackTest;
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
-public class SpringDelayerTest extends DelayerTest {
+public class SpringRollbackTest extends RollbackTest {
+
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this,
-                "org/apache/camel/spring/processor/delayer.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/rollback.xml");
     }
-}
+
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/routeBuilderRef.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/routeBuilderRef.xml?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/routeBuilderRef.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/routeBuilderRef.xml Mon Mar 23 06:22:33 2009
@@ -22,17 +22,16 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-
-
   <!-- START SNIPPET: example5 -->
-  <camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring" autowireRouteBuilders="false">
-    <routeBuilder ref="configuredRouteBuilder"/>
+  <camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring">
+      <routeBuilder ref="configuredRouteBuilder"/>
   </camelContext>
   <!-- END SNIPPET: example5 -->
 
 
   <bean id="configuredRouteBuilder" class="org.apache.camel.spring.xml.ConfiguredRouteBuilder">
-    <property name="fromUri" value="seda:test.a"/>
-    <property name="toUri" value="seda:test.b"/>
+      <property name="fromUri" value="seda:test.a"/>
+      <property name="toUri" value="seda:test.b"/>
   </bean>
+
 </beans>

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/rollback.xml (from r757142, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/rollback.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/rollback.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/rollback.xml Mon Mar 23 06:22:33 2009
@@ -21,27 +21,33 @@
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
-    <!--
-        from("seda:a").delayer(header("JMSTimestamp"), 3000).to("mock:result");
-        from("seda:b").delayer(3000).to("mock:result");
-    -->
-    <!-- START SNIPPET: example -->
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-        <route>
-            <from uri="seda:a"/>
-            <delay delayTime="3000">
-                <simple>header.JMSTimestamp</simple>
-            </delay>
-            <to uri="mock:result"/>
-        </route>
-        <route>
-            <from uri="seda:b"/>
-            <delay delayTime="3000">
-                <language/>
-            </delay>
-            <to uri="mock:result"/>
+
+    <bean id="errorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+        <property name="deadLetterUri" value="mock:dead"/>
+        <property name="redeliveryPolicy" ref="policy"/>
+    </bean>
+
+    <bean id="policy" class="org.apache.camel.processor.RedeliveryPolicy">
+        <property name="delay" value="0"/>
+        <property name="maximumRedeliveries" value="1"/>
+    </bean>
+
+    <!-- START SNIPPET: e1 -->
+    <camelContext trace="true" id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <route errorHandlerRef="errorHandler">
+            <from uri="direct:start"/>
+            <choice>
+                <when>
+                    <simple>${body} != 'ok'</simple>
+                    <to uri="mock:rollback"/>
+                    <rollback/>
+                </when>
+                <otherwise>
+                    <to uri="mock:result"/>
+                </otherwise>
+            </choice>
         </route>
     </camelContext>
-    <!-- END SNIPPET: example -->
+    <!-- END SNIPPET: e1 -->
 
 </beans>

Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java Mon Mar 23 06:22:33 2009
@@ -37,28 +37,31 @@
 public class JmsToHttpRoute extends SpringRouteBuilder {
 
     @Resource(name = "PROPAGATION_REQUIRED")
-    private SpringTransactionPolicy required;
+    protected SpringTransactionPolicy required;
 
     @EndpointInject(name = "data")
-    private Endpoint data;
+    protected Endpoint data;
 
-    private static int counter;
+    protected static int counter;
 
-    private String nok = "<?xml version=\"1.0\"?><reply><status>nok</status></reply>";
-    private String ok  = "<?xml version=\"1.0\"?><reply><status>ok</status></reply>";
+    protected String nok = "<?xml version=\"1.0\"?><reply><status>nok</status></reply>";
+    protected String ok  = "<?xml version=\"1.0\"?><reply><status>ok</status></reply>";
 
     public void configure() throws Exception {
         // configure a global transacted error handler
         errorHandler(transactionErrorHandler(required));
 
         from(data)
+            // must setup policy for each route due CAMEL-1475 bug
+            .policy(required)
             // send a request to http and get the response
             .to("http://localhost:8080/sender")
-            // convert the response to String so we can work with it
+            // convert the response to String so we can work with it and avoid streams only be readable once
+            // as the http component will return data as a stream
             .convertBodyTo(String.class)
             // do a choice if the response is okay or not
             .choice()
-                // do an xpath to compare if the statis is NOT okay
+                // do a xpath to compare if the status is NOT okay
                 .when().xpath("/reply/status != 'ok'")
                     // as this is based on an unit test we use mocks to verify how many times we did rollback
                     .to("mock:rollback")
@@ -74,7 +77,7 @@
             .end();
 
         // this is our http route that will fail the first 2 attempts
-        // before it sends a ok response
+        // before it sends an ok response
         from("jetty:http://localhost:8080/sender").process(new Processor() {
             public void process(Exchange exchange) throws Exception {
                 if (counter++ < 2) {

Copied: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java (from r757142, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXTest.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest.java Mon Mar 23 06:22:33 2009
@@ -28,11 +28,11 @@
  * <p/>
  * We use Spring Testing for unit test, eg we extend AbstractJUnit38SpringContextTests
  * that is a Spring class.
- * 
+ *
  * @version $Revision$
  */
 @ContextConfiguration
-public class JmsToHttpTXTest extends AbstractJUnit38SpringContextTests {
+public class JmsToHttpTXWithRollbackTest extends AbstractJUnit38SpringContextTests {
 
     // use uri to refer to our mock
     @EndpointInject(uri = "mock:rollback")
@@ -47,7 +47,7 @@
     // the ok response to expect
     private String ok  = "<?xml version=\"1.0\"?><reply><status>ok</status></reply>";
 
-    public void testSendToTXJms() throws Exception {
+    public void testSendToTXJmsWithRollback() throws Exception {
         // we assume 2 rollbacks
         mock.expectedMessageCount(2);
 
@@ -62,4 +62,4 @@
         mock.assertIsSatisfied();
     }
 
-}
+}
\ No newline at end of file

Copied: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpWithRollbackRoute.java (from r757142, camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpWithRollbackRoute.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpWithRollbackRoute.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpRoute.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/tx/JmsToHttpWithRollbackRoute.java Mon Mar 23 06:22:33 2009
@@ -16,14 +16,8 @@
  */
 package org.apache.camel.itest.tx;
 
-import javax.annotation.Resource;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.spring.SpringRouteBuilder;
-import org.apache.camel.spring.spi.SpringTransactionPolicy;
 
 /**
  * Route that listen on a JMS queue and send a request/reply over http
@@ -34,47 +28,35 @@
  *
  * @version $Revision$
  */
-public class JmsToHttpRoute extends SpringRouteBuilder {
-
-    @Resource(name = "PROPAGATION_REQUIRED")
-    private SpringTransactionPolicy required;
-
-    @EndpointInject(name = "data")
-    private Endpoint data;
-
-    private static int counter;
-
-    private String nok = "<?xml version=\"1.0\"?><reply><status>nok</status></reply>";
-    private String ok  = "<?xml version=\"1.0\"?><reply><status>ok</status></reply>";
+public class JmsToHttpWithRollbackRoute extends JmsToHttpRoute {
 
     public void configure() throws Exception {
         // configure a global transacted error handler
         errorHandler(transactionErrorHandler(required));
 
         from(data)
+            // must setup policy for each route due CAMEL-1475 bug
+            .policy(required)
             // send a request to http and get the response
             .to("http://localhost:8080/sender")
-            // convert the response to String so we can work with it
+            // convert the response to String so we can work with it and avoid streams only be readable once
+            // as the http component will return data as a stream
             .convertBodyTo(String.class)
             // do a choice if the response is okay or not
             .choice()
-                // do an xpath to compare if the statis is NOT okay
+                // do a xpath to compare if the status is NOT okay
                 .when().xpath("/reply/status != 'ok'")
                     // as this is based on an unit test we use mocks to verify how many times we did rollback
                     .to("mock:rollback")
-                    // response is not okay so force a rollback by throwing an exception
-                    .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            throw new IllegalArgumentException("Rollback please");
-                        }
-                    })
+                    // response is not okay so force a rollback
+                    .rollback()
                 .otherwise()
                 // otherwise since its okay, the route ends and the response is sent back
                 // to the original caller
             .end();
 
         // this is our http route that will fail the first 2 attempts
-        // before it sends a ok response
+        // before it sends an ok response
         from("jetty:http://localhost:8080/sender").process(new Processor() {
             public void process(Exchange exchange) throws Exception {
                 if (counter++ < 2) {
@@ -86,4 +68,4 @@
         });
     }
 
-}
+}
\ No newline at end of file

Modified: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml?rev=757326&r1=757325&r2=757326&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml Mon Mar 23 06:22:33 2009
@@ -59,10 +59,12 @@
         <property name="configuration" ref="jmsConfig"/>
     </bean>
 
+    <bean id="route" class="org.apache.camel.itest.tx.JmsToHttpRoute"/>
+
     <!-- Camel context -->
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-        <!-- find our router in this package -->
-        <package>org.apache.camel.itest.tx</package>
+        <!--use our route -->
+       <routeBuilder ref="route"/>
 
         <!-- define our data endpoint as the activemq queue we send a message to -->
         <endpoint id="data" uri="activemq:queue:data"/>

Copied: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest-context.xml (from r757142, camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest-context.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest-context.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml&r1=757142&r2=757326&rev=757326&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/tx/JmsToHttpTXWithRollbackTest-context.xml Mon Mar 23 06:22:33 2009
@@ -59,10 +59,12 @@
         <property name="configuration" ref="jmsConfig"/>
     </bean>
 
+    <bean id="route" class="org.apache.camel.itest.tx.JmsToHttpWithRollbackRoute"/>
+
     <!-- Camel context -->
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-        <!-- find our router in this package -->
-        <package>org.apache.camel.itest.tx</package>
+         <!--use our route -->
+        <routeBuilder ref="route"/>
 
         <!-- define our data endpoint as the activemq queue we send a message to -->
         <endpoint id="data" uri="activemq:queue:data"/>