camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1238463 - 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/processor/ camel-core/src/main/java/org/apache/camel/util/ components/camel-jms...
Date Tue, 31 Jan 2012 12:56:51 GMT
Author: davsclaus
Date: Tue Jan 31 12:56:51 2012
New Revision: 1238463

URL: http://svn.apache.org/viewvc?rev=1238463&view=rev
Log:
CAMEL-4961: Added isTransactedRedelivered to Exchange, which allows to better track redelivered
messages, from ex JMS brokers. Makes easier to correlate in logs and whatnot. Improved TX
logging in TransactedErrorHandler. Polished the scala RichExchange as well, as slight API
change in Exchange.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.java
      - copied, changed from r1238245, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml
      - copied, changed from r1238245, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.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/DefaultMessage.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java
    camel/trunk/components/camel-jms/src/test/resources/log4j.properties
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java

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=1238463&r1=1238462&r2=1238463&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 Tue Jan 31 12:56:51
2012
@@ -398,6 +398,17 @@ public interface Exchange {
     boolean isTransacted();
 
     /**
+     * Returns true if this exchange is redelivered from a transacted source (such as a JMS
broker)
+     * <p/>
+     * <b>Important: </b> It is not always possible to determine if the transacted
is a redelivery
+     * or not, and therefore <tt>null</tt> is returned. Such an example would
be a JDBC message.
+     * However JMS brokers provides details if a transacted message is redelivered.
+     *
+     * @return <tt>true</tt> if redelivered, <tt>false</tt> if not,
<tt>null</tt> if not able to determine
+     */
+    Boolean isTransactedRedelivered();
+
+    /**
      * Returns true if this exchange is marked for rollback
      */
     boolean isRollbackOnly();

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=1238463&r1=1238462&r2=1238463&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 Tue Jan
31 12:56:51 2012
@@ -331,6 +331,17 @@ public final class DefaultExchange imple
         }
     }
 
+    public Boolean isTransactedRedelivered() {
+        // lets avoid adding methods to the Message API, so we use the
+        // DefaultMessage to allow component specific messages to extend
+        // and implement the isTransactedRedelivered method.
+        DefaultMessage msg = getIn(DefaultMessage.class);
+        if (msg != null) {
+            return msg.isTransactedRedelivered();
+        }
+        return null;
+    }
+
     public boolean isRollbackOnly() {
         return Boolean.TRUE.equals(getProperty(Exchange.ROLLBACK_ONLY)) || Boolean.TRUE.equals(getProperty(Exchange.ROLLBACK_ONLY_LAST));
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java Tue Jan
31 12:56:51 2012
@@ -237,6 +237,21 @@ public class DefaultMessage extends Mess
         // do nothing by default
     }
 
