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 2023/05/15 14:53:46 UTC

[camel] branch camel-3.20.x updated: CAMEL-19353: camel-jbang - Reload on demand should use ACL classloader so using what Camel was used during boostrap to be consistent.

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

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


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new e942ef99571 CAMEL-19353: camel-jbang - Reload on demand should use ACL classloader so using what Camel was used during boostrap to be consistent.
e942ef99571 is described below

commit e942ef99571dcb330c2cc3655418a8470e34a2ae
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 15 16:53:05 2023 +0200

    CAMEL-19353: camel-jbang - Reload on demand should use ACL classloader so using what Camel was used during boostrap to be consistent.
---
 .../org/apache/camel/support/RouteOnDemandReloadStrategy.java  | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteOnDemandReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteOnDemandReloadStrategy.java
index 0e300322d29..fd71e22782f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteOnDemandReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteOnDemandReloadStrategy.java
@@ -64,7 +64,13 @@ public class RouteOnDemandReloadStrategy extends RouteWatcherReloadStrategy {
      */
     @Override
     public void onReload(Object source) {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
+            // use bootstrap classloader from camel so its consistent
+            ClassLoader acl = getCamelContext().getApplicationContextClassLoader();
+            if (acl != null) {
+                Thread.currentThread().setContextClassLoader(acl);
+            }
             doOnReload(source);
             incSucceededCounter();
         } catch (Exception e) {
@@ -72,6 +78,10 @@ public class RouteOnDemandReloadStrategy extends RouteWatcherReloadStrategy {
             LOG.warn("Error reloading routes due " + e.getMessage()
                      + ". This exception is ignored.",
                     e);
+        } finally {
+            if (cl != null) {
+                Thread.currentThread().setContextClassLoader(cl);
+            }
         }
     }