camel-jms reply manager should use AC classloader to avoid using current thread CL which may lead to CL issues in OSGi deployments.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5e8235a8 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5e8235a8 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5e8235a8 Branch: refs/heads/camel-2.11.x Commit: 5e8235a80449e795484127ac89990dd7e7897eee Parents: e118998 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 23 09:10:01 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 23 09:15:30 2013 +0200 ---------------------------------------------------------------------- .../org/apache/camel/component/jms/JmsProducer.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5e8235a8/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java index ec93dd8..4bf5598 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java @@ -75,7 +75,16 @@ public class JmsProducer extends DefaultAsyncProducer { if (started.get()) { return; } + + // must use the classloader from the application context when creating reply manager, + // as it should inherit the classloader from app context and not the current which may be + // a different classloader + ClassLoader current = Thread.currentThread().getContextClassLoader(); + ClassLoader ac = endpoint.getCamelContext().getApplicationContextClassLoader(); try { + if (ac != null) { + Thread.currentThread().setContextClassLoader(ac); + } // validate that replyToType and replyTo is configured accordingly if (endpoint.getReplyToType() != null) { // setting temporary with a fixed replyTo is not supported @@ -96,6 +105,10 @@ public class JmsProducer extends DefaultAsyncProducer { } } catch (Exception e) { throw new FailedToCreateProducerException(endpoint, e); + } finally { + if (ac != null) { + Thread.currentThread().setContextClassLoader(current); + } } started.set(true); }