From 562a484efbe0259642737f835cd6ece3c9ec7c17 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 16 Sep 2011 12:56:23 +0000 Subject: TUSCANY-3946 - only reset the TCCL if it's not already set to the contribution classloader git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171532 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/invocation/JavaImplementationInvoker.java | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java index 33e1b1891d..33008c2e25 100644 --- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java +++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java @@ -84,7 +84,7 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics @SuppressWarnings("unchecked") public Message invoke(Message msg) { - + Operation op = msg.getOperation(); if (op == null) { op = this.operation; @@ -104,6 +104,7 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics return tccl; } }); + ClassLoader contributionClassloader = null; try { // The following call might create a new conversation, as a result, the msg.getConversationID() might @@ -131,17 +132,19 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics } } - // Set the thread context classloader of the thread used to invoke an operation + // TUSCANY-3946 - If the TCCL has not already been set to the contribution classloader then + // set it so that the thread context classloader of the thread used to invoke an operation // of a Java POJO component implementation is the class loader of the contribution - // that contains the POJO implementation class. - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(instance.getClass().getClassLoader()); - return null; - } - }); - - + // used to load the POJO implementation class. + contributionClassloader = instance.getClass().getClassLoader(); + if (tccl != contributionClassloader){ + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Thread.currentThread().setContextClassLoader(instance.getClass().getClassLoader()); + return null; + } + }); + } int argumentHolderCount = 0; @@ -260,14 +263,16 @@ public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics } catch (Exception e) { msg.setFaultBody(e); } finally { - // set the tccl - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(tccl); - return null; - } - }); - + // reset the tccl if it was replaced above + // with the contribution classloader + if (tccl != contributionClassloader){ + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Thread.currentThread().setContextClassLoader(tccl); + return null; + } + }); + } } return msg; } -- cgit v1.2.3