camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1066836 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/xml/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/spi/ components/camel-jetty/src/test/java/org/apache/camel/componen...
Date Thu, 03 Feb 2011 15:47:44 GMT
Author: davsclaus
Date: Thu Feb  3 15:47:43 2011
New Revision: 1066836

URL: http://svn.apache.org/viewvc?rev=1066836&view=rev
Log:
CAMEL-3610: Added transactionKey to MDC logging.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMDCTest.java
      - copied, changed from r1066781, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UnitOfWork.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyMinMaxThreadPoolTest.java
    camel/trunk/components/camel-spring/src/test/resources/log4j.properties

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java?rev=1066836&r1=1066835&r2=1066836&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultTransformErrorHandler.java
Thu Feb  3 15:47:43 2011
@@ -19,15 +19,16 @@ package org.apache.camel.builder.xml;
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.TransformerException;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-
+/**
+ * {@link ErrorHandler} and {@link ErrorListener} which will log warnings,
+ * and throws error and fatal as exception, which ensures those can be caught by Camel and
dealt-with.
+ */
 public class DefaultTransformErrorHandler implements ErrorHandler, ErrorListener {
     private static final transient Logger LOG = LoggerFactory.getLogger(DefaultTransformErrorHandler.class);
 
@@ -41,7 +42,6 @@ public class DefaultTransformErrorHandle
 
     public void warning(SAXParseException exception) throws SAXException {
         LOG.warn("parser warning", exception);
-        
     }
 
     public void error(TransformerException exception) throws TransformerException {
@@ -54,7 +54,6 @@ public class DefaultTransformErrorHandle
 
     public void warning(TransformerException exception) throws TransformerException {
         LOG.warn("parser warning", exception);
-        
     }
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java?rev=1066836&r1=1066835&r2=1066836&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java Thu Feb
 3 15:47:43 2011
@@ -32,6 +32,7 @@ public class MDCUnitOfWork extends Defau
     public static final String MDC_EXCHANGE_ID = "exchangeId";
     public static final String MDC_CORRELATION_ID = "correlationId";
     public static final String MDC_ROUTE_ID = "routeId";
+    public static final String MDC_TRANSACTION_KEY = "transactionKey";
 
     public MDCUnitOfWork(Exchange exchange) {
         super(exchange);
@@ -53,8 +54,8 @@ public class MDCUnitOfWork extends Defau
 
     @Override
     public void pushRouteContext(RouteContext routeContext) {
-        super.pushRouteContext(routeContext);
         MDC.put(MDC_ROUTE_ID, routeContext.getRoute().getId());
+        super.pushRouteContext(routeContext);
     }
 
     @Override
@@ -64,6 +65,18 @@ public class MDCUnitOfWork extends Defau
     }
 
     @Override
+    public void beginTransactedBy(Object key) {
+        MDC.put(MDC_TRANSACTION_KEY, key.toString());
+        super.beginTransactedBy(key);
+    }
+
+    @Override
+    public void endTransactedBy(Object key) {
+        MDC.remove(MDC_TRANSACTION_KEY);
+        super.endTransactedBy(key);
+    }
+
+    @Override
     public AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback
callback) {
         return new MDCCallback(callback);
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UnitOfWork.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UnitOfWork.java?rev=1066836&r1=1066835&r2=1066836&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UnitOfWork.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UnitOfWork.java Thu Feb  3 15:47:43
2011
@@ -155,12 +155,12 @@ public interface UnitOfWork extends Serv
      * @param processor the processor to be executed
      * @param exchange  the current exchange
      * @param callback the callback
-     * @return the callback to be used (can be wrapped)
+     * @return the callback to be used (can return a wrapped callback)
      */
     AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback callback);
 
     /**
-     * Strategy for optional work to be executed after the callback has been processed.
+     * Strategy for optional work to be executed after the processing
      *
      * @param processor the processor executed
      * @param exchange  the current exchange

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyMinMaxThreadPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyMinMaxThreadPoolTest.java?rev=1066836&r1=1066835&r2=1066836&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyMinMaxThreadPoolTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyMinMaxThreadPoolTest.java
Thu Feb  3 15:47:43 2011
@@ -53,6 +53,7 @@ public class JettyMinMaxThreadPoolTest e
                 @Override
                 public void onDone(Exchange exchange) {
                     String body = exchange.getOut().getBody(String.class);
+                    log.info("Got reply " + body);
                     replies.add(body);
                     latch.countDown();
                 }
@@ -66,6 +67,8 @@ public class JettyMinMaxThreadPoolTest e
         // sort replies
         Collections.sort(replies);
 
+        log.info("Sorted replies: " + replies.toArray());
+
         for (int i = 0; i < 10; i++) {
             assertEquals("Bye " + i, replies.get(i));
         }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMDCTest.java
(from r1066781, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMDCTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMDCTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedTest.java&r1=1066781&r2=1066836&rev=1066836&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceTransactedTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMDCTest.java
Thu Feb  3 15:47:43 2011
@@ -16,33 +16,50 @@
  */
 package org.apache.camel.spring.interceptor;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.spring.SpringRouteBuilder;
+import org.slf4j.MDC;
 
 /**
  * Easier transaction configuration as we do not have to setup a transaction error handler
  */
-public class TransactionalClientDataSourceTransactedTest extends TransactionalClientDataSourceTest
{
+public class TransactionalClientDataSourceMDCTest extends TransactionalClientDataSourceTest
{
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new SpringRouteBuilder() {
             public void configure() throws Exception {
-                // START SNIPPET: e1
-                from("direct:okay")
-                    // marks this route as transacted, and we dont pass in any parameters
so we
-                    // will auto lookup and use the Policy defined in the spring XML file
+                context.setUseMDCLogging(true);
+
+                from("direct:okay").routeId("route-a")
                     .transacted()
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                assertEquals("route-a", MDC.get("routeId"));
+                                assertEquals(exchange.getExchangeId(), MDC.get("exchangeId"));
+                                assertNotNull(MDC.get("transactionKey"));
+                            }
+                        })
+                    .to("log:foo")
                     .setBody(constant("Tiger in Action")).beanRef("bookService")
+                    .to("log:bar")
                     .setBody(constant("Elephant in Action")).beanRef("bookService");
 
                 // marks this route as transacted that will use the single policy defined
in the registry
-                from("direct:fail")
-                    // marks this route as transacted, and we dont pass in any parameters
so we
-                    // will auto lookup and use the Policy defined in the spring XML file
+                from("direct:fail").routeId("route-b")
                     .transacted()
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                assertEquals("route-b", MDC.get("routeId"));
+                                assertEquals(exchange.getExchangeId(), MDC.get("exchangeId"));
+                                assertNotNull(MDC.get("transactionKey"));
+                            }
+                        })
+                    .to("log:foo2")
                     .setBody(constant("Tiger in Action")).beanRef("bookService")
+                    .to("log:bar2")
                     .setBody(constant("Donkey in Action")).beanRef("bookService");
-                // END SNIPPET: e1
             }
         };
     }

Modified: camel/trunk/components/camel-spring/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/log4j.properties?rev=1066836&r1=1066835&r2=1066836&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-spring/src/test/resources/log4j.properties Thu Feb  3 15:47:43
2011
@@ -35,7 +35,7 @@ log4j.appender.out=org.apache.log4j.Cons
 log4j.appender.out.layout=org.apache.log4j.PatternLayout
 log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 # MDC
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{exchangeId}
- %-10.10X{correlationId} - %-10.10X{routeId} - %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{exchangeId}
- %-10.10X{correlationId} - %-10.10X{transactionKey} - %-10.10X{routeId} - %m%n
 
 # File appender
 log4j.appender.file=org.apache.log4j.FileAppender



Mime
View raw message