+    /**
+     * A strategy for component specific messages to determine whether the
+     * message is redelivered or not.
+     * <p/>
+     * <b>Important: </b> It is not always possible to determine if the transacted
is a redelivery
+     * or not, and therefore <tt>null</tt> is returned. Such an example would
be a JDBC message.
+     * However JMS brokers provides details if a transacted message is redelivered.
+     *
+     * @return <tt>true</tt> if redelivered, <tt>false</tt> if not,
<tt>null</tt> if not able to determine
+     */
+    protected Boolean isTransactedRedelivered() {
+        // return null by default
+        return null;
+    }
+
     public void addAttachment(String id, DataHandler content) {
         if (attachments == null) {
             attachments = createAttachments();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Tue Jan 31 12:56:51 2012
@@ -580,7 +580,7 @@ public abstract class RedeliveryErrorHan
         // keep the Exchange.EXCEPTION_CAUGHT as property so end user knows the caused exception
 
         // create log message
-        String msg = "Failed delivery for exchangeId: " + exchange.getExchangeId();
+        String msg = "Failed delivery for " + ExchangeHelper.logIds(exchange);
         msg = msg + ". Exhausted after delivery attempt: " + data.redeliveryCounter + " caught:
" + caught;
         msg = msg + ". Handled and continue routing.";
 
@@ -668,7 +668,7 @@ public abstract class RedeliveryErrorHan
 
         // only log if not failure handled or not an exhausted unit of work
         if (!ExchangeHelper.isFailureHandled(exchange) && !ExchangeHelper.isUnitOfWorkExhausted(exchange))
{
-            String msg = "Failed delivery for exchangeId: " + exchange.getExchangeId()
+            String msg = "Failed delivery for " + ExchangeHelper.logIds(exchange)
                     + ". On delivery attempt: " + data.redeliveryCounter + " caught: " +
e;
             logFailedDelivery(true, false, false, exchange, msg, data, e);
         }
@@ -776,7 +776,7 @@ public abstract class RedeliveryErrorHan
         }
 
         // create log message
-        String msg = "Failed delivery for exchangeId: " + exchange.getExchangeId();
+        String msg = "Failed delivery for " + ExchangeHelper.logIds(exchange);
         msg = msg + ". Exhausted after delivery attempt: " + data.redeliveryCounter + " caught:
" + caught;
         if (processor != null) {
             msg = msg + ". Processed by failure processor: " + processor;
@@ -870,7 +870,7 @@ public abstract class RedeliveryErrorHan
         }
 
         if (exchange.isRollbackOnly()) {
-            String msg = "Rollback exchangeId: " + exchange.getExchangeId();
+            String msg = "Rollback " + ExchangeHelper.logIds(exchange);
             Throwable cause = exchange.getException() != null ? exchange.getException() :
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
             if (cause != null) {
                 msg = msg + " due: " + cause.getMessage();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Tue Jan
31 12:56:51 2012
@@ -653,23 +653,37 @@ public final class ExchangeHelper {
             exchange.setOut(null);
         }
     }
-    
+
+    /**
+     * Gets both the messageId and exchangeId to be used for logging purposes.
+     * <p/>
+     * Logging both ids, can help to correlate exchanges which may be redelivered messages
+     * from for example a JMS broker.
+     *
+     * @param exchange the exchange
+     * @return a log message with both the messageId and exchangeId
+     */
+    public static String logIds(Exchange exchange) {
+        String msgId = exchange.hasOut() ? exchange.getOut().getMessageId() : exchange.getIn().getMessageId();
+        return "(MessageId: " + msgId + " on ExchangeId: " + exchange.getExchangeId()  +
")";
+    }
+
     public static Exchange copyExchangeAndSetCamelContext(Exchange exchange, CamelContext
context) {
         DefaultExchange answer = new DefaultExchange(context, exchange.getPattern());
         if (exchange.hasProperties()) {
             answer.setProperties(safeCopy(exchange.getProperties()));
         }
         // Need to hand over the completion for async invocation
-        exchange.handoverCompletions(answer);        
+        exchange.handoverCompletions(answer);
         answer.setIn(exchange.getIn().copy());
         if (exchange.hasOut()) {
             answer.setOut(exchange.getOut().copy());
         }
         answer.setException(exchange.getException());
         return answer;
-        
+
     }
-    
+
     private static Map<String, Object> safeCopy(Map<String, Object> properties)
{
         if (properties == null) {
             return null;

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Tue Jan 31 12:56:51 2012
@@ -232,6 +232,15 @@ public class JmsMessage extends DefaultM
         }
     }
 
+    @Override
+    protected Boolean isTransactedRedelivered() {
+        if (jmsMessage != null) {
+            return JmsMessageHelper.getJMSRedelivered(jmsMessage);
+        } else {
+            return null;
+        }
+    }
+
     private String getDestinationAsString(Destination destination) throws JMSException {
         String result;
         if (destination == null) {

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessageHelper.java
Tue Jan 31 12:56:51 2012
@@ -218,6 +218,22 @@ public final class JmsMessageHelper {
     }
 
     /**
+     * Gets the JMSRedelivered from the message.
+     *
+     * @param message  the message
+     * @return <tt>true</tt> if redelivered, <tt>false</tt> if not,
<tt>null</tt> if not able to determine
+     */
+    public static Boolean getJMSRedelivered(Message message) {
+        try {
+            return message.getJMSRedelivered();
+        } catch (Exception e) {
+            // ignore if JMS broker do not support this
+        }
+
+        return null;
+    }
+
+    /**
      * Sets the JMSDeliveryMode on the message.
      *
      * @param exchange the exchange

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.java
(from r1238245, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java&r1=1238245&r2=1238463&rev=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.java
Tue Jan 31 12:56:51 2012
@@ -18,6 +18,7 @@ package org.apache.camel.component.jms.t
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelSpringTestSupport;
 import org.junit.Test;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -25,26 +26,44 @@ import org.springframework.context.suppo
 /**
  *
  */
-public class JMSTransactionRollbackTest extends CamelSpringTestSupport {
+public class JMSTransactionIsTransactedRedeliveredTestTest extends CamelSpringTestSupport
{
 
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(
-            "/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml");
+            "/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml");
     }
 
     @Test
-    public void testTransactionRollback() throws Exception {
-        getMockEndpoint("mock:before").expectedMessageCount(6);
-        getMockEndpoint("mock:result").expectedMessageCount(0);
+    public void testTransactionSuccess() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Bye World");
+        // success at 3rd attempt
+        mock.message(0).header("count").isEqualTo(3);
 
         template.sendBody("activemq:queue:okay", "Hello World");
 
-        assertMockEndpointsSatisfied();
+        mock.assertIsSatisfied();
     }
 
     public static class MyProcessor implements Processor {
+        private int count;
+
         public void process(Exchange exchange) throws Exception {
-            throw new IllegalArgumentException("Forced Exception");
+            ++count;
+
+            // the first is not redelivered
+            if (count == 1) {
+                assertFalse("Should not be transacted redelivered", exchange.isTransactedRedelivered());
+            } else {
+                assertTrue("Should be transacted redelivered", exchange.isTransactedRedelivered());
+            }
+
+            if (count < 3) {
+                throw new IllegalArgumentException("Forced exception");
+            }
+            exchange.getIn().setBody("Bye World");
+            exchange.getIn().setHeader("count", count);
         }
     }
 

Modified: camel/trunk/components/camel-jms/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/log4j.properties?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-jms/src/test/resources/log4j.properties Tue Jan 31 12:56:51
2012
@@ -31,6 +31,7 @@ log4j.rootLogger=INFO, out
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+#log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{exchangeId}
- %-10.10X{messageId} - %m%n
 
 # File appender
 log4j.appender.out=org.apache.log4j.FileAppender

Copied: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml
(from r1238245, camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml&r1=1238245&r2=1238463&rev=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionRollbackTest.xml
(original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTestTest.xml
Tue Jan 31 12:56:51 2012
@@ -19,8 +19,8 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:camel="http://camel.apache.org/schema/spring"
        xsi:schemaLocation="
-         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
     <bean id="poolConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
         <property name="maxConnections" value="8"/>
@@ -60,6 +60,6 @@
         </route>
     </camelContext>
 
-    <bean id="myProcessor" class="org.apache.camel.component.jms.tx.JMSTransactionRollbackTest$MyProcessor"/>
+    <bean id="myProcessor" class="org.apache.camel.component.jms.tx.JMSTransactionIsTransactedRedeliveredTestTest$MyProcessor"/>
 
 </beans>

Modified: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
(original)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
Tue Jan 31 12:56:51 2012
@@ -27,45 +27,47 @@ import java.lang.{String, Class}
  */
 class RichExchange(val exchange : Exchange) extends Exchange {
 
-  def in_=(message: Any) = exchange.getIn().setBody(message)
+  def in_=(message: Any) { exchange.getIn.setBody(message) }
 
-  def in(header:String) : Any = exchange.getIn().getHeader(header)
+  def in(header:String) : Any = exchange.getIn.getHeader(header)
 
-  def in = exchange.getIn().getBody()
-  def in[T](implicit manifest: Manifest[T]) : T = exchange.getIn().getBody(manifest.erasure).asInstanceOf[T]
+  def in = exchange.getIn.getBody
+  def in[T](implicit manifest: Manifest[T]) : T = exchange.getIn.getBody(manifest.erasure).asInstanceOf[T]
 
-  def out : Any = exchange.getOut().getBody()
+  def out : Any = exchange.getOut.getBody
 
-  def out(header:String) : Any = exchange.getOut().getHeader(header)
+  def out(header:String) : Any = exchange.getOut.getHeader(header)
 
-  def out_=(message:Any) = exchange.getOut().setBody(message)
+  def out_=(message:Any) { exchange.getOut.setBody(message) }
 
 
   // Delegation methods
   //-------------------------------------------------------------------------
 
-  def setUnitOfWork(unitOfWork: UnitOfWork) = exchange.setUnitOfWork(unitOfWork)
+  def setUnitOfWork(unitOfWork: UnitOfWork) { exchange.setUnitOfWork(unitOfWork) }
 
-  def setProperty(name: String, value: Any) = exchange.setProperty(name, value)
+  def setProperty(name: String, value: Any) { exchange.setProperty(name, value) }
 
-  def setPattern(pattern: ExchangePattern) = exchange.setPattern(pattern)
+  def setPattern(pattern: ExchangePattern) { exchange.setPattern(pattern) }
 
-  def setOut(out: Message) = exchange.setOut(out)
+  def setOut(out: Message) { exchange.setOut(out) }
 
-  def setIn(in: Message) = exchange.setIn(in)
+  def setIn(in: Message) { exchange.setIn(in) }
 
-  def setFromEndpoint(fromEndpoint: Endpoint) = exchange.setFromEndpoint(fromEndpoint)
+  def setFromEndpoint(fromEndpoint: Endpoint) { exchange.setFromEndpoint(fromEndpoint) }
 
-  def setFromRouteId(routeId: String) = exchange.setFromRouteId(routeId)
+  def setFromRouteId(routeId: String) { exchange.setFromRouteId(routeId) }
 
-  def setExchangeId(id: String) = exchange.setExchangeId(id)
+  def setExchangeId(id: String) { exchange.setExchangeId(id) }
 
-  def setException(t: Throwable) = exchange.setException(t)
+  def setException(t: Throwable) { exchange.setException(t) }
 
   def removeProperty(name: String) = exchange.removeProperty(name)
 
   def isTransacted = exchange.isTransacted
 
+  def isTransactedRedelivered = exchange.isTransactedRedelivered;
+
   def isRollbackOnly = exchange.isRollbackOnly
 
   def isFailed = exchange.isFailed
@@ -110,9 +112,9 @@ class RichExchange(val exchange : Exchan
 
   def copy = new RichExchange(exchange.copy)
 
-  def addOnCompletion(onCompletion: Synchronization) = exchange.addOnCompletion(onCompletion)
+  def addOnCompletion(onCompletion: Synchronization) { exchange.addOnCompletion(onCompletion)
}
   
-  def handoverCompletions(exchange : Exchange) = exchange.handoverCompletions(exchange)
+  def handoverCompletions(exchange : Exchange) { exchange.handoverCompletions(exchange) }
 
   def handoverCompletions = exchange.handoverCompletions
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java?rev=1238463&r1=1238462&r2=1238463&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
Tue Jan 31 12:56:51 2012
@@ -25,6 +25,7 @@ import org.apache.camel.processor.Redeli
 import org.apache.camel.processor.RedeliveryPolicy;
 import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
 import org.apache.camel.util.CamelLogger;
+import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
@@ -111,20 +112,31 @@ public class TransactionErrorHandler ext
     }
 
     protected void processInTransaction(final Exchange exchange) throws Exception {
+        // is the exchange redeliveried, for example JMS brokers support such details
+        Boolean redelivery = exchange.isTransactedRedelivered();
+        final String redelivered = redelivery != null ? redelivery.toString() : "unknown";
+        final String ids = ExchangeHelper.logIds(exchange);
+
         try {
             // mark the beginning of this transaction boundary
             exchange.getUnitOfWork().beginTransactedBy(transactionKey);
 
-            log.debug("Transaction begin ({}) for ExchangeId: {}", transactionKey, exchange.getExchangeId());
+            if (log.isDebugEnabled()) {
+                log.debug("Transaction begin ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
+            }
 
             doInTransactionTemplate(exchange);
 
-            log.debug("Transaction commit ({}) for ExchangeId: {}", transactionKey, exchange.getExchangeId());
+            if (log.isDebugEnabled()) {
+                log.debug("Transaction commit ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
+            }
         } catch (TransactionRollbackException e) {
             // ignore as its just a dummy exception to force spring TX to rollback
-            log.debug("Transaction rollback ({}) for ExchangeId: {} due exchange was marked
for rollbackOnly", transactionKey, exchange.getExchangeId());
+            if (log.isDebugEnabled()) {
+                log.debug("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            }
         } catch (Throwable e) {
-            log.warn("Transaction rollback (" + transactionKey + ") for ExchangeId: " + exchange.getExchangeId()
+ " due exception: " + e.getMessage());
+            log.warn("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
             exchange.setException(e);
         } finally {
             // mark the end of this transaction boundary
@@ -135,14 +147,13 @@ public class TransactionErrorHandler ext
         Boolean onlyLast = (Boolean) exchange.removeProperty(Exchange.ROLLBACK_ONLY_LAST);
         if (onlyLast != null && onlyLast) {
             if (log.isDebugEnabled()) {
-                // log exception if there was a cause exception so we have the stacktrace
+                // log exception if there was a cause exception so we have the stack trace
                 Exception cause = exchange.getException();
                 if (cause != null) {
-                    log.debug("Transaction rollback (" + transactionKey + ") for ExchangeId:
" + exchange.getExchangeId()
-                        + " due exchange was marked for rollbackOnlyLast and due exception:
", cause);
+                    log.debug("Transaction rollback (" + transactionKey + ") redelivered("
+ redelivered + ") for "
+                        + ids + " due exchange was marked for rollbackOnlyLast and caught:
", cause);
                 } else {
-                    log.debug("Transaction rollback ({}) for ExchangeId: {} due exchange
was marked for rollbackOnlyLast",
-                            transactionKey, exchange.getExchangeId());
+                    log.debug("Transaction rollback ({}) redelivered(" + redelivered + ")
for {} due exchange was marked for rollbackOnlyLast", transactionKey, ids);
                 }
             }
             // remove caused exception due we was marked as rollback only last



Mime
View raw message