Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 408E4D767 for ; Mon, 21 Jan 2013 12:44:56 +0000 (UTC) Received: (qmail 50064 invoked by uid 500); 21 Jan 2013 12:44:56 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 49947 invoked by uid 500); 21 Jan 2013 12:44:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 49844 invoked by uid 99); 21 Jan 2013 12:44:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jan 2013 12:44:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jan 2013 12:44:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9143423888D2; Mon, 21 Jan 2013 12:44:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1436312 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java Date: Mon, 21 Jan 2013 12:44:29 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130121124429.9143423888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Mon Jan 21 12:44:29 2013 New Revision: 1436312 URL: http://svn.apache.org/viewvc?rev=1436312&view=rev Log: CAMEL-5748: direct-vm component should favor using their own application context class loader to avoid using class loaders from other Camel apps. Modified: camel/branches/camel-2.10.x/ (props changed) camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java Propchange: camel/branches/camel-2.10.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1436308 Propchange: camel/branches/camel-2.10.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java?rev=1436312&r1=1436311&r2=1436312&view=diff ============================================================================== --- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java (original) +++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/directvm/DirectVmProcessor.java Mon Jan 21 12:44:29 2013 @@ -20,12 +20,15 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.processor.DelegateProcessor; import org.apache.camel.util.ExchangeHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * */ public final class DirectVmProcessor extends DelegateProcessor { + private static final transient Logger LOG = LoggerFactory.getLogger(DirectVmProcessor.class); private final DirectVmEndpoint endpoint; public DirectVmProcessor(Processor processor, DirectVmEndpoint endpoint) { @@ -37,11 +40,26 @@ public final class DirectVmProcessor ext public void process(Exchange exchange) throws Exception { // need to use a copy of the incoming exchange, so we route using this camel context Exchange copy = prepareExchange(exchange); + + ClassLoader current = Thread.currentThread().getContextClassLoader(); + boolean changed = false; try { + // set TCCL to application context class loader if given + ClassLoader appClassLoader = endpoint.getCamelContext().getApplicationContextClassLoader(); + if (appClassLoader != null) { + LOG.trace("Setting Thread ContextClassLoader to {}", appClassLoader); + Thread.currentThread().setContextClassLoader(appClassLoader); + changed = true; + } getProcessor().process(copy); } finally { // make sure to copy results back ExchangeHelper.copyResults(exchange, copy); + // restore TCCL if it was changed during processing + if (changed) { + LOG.trace("Restoring Thread ContextClassLoader to {}", current); + Thread.currentThread().setContextClassLoader(current); + } } }