This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new 2da99f6  [CAMEL-12082] Set the TCCL to the application classloader 
when executing local route commands
2da99f6 is described below

commit 2da99f6198529d499791a5f5580b1f51e2eaf63d
Author: jpoth <[email protected]>
AuthorDate: Wed Dec 13 18:00:56 2017 +0100

    [CAMEL-12082] Set the TCCL to the application classloader when executing 
local route commands
---
 .../camel/commands/AbstractRouteCommand.java       | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
index 74611e8..d0da95c 100644
--- 
a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
+++ 
b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractRouteCommand.java
@@ -22,6 +22,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.commands.internal.RegexUtil;
 
 /**
@@ -53,12 +54,36 @@ public abstract class AbstractRouteCommand extends 
AbstractCamelCommand {
         for (Map<String, String> row : camelRoutes) {
             String camelContextName = row.get("camelContextName");
             String routeId = row.get("routeId");
-            executeOnRoute(camelController, camelContextName, routeId, out, 
err);
+            if (camelController instanceof LocalCamelController) {
+                executeLocal((LocalCamelController) camelController, 
camelContextName, routeId, out, err);
+            } else {
+                executeOnRoute(camelController, camelContextName, routeId, 
out, err);
+            }
         }
 
         return null;
     }
 
+    private void executeLocal(LocalCamelController camelController, String 
camelContextName, String routeId, PrintStream out, PrintStream err) throws 
Exception {
+        CamelContext camelContext = 
camelController.getLocalCamelContext(context);
+        if (camelContext == null) {
+            err.println("Camel context " + context + " not found.");
+            return;
+        }
+
+        // Setting thread context classloader to the bundle classloader to 
enable legacy code that relies on it
+        ClassLoader oldClassloader = 
Thread.currentThread().getContextClassLoader();
+        ClassLoader applicationContextClassLoader = 
camelContext.getApplicationContextClassLoader();
+        if (applicationContextClassLoader  != null) {
+            
Thread.currentThread().setContextClassLoader(applicationContextClassLoader);
+        }
+        try {
+            executeOnRoute(camelController, camelContextName, routeId, out, 
err);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassloader);
+        }
+    }
+
     public abstract void executeOnRoute(CamelController camelController, 
String contextName, String routeId, PrintStream out, PrintStream err) throws 
Exception;
 
     /**

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to