This is an automated email from the ASF dual-hosted git repository. ggrzybek pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new b26db98 [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands b26db98 is described below commit b26db98574e8b073e7274677697486065bfd0605 Author: Grzegorz Grzybek <gr.grzy...@gmail.com> AuthorDate: Fri Jan 11 13:47:08 2019 +0100 [CAMEL-13049] Use CamelContext's ClassLoader as TCCL for some Karaf commands (cherry picked from commit da36458fbd564440cec711c80013790cc22dccf9) --- .../commands/internal/CamelControllerImpl.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java index 7c08466..3340272 100644 --- a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java +++ b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/internal/CamelControllerImpl.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.commands.AbstractLocalCamelController; import org.apache.camel.api.management.ManagedCamelContext; +import org.apache.camel.support.ObjectHelper; import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -101,4 +102,57 @@ public class CamelControllerImpl extends AbstractLocalCamelController { return answer; } + @Override + public void startContext(String camelContextName) throws Exception { + final CamelContext context = getLocalCamelContext(camelContextName); + if (context != null) { + ObjectHelper.callWithTCCL(() -> { + context.start(); + return null; + }, getClassLoader(context)); + } + } + + @Override + public void resumeContext(String camelContextName) throws Exception { + final CamelContext context = getLocalCamelContext(camelContextName); + if (context != null) { + ObjectHelper.callWithTCCL(() -> { + context.resume(); + return null; + }, getClassLoader(context)); + } + } + + @Override + public void startRoute(String camelContextName, final String routeId) throws Exception { + final CamelContext context = getLocalCamelContext(camelContextName); + if (context != null) { + ObjectHelper.callWithTCCL(() -> { + context.getRouteController().startRoute(routeId); + return null; + }, getClassLoader(context)); + } + } + + @Override + public void resumeRoute(String camelContextName, final String routeId) throws Exception { + final CamelContext context = getLocalCamelContext(camelContextName); + if (context != null) { + ObjectHelper.callWithTCCL(() -> { + context.getRouteController().resumeRoute(routeId); + return null; + }, getClassLoader(context)); + } + } + + /** + * Gets classloader associated with {@link CamelContext} + * @param context + * @return + */ + private ClassLoader getClassLoader(CamelContext context) { + return context.getApplicationContextClassLoader(); + } + }