camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/6] camel git commit: CAMEL-11287: MDC routeId value is lost after calling a direct route from a transacted route
Date Tue, 16 May 2017 14:53:34 GMT
CAMEL-11287: MDC routeId value is lost after calling a direct route from a transacted route


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/445ef3d8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/445ef3d8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/445ef3d8

Branch: refs/heads/camel-2.19.x
Commit: 445ef3d835e4e21a68a84638451b4e8810f8fc81
Parents: ccdfa1a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue May 16 16:46:36 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue May 16 16:52:45 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/impl/MDCUnitOfWork.java  | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/445ef3d8/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java b/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
index 1726b80..f0f834a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
@@ -94,14 +94,25 @@ public class MDCUnitOfWork extends DefaultUnitOfWork {
 
     @Override
     public void pushRouteContext(RouteContext routeContext) {
-        MDC.put(MDC_ROUTE_ID, routeContext.getRoute().getId());
         super.pushRouteContext(routeContext);
+        MDC.put(MDC_ROUTE_ID, routeContext.getRoute().getId());
     }
 
     @Override
     public RouteContext popRouteContext() {
-        MDC.remove(MDC_ROUTE_ID);
-        return super.popRouteContext();
+        RouteContext answer = super.popRouteContext();
+
+        // restore old route id back again after we have popped
+        RouteContext previous = getRouteContext();
+        if (previous != null) {
+            // restore old route id back again
+            MDC.put(MDC_ROUTE_ID, previous.getRoute().getId());
+        } else {
+            // not running in route, so clear (should ideally not happen)
+            MDC.remove(MDC_ROUTE_ID);
+        }
+
+        return answer;
     }
 
     @Override


Mime
View raw message