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);
+            }
         }
     }
 


Reply via email to