You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2011/08/17 18:04:46 UTC

svn commit: r1158793 - in /tuscany/sca-java-2.x/trunk/modules: binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/ databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/ databinding/src/main/java/org/apache/tusc...

Author: slaws
Date: Wed Aug 17 16:04:45 2011
New Revision: 1158793

URL: http://svn.apache.org/viewvc?rev=1158793&view=rev
Log:
TUSCANY-3922 - apply Jennifer's patch to add some missing doPrivileged calls around various classloader calls. Thanks for the patch Jennifer. 

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
    tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
    tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
    tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java?rev=1158793&r1=1158792&r2=1158793&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGenerator.java Wed Aug 17 16:04:45 2011
@@ -21,6 +21,9 @@ package org.apache.tuscany.sca.binding.w
 
 import java.lang.reflect.Method;
 import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -118,7 +121,17 @@ public class Interface2WSDLGenerator {
         this.dataBindings = dataBindings;
         this.xsdFactory = xsdFactory;
         this.monitor = monitor;
-        this.factory = WSDLFactory.newInstance();
+        try{
+            this.factory = AccessController.doPrivileged(new PrivilegedExceptionAction<WSDLFactory>() {
+                public WSDLFactory run() throws WSDLException{
+                    WSDLFactory factory =  WSDLFactory.newInstance();
+                    return factory;
+                 }
+            });
+        } catch (PrivilegedActionException e){
+            throw (WSDLException) e.getException();
+        }
+        
     }
 
     /**

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java?rev=1158793&r1=1158792&r2=1158793&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java Wed Aug 17 16:04:45 2011
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
 import java.lang.ref.SoftReference;
 import java.net.URI;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
@@ -472,7 +473,14 @@ public class JAXBContextCache {
         for (Class<?> cls : classes) {
             Package pkg = getPackage(cls);
             if (pkg != null) {
-                pkgs.put(pkg, cls.getClassLoader());
+                final Class fcls = cls;
+                ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
+                    ClassLoader cl = fcls.getClassLoader();
+                    return cl;
+                 }
+            });
+                pkgs.put(pkg, cl);
             }
         }
         return pkgs;

Modified: tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java?rev=1158793&r1=1158792&r2=1158793&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java Wed Aug 17 16:04:45 2011
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.databinding.javabeans;
 
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -30,6 +31,8 @@ import java.io.OutputStream;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.logging.Logger;
 
 import org.apache.tuscany.sca.databinding.BaseDataBinding;
@@ -88,7 +91,16 @@ public class JavaBeansDataBinding extend
                 //     because Collection classes are loaded by the System ClassLoader but their contents
                 //     may be loaded from another ClassLoader
                 //
-                ClassLoader classLoaderToUse = targetDataType.getPhysical().getClassLoader();
+                final DataType fTargetDataType = targetDataType;
+                ClassLoader classLoaderToUse = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+                    public ClassLoader run() {
+                        ClassLoader cl = fTargetDataType.getPhysical().getClassLoader();
+                        return cl;
+                    }
+                });
+                
+                
+                
                 if (classLoaderToUse == null) {
                     classLoaderToUse = clazz.getClassLoader();
                 }

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java?rev=1158793&r1=1158792&r2=1158793&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java Wed Aug 17 16:04:45 2011
@@ -18,8 +18,12 @@
  */
 package org.apache.tuscany.sca.implementation.java.invocation;
 
+
+
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -94,7 +98,12 @@ public class JavaImplementationInvoker i
         // store the current thread context classloader
         // as we need to replace it with the class loader
         // used to load the java class as per SCA Spec
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        final ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
+                    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+                    return tccl;
+                 }
+            });
         
         try {
             // The following call might create a new conversation, as a result, the msg.getConversationID() might 
@@ -107,7 +116,7 @@ public class JavaImplementationInvoker i
             	injectCallbacks(wrapper, (JavaInterface)interfaze.getCallbackInterface());
             }
             
-            Object instance = wrapper.getInstance();
+            final Object instance = wrapper.getInstance();
 
             // If the method couldn't be computed statically, or the instance being
             // invoked is a user-specified callback object that doesn't implement
@@ -125,8 +134,14 @@ public class JavaImplementationInvoker i
             // Set 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;
+                 }
+            });
+            
             
-            Thread.currentThread().setContextClassLoader(instance.getClass().getClassLoader());
             
             int argumentHolderCount = 0;
 
@@ -245,8 +260,14 @@ public class JavaImplementationInvoker i
         } catch (Exception e) {
             msg.setFaultBody(e);           
         } finally {
-            // set the tccl 
-            Thread.currentThread().setContextClassLoader(tccl);
+            // set the tccl
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    Thread.currentThread().setContextClassLoader(tccl);
+                    return null;
+                 }
+            });
+            
         }
         return msg;
     }