cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1170390 [2/2] - in /cxf/trunk: api/src/main/java/org/apache/cxf/ api/src/main/java/org/apache/cxf/io/ common/common/src/main/java/org/apache/cxf/common/annotation/ common/common/src/main/java/org/apache/cxf/common/classloader/ common/commo...
Date Tue, 13 Sep 2011 23:36:30 GMT
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java Tue Sep 13 23:36:28 2011
@@ -30,6 +30,9 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -72,6 +75,7 @@ import org.w3c.dom.Node;
 
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
@@ -357,12 +361,12 @@ public final class JAXBEncoderDecoder {
             } else {
                 LOG.warning("Schema associated with " + namespace + " is null");
             }
-            for (Field f : cls.getDeclaredFields()) {
+            for (Field f : ReflectionUtil.getDeclaredFields(cls)) {
                 if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                     XmlAttribute at = f.getAnnotation(XmlAttribute.class);
                     if (at == null) {
                         QName fname = new QName(namespace, f.getName());
-                        f.setAccessible(true);
+                        ReflectionUtil.setAccessible(f);
                         if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
                             writeArrayObject(marshaller, writer, fname, f.get(elValue));
                         } else {
@@ -465,10 +469,8 @@ public final class JAXBEncoderDecoder {
             while (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
                 QName q = reader.getName();
                 try {
-                    Field f =  null;
-                    try {
-                        f = cls.getDeclaredField(q.getLocalPart());
-                    } catch (NoSuchFieldException nsf) {
+                    Field f = ReflectionUtil.getDeclaredField(cls, q.getLocalPart());
+                    if (f == null) {
                         f = cls.getField(q.getLocalPart());
                     }
                     Type type = f.getGenericType();
@@ -738,63 +740,84 @@ public final class JAXBEncoderDecoder {
         return false;
     }
 
-    public static Object unmarshall(Unmarshaller u, Object source, QName elName,
-                                    Class<?> clazz, boolean unwrap) {
+    private static Object doUnmarshal(final Unmarshaller u,
+                                      final Object source,
+                                      final QName elName,
+                                      final Class<?> clazz,
+                                      final boolean unwrap) throws Exception {
+        
         Object obj = null;
-        try {
-            boolean unmarshalWithClass = true;
+        boolean unmarshalWithClass = true;
 
-            if (clazz == null
-                || (!clazz.isPrimitive() 
-                    && !clazz.isArray() 
-                    && !clazz.isEnum() 
-                    && !clazz.equals(Calendar.class)
-                    && (Modifier.isAbstract(clazz.getModifiers()) 
-                        || Modifier.isInterface(clazz.getModifiers())))) {
-                unmarshalWithClass = false;
-            }
-
-            if (clazz != null
-                && (clazz.getName().equals("javax.xml.datatype.XMLGregorianCalendar") || clazz.getName()
-                    .equals("javax.xml.datatype.Duration"))) {
-                // special treat two jaxb defined built-in abstract types
-                unmarshalWithClass = true;
-            }
-            if (source instanceof Node) {
-                obj = unmarshalWithClass ? u.unmarshal((Node)source, clazz) : u.unmarshal((Node)source);
-            } else if (source instanceof DepthXMLStreamReader) {
-                // JAXB optimizes a ton of stuff depending on the StreamReader impl. Thus,
-                // we REALLY want to pass the original reader in.   This is OK with JAXB
-                // as it doesn't read beyond the end so the DepthXMLStreamReader state
-                // would be OK when it returns.   The main winner is FastInfoset where parsing
-                // a testcase I have goes from about 300/sec to well over 1000.
-                
-                DepthXMLStreamReader dr = (DepthXMLStreamReader)source;
-                XMLStreamReader reader = dr.getReader();
-                if (u.getSchema() != null) {
-                    //validating, but we may need more namespaces
-                    reader = findExtraNamespaces(reader);
-                }
-                obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
-                    .unmarshal(dr.getReader());
-            } else if (source instanceof XMLStreamReader) {
-                XMLStreamReader reader = (XMLStreamReader)source;
-                if (u.getSchema() != null) {
-                    //validating, but we may need more namespaces
-                    reader = findExtraNamespaces(reader);
-                }
-                obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
-                    .unmarshal((XMLStreamReader)source);
-            } else if (source instanceof XMLEventReader) {
-                obj = unmarshalWithClass ? u.unmarshal((XMLEventReader)source, clazz) : u
-                    .unmarshal((XMLEventReader)source);
-            } else {
-                throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
+        if (clazz == null
+            || (!clazz.isPrimitive() 
+                && !clazz.isArray() 
+                && !clazz.isEnum() 
+                && !clazz.equals(Calendar.class)
+                && (Modifier.isAbstract(clazz.getModifiers()) 
+                    || Modifier.isInterface(clazz.getModifiers())))) {
+            unmarshalWithClass = false;
+        }
+
+        if (clazz != null
+            && (clazz.getName().equals("javax.xml.datatype.XMLGregorianCalendar") 
+                || clazz.getName().equals("javax.xml.datatype.Duration"))) {
+            // special treat two jaxb defined built-in abstract types
+            unmarshalWithClass = true;
+        }
+        if (source instanceof Node) {
+            obj = unmarshalWithClass ? u.unmarshal((Node)source, clazz) 
+                : u.unmarshal((Node)source);
+        } else if (source instanceof DepthXMLStreamReader) {
+            // JAXB optimizes a ton of stuff depending on the StreamReader impl. Thus,
+            // we REALLY want to pass the original reader in.   This is OK with JAXB
+            // as it doesn't read beyond the end so the DepthXMLStreamReader state
+            // would be OK when it returns.   The main winner is FastInfoset where parsing
+            // a testcase I have goes from about 300/sec to well over 1000.
+            
+            DepthXMLStreamReader dr = (DepthXMLStreamReader)source;
+            XMLStreamReader reader = dr.getReader();
+            if (u.getSchema() != null) {
+                //validating, but we may need more namespaces
+                reader = findExtraNamespaces(reader);
+            }
+            obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
+                .unmarshal(dr.getReader());
+        } else if (source instanceof XMLStreamReader) {
+            XMLStreamReader reader = (XMLStreamReader)source;
+            if (u.getSchema() != null) {
+                //validating, but we may need more namespaces
+                reader = findExtraNamespaces(reader);
+            }
+            obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
+                .unmarshal((XMLStreamReader)source);
+        } else if (source instanceof XMLEventReader) {
+            obj = unmarshalWithClass ? u.unmarshal((XMLEventReader)source, clazz) : u
+                .unmarshal((XMLEventReader)source);
+        } else if (source == null) {
+            throw new Fault(new Message("UNKNOWN_SOURCE", LOG, "null"));
+        } else {
+            throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
+        }
+        return unwrap ? getElementValue(obj) : obj;
+    }
+    public static Object unmarshall(final Unmarshaller u,
+                                    final Object source,
+                                    final QName elName,
+                                    final Class<?> clazz,
+                                    final boolean unwrap) {
+        try {
+            return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+                public Object run() throws Exception {
+                    return doUnmarshal(u, source, elName, clazz, unwrap);
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            Exception ex = e.getException();
+            if (ex instanceof Fault) {
+                ex.fillInStackTrace();
+                throw (Fault)ex;
             }
-        } catch (Fault ex) {
-            ex.fillInStackTrace();
-            throw ex;
-        } catch (Throwable ex) {
             if (ex instanceof javax.xml.bind.UnmarshalException) {
                 javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
                 if (unmarshalEx.getLinkedException() != null) {
@@ -804,11 +827,9 @@ public final class JAXBEncoderDecoder {
                     throw new Fault(new Message("UNMARSHAL_ERROR", LOG, 
                                                 unmarshalEx.getMessage()), ex);                    
                 }
-            } else {
-                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
-        }
-        return unwrap ? getElementValue(obj) : obj;
+            throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
+        }        
     }
     
     private static XMLStreamReader findExtraNamespaces(XMLStreamReader source) {
@@ -848,7 +869,7 @@ public final class JAXBEncoderDecoder {
                 } catch (Throwable t) {
                     //ignore
                 }
-                Field f = c.getClass().getDeclaredField("mNamespaces");
+                Field f = ReflectionUtil.getDeclaredField(c.getClass(), "mNamespaces");
                 f.setAccessible(true);
                 String ns[] = (String[])f.get(c);
                 for (int x = 0; x < ns.length; x += 2) {
@@ -858,7 +879,7 @@ public final class JAXBEncoderDecoder {
         } catch (Throwable t) {
             //internal JDK/xerces version
             try {
-                Field f = c.getClass().getDeclaredField("fNamespaceContext");
+                Field f =  ReflectionUtil.getDeclaredField(c.getClass(), "fNamespaceContext");
                 f.setAccessible(true);
                 Object c2 = f.get(c);
                 Enumeration enm = (Enumeration)c2.getClass().getMethod("getAllPrefixes").invoke(c2);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Tue Sep 13 23:36:28 2011
@@ -33,6 +33,8 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ClassHelper;
@@ -155,11 +157,11 @@ public class JAXRSInvoker extends Abstra
         }
 
         Object result = null;
-        ClassLoader contextLoader = null;
+        ClassLoaderHolder contextLoader = null;
         try {
             if (setServiceLoaderAsContextLoader(exchange.getInMessage())) {
-                contextLoader = Thread.currentThread().getContextClassLoader();
-                Thread.currentThread().setContextClassLoader(resourceObject.getClass().getClassLoader());
+                contextLoader = ClassLoaderUtils
+                    .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
             }
             result = invoke(exchange, resourceObject, methodToInvoke, params);
         } catch (Fault ex) {
@@ -190,7 +192,7 @@ public class JAXRSInvoker extends Abstra
         } finally {
             exchange.put(LAST_SERVICE_OBJECT, resourceObject);
             if (contextLoader != null) {
-                Thread.currentThread().setContextClassLoader(contextLoader);
+                contextLoader.reset();
             }
         }
         ClassResourceInfo subCri = null;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -29,6 +29,8 @@ import javax.ws.rs.core.Application;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.Server;
@@ -131,12 +133,12 @@ public class JAXRSServerFactoryBean exte
      * @return the server
      */
     public Server create() {
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             Bus bus = getBus();
             ClassLoader loader = bus.getExtension(ClassLoader.class);
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             serviceFactory.setBus(bus);
             checkResources(true);
@@ -191,7 +193,9 @@ public class JAXRSServerFactoryBean exte
         } catch (Exception e) {
             throw new ServiceConstructionException(e);
         } finally {
-            Thread.currentThread().setContextClassLoader(origLoader);
+            if (origLoader != null) {
+                origLoader.reset();
+            }
         }
 
         return server;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java Tue Sep 13 23:36:28 2011
@@ -21,6 +21,8 @@ package org.apache.cxf.jaxrs.client;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.transport.MessageObserver;
@@ -45,16 +47,18 @@ class ClientMessageObserver implements M
         message.getExchange().setInMessage(message);
         Bus origBus = BusFactory.getThreadDefaultBus(false);
         BusFactory.setThreadDefaultBus(cfg.getBus());
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             // execute chain
             chain.doIntercept(message);
         } finally {
             BusFactory.setThreadDefaultBus(origBus);
-            Thread.currentThread().setContextClassLoader(origLoader);
+            if (origLoader != null) {
+                origLoader.reset();
+            }
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ServerWebApplicationException.java Tue Sep 13 23:36:28 2011
@@ -34,6 +34,7 @@ import javax.ws.rs.core.Response.Respons
 import javax.ws.rs.ext.MessageBodyReader;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -107,7 +108,7 @@ public class ServerWebApplicationExcepti
     
     @Override
     public String toString() {
-        String lineSep = System.getProperty("line.separator");
+        String lineSep = SystemPropertyAction.getProperty("line.separator");
         
         StringBuilder sb = new StringBuilder();
         sb.append("Status : " + getStatus()).append(lineSep);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java Tue Sep 13 23:36:28 2011
@@ -42,6 +42,7 @@ import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
@@ -178,7 +179,7 @@ public class CodeGeneratorProvider imple
     private String getLineSep() {
         String os = ui.getQueryParameters().getFirst(OS_QUERY);
         if (os == null) {
-            return System.getProperty(SourceGenerator.LINE_SEP_PROPERTY);
+            return SystemPropertyAction.getProperty(SourceGenerator.LINE_SEP_PROPERTY);
         }
         return "unix".equals(os) ? "\r" : "\r\n";
     }
@@ -186,7 +187,7 @@ public class CodeGeneratorProvider imple
     private String getFileSep() {
         String os = ui.getQueryParameters().getFirst(OS_QUERY);
         if (os == null) {
-            return System.getProperty(SourceGenerator.FILE_SEP_PROPERTY);
+            return SystemPropertyAction.getProperty(SourceGenerator.FILE_SEP_PROPERTY);
         }
         return "unix".equals(os) ? "/" : "\\";
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java Tue Sep 13 23:36:28 2011
@@ -72,6 +72,7 @@ import org.apache.cxf.catalog.OASISCatal
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.ReflectionInvokationHandler;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
@@ -157,12 +158,12 @@ public class SourceGenerator {
     
     private String getLineSep() {
         String value = properties.get(LINE_SEP_PROPERTY);
-        return value == null ? System.getProperty(LINE_SEP_PROPERTY) : value;
+        return value == null ? SystemPropertyAction.getProperty(LINE_SEP_PROPERTY) : value;
     }
     
     private String getFileSep() {
         String value = properties.get(FILE_SEP_PROPERTY);
-        return value == null ? System.getProperty(FILE_SEP_PROPERTY) : value;
+        return value == null ? SystemPropertyAction.getProperty(FILE_SEP_PROPERTY) : value;
     }
     
     public void generateSource(String wadl, File srcDir, String codeType) {

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Tue Sep 13 23:36:28 2011
@@ -48,6 +48,8 @@ import org.w3c.dom.Element;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
@@ -311,12 +313,12 @@ public class EndpointImpl extends javax.
         
         ServerImpl serv = null;
         
-        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder loader = null;
         try {
             if (bus != null) {
                 ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                 if (newLoader != null) {
-                    Thread.currentThread().setContextClassLoader(newLoader);
+                    loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                 }
             }
             serv = getServer(addr);
@@ -349,7 +351,9 @@ public class EndpointImpl extends javax.
             
             throw new WebServiceException(ex);
         } finally {
-            Thread.currentThread().setContextClassLoader(loader);
+            if (loader != null) {
+                loader.reset();
+            }
         }
     }
     
@@ -361,12 +365,12 @@ public class EndpointImpl extends javax.
         if (server == null) {
             checkProperties();
 
-            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            ClassLoaderHolder loader = null;
             try {
                 if (bus != null) {
                     ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                     if (newLoader != null) {
-                        Thread.currentThread().setContextClassLoader(newLoader);
+                        loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                     }
                 }
     
@@ -466,7 +470,9 @@ public class EndpointImpl extends javax.
                     endpointName = endpoint.getEndpointInfo().getName();
                 }
             } finally {
-                Thread.currentThread().setContextClassLoader(loader);
+                if (loader != null) {
+                    loader.reset();
+                }
             }
         }
         return (ServerImpl) server;

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -27,6 +27,8 @@ import javax.xml.namespace.QName;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.handler.Handler;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.injection.ResourceInjector;
 import org.apache.cxf.endpoint.Client;
@@ -139,12 +141,12 @@ public class JaxWsProxyFactoryBean exten
      */
     @Override
     public synchronized Object create() {
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             if (getBus() != null) {
                 ClassLoader loader = getBus().getExtension(ClassLoader.class);
                 if (loader != null) {
-                    Thread.currentThread().setContextClassLoader(loader);
+                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                 }
             }
             
@@ -160,7 +162,9 @@ public class JaxWsProxyFactoryBean exten
             }
             return obj;
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -29,6 +29,8 @@ import javax.xml.ws.handler.Handler;
 import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.cxf.binding.soap.Soap12;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.injection.ResourceInjector;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.Server;
@@ -190,12 +192,12 @@ public class JaxWsServerFactoryBean exte
     }
     
     public Server create() {
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             if (bus != null) {
                 ClassLoader loader = bus.getExtension(ClassLoader.class);
                 if (loader != null) {
-                    Thread.currentThread().setContextClassLoader(loader);
+                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                 }
             }
 
@@ -205,7 +207,9 @@ public class JaxWsServerFactoryBean exte
             
             return server;
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }
     }
     

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -30,6 +30,8 @@ import javax.xml.namespace.QName;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
@@ -118,12 +120,12 @@ public class ClientProxyFactoryBean exte
      * @return the proxy. You must cast the returned object to the appropriate class before using it.
      */
     public synchronized Object create() {
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             if (getBus() != null) {
                 ClassLoader loader = getBus().getExtension(ClassLoader.class);
                 if (loader != null) {
-                    Thread.currentThread().setContextClassLoader(loader);
+                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                 }
             }
             configureObject();
@@ -176,7 +178,9 @@ public class ClientProxyFactoryBean exte
                                                classes, handler, obj);
             return obj;
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }
     }
 

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ServerFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -23,6 +23,8 @@ import java.util.List;
 
 
 import org.apache.cxf.BusException;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
@@ -129,13 +131,13 @@ public class ServerFactoryBean extends A
     
 
     public Server create() {
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             try {
                 if (bus != null) {
                     ClassLoader loader = bus.getExtension(ClassLoader.class);
                     if (loader != null) {
-                        Thread.currentThread().setContextClassLoader(loader);
+                        orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                     }
                 }
     
@@ -203,22 +205,26 @@ public class ServerFactoryBean extends A
             }
             return server;
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }            
     }
     public void init() {
         if (getServer() == null) {
-            ClassLoader orig = Thread.currentThread().getContextClassLoader();
+            ClassLoaderHolder orig = null;
             try {
                 if (bus != null) {
                     ClassLoader loader = bus.getExtension(ClassLoader.class);
                     if (loader != null) {
-                        Thread.currentThread().setContextClassLoader(loader);
+                        orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                     }
                 }
                 create();
             } finally {
-                Thread.currentThread().setContextClassLoader(orig);
+                if (orig != null) {
+                    orig.reset();
+                }
             }
         }
     }

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Tue Sep 13 23:36:28 2011
@@ -31,6 +31,7 @@ import java.lang.reflect.TypeVariable;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
+import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -65,6 +66,7 @@ import org.apache.cxf.common.WSDLConstan
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
 import org.apache.cxf.common.xmlschema.XmlSchemaUtils;
 import org.apache.cxf.common.xmlschema.XmlSchemaValidationManager;
@@ -2508,7 +2510,9 @@ public class ReflectionServiceFactoryBea
     }
 
     private boolean isValidate() {
-        return validate || System.getProperty("cxf.validateServiceSchemas", "false").equals("true");
+        return validate 
+            || AccessController.doPrivileged(new SystemPropertyAction("cxf.validateServiceSchemas",
+                                                                      "false")).equals("true");
     }
 
     /**

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java (original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java Tue Sep 13 23:36:28 2011
@@ -33,6 +33,7 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
 
 /**
@@ -48,7 +49,7 @@ public class ReadOnlyFileStorage impleme
     
     public static final String DATE_ONLY_FORMAT = "yyyy-MM-dd";
         
-    private static final String LINE_SEP = System.getProperty("line.separator"); 
+    private static final String LINE_SEP = SystemPropertyAction.getProperty("line.separator"); 
     private static final String DEFAULT_COLUMN_SEP = "|";
     
     private String columnSep = DEFAULT_COLUMN_SEP;
@@ -391,7 +392,7 @@ public class ReadOnlyFileStorage impleme
         String realPath = null;
         if (indexOpen == 0 && indexClose != -1) {
             String property = location.substring(1, indexClose);
-            String resolvedPath = System.getProperty(property);
+            String resolvedPath = SystemPropertyAction.getProperty(property);
             if (resolvedPath == null) {
                 throw new IllegalArgumentException("System property " + property + " can not be resolved");
             }

Modified: cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java (original)
+++ cxf/trunk/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java Tue Sep 13 23:36:28 2011
@@ -27,6 +27,7 @@ import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
@@ -58,7 +59,7 @@ public class CryptoLoader {
             return crypto;
         }
         
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             URL url = ClassLoaderUtils.getResource((String)o, this.getClass());
             if (url == null) {
@@ -66,7 +67,7 @@ public class CryptoLoader {
                         .getBus().getExtension(ResourceManager.class);
                 ClassLoader loader = manager.resolveResource("", ClassLoader.class);
                 if (loader != null) {
-                    Thread.currentThread().setContextClassLoader(loader);
+                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                 }
                 url = manager.resolveResource((String)o, URL.class);
             }
@@ -82,7 +83,9 @@ public class CryptoLoader {
             getCryptoCache(message).put(o, crypto);
             return crypto;
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }
     }
     

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java (original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java Tue Sep 13 23:36:28 2011
@@ -31,6 +31,8 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.jsse.TLSServerParameters;
 import org.apache.cxf.configuration.security.CertificateConstraintsType;
@@ -278,16 +280,18 @@ public class JettyHTTPDestination extend
         }
 
         // REVISIT: service on executor if associated with endpoint
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             BusFactory.setThreadDefaultBus(bus); 
             serviceRequest(context, req, resp);
         } finally {
             BusFactory.setThreadDefaultBus(null);
-            Thread.currentThread().setContextClassLoader(origLoader);
+            if (origLoader != null) { 
+                origLoader.reset();
+            }
         }    
     }
 

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java (original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java Tue Sep 13 23:36:28 2011
@@ -33,6 +33,7 @@ import javax.servlet.ServletContext;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.configuration.jsse.TLSServerParameters;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.transport.HttpUriMapper;
@@ -216,9 +217,11 @@ public class JettyHTTPServerEngine
         //this is most often seen in our unit/system tests that 
         //test things in the same VM.
         
-        String s = System.getProperty("org.apache.cxf.transports.http_jetty.DontClosePort." + port);
+        String s = SystemPropertyAction
+                .getProperty("org.apache.cxf.transports.http_jetty.DontClosePort." + port);
         if (s == null) {
-            s = System.getProperty("org.apache.cxf.transports.http_jetty.DontClosePort");
+            s = SystemPropertyAction
+                .getProperty("org.apache.cxf.transports.http_jetty.DontClosePort");
         }
         return !Boolean.valueOf(s);
     }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Tue Sep 13 23:36:28 2011
@@ -45,6 +45,7 @@ import javax.xml.namespace.QName;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
@@ -1632,7 +1633,7 @@ public class HTTPConduit 
                 LOG.fine("Content length: " + connection.getContentLength());
                 Map<String, List<String>> headerFields = connection.getHeaderFields();
                 if (null != headerFields) {
-                    String newLine = System.getProperty("line.separator");
+                    String newLine = SystemPropertyAction.getProperty("line.separator");
                     StringBuilder buf = new StringBuilder();
                     buf.append("Header fields: " + newLine);
                     for (String headerKey : headerFields.keySet()) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java Tue Sep 13 23:36:28 2011
@@ -24,6 +24,7 @@ import java.net.URL;
 import java.util.regex.Pattern;
 
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.apache.cxf.transports.http.configuration.ProxyServerType;
 
@@ -61,7 +62,7 @@ public class ProxyFactory {
     private static HTTPClientPolicy createSystemProxyConfiguration() {
         // Retrieve system properties (if any)
         HTTPClientPolicy systemProxyConfiguration = null;
-        String proxyHost = System.getProperty(HTTP_PROXY_HOST);
+        String proxyHost = SystemPropertyAction.getProperty(HTTP_PROXY_HOST);
         if (proxyHost != null) {
             // System is configured with a proxy, use it
 
@@ -70,11 +71,11 @@ public class ProxyFactory {
             systemProxyConfiguration.setProxyServerType(ProxyServerType.HTTP);
 
             // 8080 is the default proxy port value as per some documentation
-            String proxyPort = System.getProperty(HTTP_PROXY_PORT, "8080");
+            String proxyPort = SystemPropertyAction.getProperty(HTTP_PROXY_PORT, "8080");
             systemProxyConfiguration.setProxyServerPort(Integer.valueOf(proxyPort));
 
             // Load non proxy hosts
-            String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
+            String nonProxyHosts = SystemPropertyAction.getProperty(HTTP_NON_PROXY_HOSTS);
             if (!StringUtils.isEmpty(nonProxyHosts)) {
                 systemProxyConfiguration.setNonProxyHosts(nonProxyHosts);
             }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/SSLUtils.java Tue Sep 13 23:36:28 2011
@@ -47,6 +47,7 @@ import javax.net.ssl.TrustManagerFactory
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.configuration.security.FiltersType;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.security.transport.TLSSessionInfo;
@@ -246,12 +247,12 @@ public final class SSLUtils {
         if (keyStoreLocation != null) {
             logMsg = "KEY_STORE_SET";
         } else {
-            keyStoreLocation = System.getProperty("javax.net.ssl.keyStore");
+            keyStoreLocation = SystemPropertyAction.getProperty("javax.net.ssl.keyStore");
             if (keyStoreLocation != null) {
                 logMsg = "KEY_STORE_SYSTEM_PROPERTY_SET";
             } else {
                 keyStoreLocation =
-                    System.getProperty("user.home") + "/.keystore";
+                    SystemPropertyAction.getProperty("user.home") + "/.keystore";
                 logMsg = "KEY_STORE_NOT_SET";
             }
         }
@@ -278,7 +279,7 @@ public final class SSLUtils {
             logMsg = "KEY_STORE_PASSWORD_SET";
         } else {
             keyStorePassword =
-                System.getProperty("javax.net.ssl.keyStorePassword");
+                SystemPropertyAction.getProperty("javax.net.ssl.keyStorePassword");
             logMsg = keyStorePassword != null
                      ? "KEY_STORE_PASSWORD_SYSTEM_PROPERTY_SET"
                      : "KEY_STORE_PASSWORD_NOT_SET";
@@ -293,7 +294,7 @@ public final class SSLUtils {
             logMsg = "KEY_PASSWORD_SET";
         } else {
             keyPassword =
-                System.getProperty("javax.net.ssl.keyStorePassword");
+                SystemPropertyAction.getProperty("javax.net.ssl.keyStorePassword");
             logMsg = keyPassword != null
                      ? "KEY_PASSWORD_SYSTEM_PROPERTY_SET"
                      : "KEY_PASSWORD_NOT_SET";
@@ -458,12 +459,12 @@ public final class SSLUtils {
         if (trustStoreLocation != null) {
             logMsg = "TRUST_STORE_SET";
         } else {            
-            trustStoreLocation = System.getProperty("javax.net.ssl.trustStore");
+            trustStoreLocation = SystemPropertyAction.getProperty("javax.net.ssl.trustStore");
             if (trustStoreLocation != null) {
                 logMsg = "TRUST_STORE_SYSTEM_PROPERTY_SET";
             } else {
                 trustStoreLocation =
-                    System.getProperty("java.home") + "/lib/security/cacerts";
+                    SystemPropertyAction.getProperty("java.home") + "/lib/security/cacerts";
                 logMsg = "TRUST_STORE_NOT_SET";
             }
         }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java Tue Sep 13 23:36:28 2011
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletRes
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
@@ -105,16 +107,18 @@ public class CXFNonSpringServlet extends
 
     @Override
     protected void invoke(HttpServletRequest request, HttpServletResponse response) throws ServletException {
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             BusFactory.setThreadDefaultBus(bus);
             controller.invoke(request, response);
         } finally {
             BusFactory.setThreadDefaultBus(null);
-            Thread.currentThread().setContextClassLoader(origLoader);
+            if (origLoader != null) {
+                origLoader.reset();
+            }
         }
     }
 

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java Tue Sep 13 23:36:28 2011
@@ -31,6 +31,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.message.Message;
@@ -164,14 +166,14 @@ public class ServletController {
             } else {
                 EndpointInfo ei = d.getEndpointInfo();
                 Bus bus = d.getBus();
-                ClassLoader orig = Thread.currentThread().getContextClassLoader();
+                ClassLoaderHolder orig = null;
                 try {
                     ResourceManager manager = bus.getExtension(ResourceManager.class);
                     if (manager != null) {
                         ClassLoader loader = manager.resolveResource("", ClassLoader.class);
                         if (loader != null) {
                             //need to set the context classloader to the loader of the bundle
-                            Thread.currentThread().setContextClassLoader(loader);
+                            orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                         }
                     }
                     QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
@@ -199,7 +201,9 @@ public class ServletController {
                     }
                     invokeDestination(request, res, d);
                 } finally {
-                    Thread.currentThread().setContextClassLoader(orig);
+                    if (orig != null) { 
+                        orig.reset();
+                    }
                 }
                 
             }

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java (original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java Tue Sep 13 23:36:28 2011
@@ -41,6 +41,8 @@ import javax.jms.TextMessage;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.continuations.ContinuationProvider;
@@ -183,10 +185,10 @@ public class JMSDestination extends Abst
         onMessage(message, null);
     }
     public void onMessage(javax.jms.Message message, Session session) {
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             getLogger().log(Level.FINE, "server received request: ", message);
              // Build CXF message from JMS message
@@ -254,7 +256,9 @@ public class JMSDestination extends Abst
             getLogger().log(Level.WARNING, "can't get the right encoding information. " + ex);
         } finally {
             BusFactory.setThreadDefaultBus(null);
-            Thread.currentThread().setContextClassLoader(origLoader);
+            if (origLoader != null) { 
+                origLoader.reset();
+            }
         }
     }
 

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java (original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/continuations/JMSContinuation.java Tue Sep 13 23:36:28 2011
@@ -24,6 +24,8 @@ import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.continuations.Continuation;
 import org.apache.cxf.message.Message;
@@ -109,17 +111,19 @@ public class JMSContinuation implements 
     
     protected void doResume() {
         updateContinuations(true);
-        ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder origLoader = null;
         try {
             BusFactory.setThreadDefaultBus(bus);
             if (loader != null) {
-                Thread.currentThread().setContextClassLoader(loader);
+                origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
             incomingObserver.onMessage(inMessage);
         } finally {
             isPending = false;
             BusFactory.setThreadDefaultBus(null);
-            Thread.currentThread().setContextClassLoader(origLoader);            
+            if (origLoader != null) { 
+                origLoader.reset();
+            }
         }
     }
 

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java Tue Sep 13 23:36:28 2011
@@ -26,6 +26,7 @@ import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.message.Exchange;
@@ -94,7 +95,7 @@ public class PolicyOutInterceptor extend
                 if (LOG.isLoggable(Level.FINEST)) {
                     StringBuilder buf = new StringBuilder();
                     buf.append("Chosen alternative: ");
-                    String nl = System.getProperty("line.separator");
+                    String nl = SystemPropertyAction.getProperty("line.separator");
                     buf.append(nl);
                     for (Assertion a : assertions) {
                         PolicyUtils.printPolicyComponent(a, buf, 1);
@@ -125,7 +126,7 @@ public class PolicyOutInterceptor extend
                 if (LOG.isLoggable(Level.FINEST)) {
                     StringBuilder buf = new StringBuilder();
                     buf.append("Chosen alternative: ");
-                    String nl = System.getProperty("line.separator");
+                    String nl = SystemPropertyAction.getProperty("line.separator");
                     buf.append(nl);
                     for (Assertion a : assertions) {
                         PolicyUtils.printPolicyComponent(a, buf, 1);

Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java Tue Sep 13 23:36:28 2011
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.Constants;
@@ -179,7 +180,7 @@ public final class PolicyUtils {
     }
     
     private static void nl(StringBuilder buf) {
-        buf.append(System.getProperty("line.separator"));
+        buf.append(SystemPropertyAction.getProperty("line.separator"));
     }
     
     private static String typeToString(short type) {

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java (original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java Tue Sep 13 23:36:28 2011
@@ -42,6 +42,7 @@ import javax.annotation.PostConstruct;
 
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.rm.DestinationSequence;
 import org.apache.cxf.ws.rm.ProtocolVariation;
@@ -642,7 +643,8 @@ public class RMTxStore implements RMStor
     public synchronized void init() {
         
         if (null == connection) {
-            LOG.log(Level.FINE, "Using derby.system.home: {0}", System.getProperty("derby.system.home"));
+            LOG.log(Level.FINE, "Using derby.system.home: {0}", 
+                    SystemPropertyAction.getProperty("derby.system.home"));
             assert null != url;
             assert null != driverClassName;
             try {
@@ -692,7 +694,7 @@ public class RMTxStore implements RMStor
     }
     
     public static void deleteDatabaseFiles(String dbName, boolean now) {
-        String dsh = System.getProperty("derby.system.home");
+        String dsh = SystemPropertyAction.getProperty("derby.system.home");
        
         File root = null;  
         File log = null;

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java?rev=1170390&r1=1170389&r2=1170390&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractWSS4JInterceptor.java Tue Sep 13 23:36:28 2011
@@ -33,6 +33,7 @@ import javax.xml.namespace.QName;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.SoapInterceptor;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
@@ -174,7 +175,7 @@ public abstract class AbstractWSS4JInter
         String propFilename, 
         RequestData reqData
     ) throws WSSecurityException {
-        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        ClassLoaderHolder orig = null;
         try {
             try {
                 URL url = ClassLoaderUtils.getResource(propFilename, this.getClass());
@@ -183,7 +184,7 @@ public abstract class AbstractWSS4JInter
                             .getBus().getExtension(ResourceManager.class);
                     ClassLoader loader = manager.resolveResource("", ClassLoader.class);
                     if (loader != null) {
-                        Thread.currentThread().setContextClassLoader(loader);
+                        orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                     }
                     url = manager.resolveResource(propFilename, URL.class);
                 }
@@ -200,7 +201,9 @@ public abstract class AbstractWSS4JInter
             } 
             return CryptoFactory.getInstance(propFilename, this.getClassLoader(reqData.getMsgContext()));
         } finally {
-            Thread.currentThread().setContextClassLoader(orig);
+            if (orig != null) {
+                orig.reset();
+            }
         }
     }
 



Mime
View raw message