cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [09/15] cxf git commit: [CXF-6077] Make sure we use the classloader for the extension that is trying to load/create the wsdl extension
Date Fri, 07 Nov 2014 19:12:56 GMT
[CXF-6077] Make sure we use the classloader for the extension that is trying to load/create
the wsdl extension


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e3ac9e98
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e3ac9e98
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e3ac9e98

Branch: refs/heads/3.0.x-fixes
Commit: e3ac9e98557ef2f2383aff238d463fdef7f22dc0
Parents: 556c238
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Oct 31 16:59:09 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Nov 7 13:50:40 2014 -0500

----------------------------------------------------------------------
 .../org/apache/cxf/common/util/ASMHelper.java   | 35 +++++++++++++++++---
 .../corba/wsdl/WSDLExtensionRegister.java       |  4 ++-
 .../xml/wsdl11/XMLWSDLExtensionLoader.java      |  4 ++-
 .../transport/http/HTTPWSDLExtensionLoader.java |  3 +-
 .../jms/wsdl11/JMSWSDLExtensionLoader.java      |  3 +-
 .../impl/AddressingWSDLExtensionLoader.java     |  3 +-
 .../apache/cxf/wsdl/JAXBExtensionHelper.java    | 19 +++++++----
 .../cxf/xkms/itests/BasicIntegrationTest.java   |  2 +-
 8 files changed, 57 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/core/src/main/java/org/apache/cxf/common/util/ASMHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/ASMHelper.java b/core/src/main/java/org/apache/cxf/common/util/ASMHelper.java
index b183968..bf1d692 100644
--- a/core/src/main/java/org/apache/cxf/common/util/ASMHelper.java
+++ b/core/src/main/java/org/apache/cxf/common/util/ASMHelper.java
@@ -41,7 +41,9 @@ public class ASMHelper {
     protected static final Map<Class<?>, String> NONPRIMITIVE_MAP = new HashMap<Class<?>,
String>();
     protected static final Map<Class<?>, Integer> PRIMITIVE_ZERO_MAP = new HashMap<Class<?>,
Integer>();
     
-    protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>>
LOADER_MAP 
+    protected static final Map<ClassLoader, WeakReference<TypeHelperClassLoader>>
LOADER_MAP 
+        = new WeakIdentityHashMap<ClassLoader, WeakReference<TypeHelperClassLoader>>();
+    protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>>
CLASS_MAP 
         = new WeakIdentityHashMap<Class<?>, WeakReference<TypeHelperClassLoader>>();
     
     protected static boolean badASM;
@@ -308,7 +310,7 @@ public class ASMHelper {
     }
     
     
-    public Class<?> loadClass(String className, Class<?> clz , byte[] bytes)
{ 
+    public Class<?> loadClass(String className, Class<?> clz , byte[] bytes)
{
         TypeHelperClassLoader loader = getTypeHelperClassLoader(clz);
         synchronized (loader) {
             Class<?> cls = loader.lookupDefinedClass(className);
@@ -318,22 +320,47 @@ public class ASMHelper {
             return cls;
         }
     }
+    public Class<?> loadClass(String className, ClassLoader l , byte[] bytes) {
+        TypeHelperClassLoader loader = getTypeHelperClassLoader(l);
+        synchronized (loader) {
+            Class<?> cls = loader.lookupDefinedClass(className);
+            if (cls == null) {
+                return loader.defineClass(className, bytes);
+            }
+            return cls;
+        }
+    }
     public Class<?> findClass(String className, Class<?> clz) { 
         TypeHelperClassLoader loader = getTypeHelperClassLoader(clz);
         return loader.lookupDefinedClass(className);
     }
+    public Class<?> findClass(String className, ClassLoader l) { 
+        TypeHelperClassLoader loader = getTypeHelperClassLoader(l);
+        return loader.lookupDefinedClass(className);
+    }
     
-    private static synchronized TypeHelperClassLoader getTypeHelperClassLoader(Class<?>
l) {
+    private static synchronized TypeHelperClassLoader getTypeHelperClassLoader(ClassLoader
l) {
         WeakReference<TypeHelperClassLoader> ref = LOADER_MAP.get(l);
         TypeHelperClassLoader ret;
         if (ref == null || ref.get() == null) {
-            ret = new TypeHelperClassLoader(l.getClassLoader());
+            ret = new TypeHelperClassLoader(l);
             LOADER_MAP.put(l, new WeakReference<TypeHelperClassLoader>(ret));
         } else {
             ret = ref.get();
         }
         return ret;
     }
+    private static synchronized TypeHelperClassLoader getTypeHelperClassLoader(Class<?>
cls) {
+        WeakReference<TypeHelperClassLoader> ref = CLASS_MAP.get(cls);
+        TypeHelperClassLoader ret;
+        if (ref == null || ref.get() == null) {
+            ret = new TypeHelperClassLoader(cls.getClassLoader());
+            CLASS_MAP.put(cls, new WeakReference<TypeHelperClassLoader>(ret));
+        } else {
+            ret = ref.get();
+        }
+        return ret;
+    }
     
     public static class TypeHelperClassLoader extends ClassLoader {
         ConcurrentHashMap<String, Class<?>> defined = new ConcurrentHashMap<String,
Class<?>>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/wsdl/WSDLExtensionRegister.java
----------------------------------------------------------------------
diff --git a/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/wsdl/WSDLExtensionRegister.java
b/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/wsdl/WSDLExtensionRegister.java
index ef006d2..f50f780 100644
--- a/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/wsdl/WSDLExtensionRegister.java
+++ b/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/wsdl/WSDLExtensionRegister.java
@@ -70,7 +70,9 @@ public final class WSDLExtensionRegister implements WSDLExtensionLoader
{
         try {
             JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(),
                                               parentType, 
-                                              elementType);
+                                              elementType,
+                                              null,
+                                              this.getClass().getClassLoader());
         } catch (JAXBException e) {
             //ignore, won't support CORBA
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/wsdl11/XMLWSDLExtensionLoader.java
----------------------------------------------------------------------
diff --git a/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/wsdl11/XMLWSDLExtensionLoader.java
b/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/wsdl11/XMLWSDLExtensionLoader.java
index 62de127..2e4e451 100644
--- a/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/wsdl11/XMLWSDLExtensionLoader.java
+++ b/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/wsdl11/XMLWSDLExtensionLoader.java
@@ -56,7 +56,9 @@ public final class XMLWSDLExtensionLoader implements WSDLExtensionLoader
{
         try {
             JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(),
                                               parentType, 
-                                              elementType);
+                                              elementType,
+                                              null,
+                                              XMLWSDLExtensionLoader.class.getClassLoader());
         } catch (JAXBException e) {
             //ignore, won't support XML
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPWSDLExtensionLoader.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPWSDLExtensionLoader.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPWSDLExtensionLoader.java
index cdb9c51..32a48c2 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPWSDLExtensionLoader.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPWSDLExtensionLoader.java
@@ -50,7 +50,8 @@ public final class HTTPWSDLExtensionLoader implements WSDLExtensionLoader
{
         try {
             JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(),
                                               parentType, 
-                                              elementType);
+                                              elementType, null,
+                                              this.getClass().getClassLoader());
         } catch (JAXBException e) {
             //ignore, won't support XML
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/wsdl11/JMSWSDLExtensionLoader.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/wsdl11/JMSWSDLExtensionLoader.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/wsdl11/JMSWSDLExtensionLoader.java
index b46d9e6..fcbabdf 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/wsdl11/JMSWSDLExtensionLoader.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/wsdl11/JMSWSDLExtensionLoader.java
@@ -64,7 +64,8 @@ public final class JMSWSDLExtensionLoader implements WSDLExtensionLoader
{
 
     public void addExtensions(WSDLManager manager, Class<?> parentType, Class<?>
elementType) {
         try {
-            JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(), parentType,
elementType);
+            JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(), parentType,
elementType, null,
+                                              this.getClass().getClassLoader());
         } catch (JAXBException e) {
             // ignore, won't support XML
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/AddressingWSDLExtensionLoader.java
----------------------------------------------------------------------
diff --git a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/AddressingWSDLExtensionLoader.java
b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/AddressingWSDLExtensionLoader.java
index 61dd008..baefcbc 100644
--- a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/AddressingWSDLExtensionLoader.java
+++ b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/impl/AddressingWSDLExtensionLoader.java
@@ -45,7 +45,8 @@ public final class AddressingWSDLExtensionLoader implements WSDLExtensionLoader
         try {
             JAXBExtensionHelper.addExtensions(manager.getExtensionRegistry(),
                                               parentType, 
-                                              elementType);
+                                              elementType, null,
+                                              this.getClass().getClassLoader());
         } catch (JAXBException e) {
             //ignore, won't support XML
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
----------------------------------------------------------------------
diff --git a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
index c4df3e2..abe0bcc 100644
--- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
+++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
@@ -167,13 +167,20 @@ public class JAXBExtensionHelper implements ExtensionSerializer, ExtensionDeseri
                                      Class<?> parentType,
                                      Class<?> cls,
                                      String namespace) throws JAXBException {
+        addExtensions(registry, parentType, cls, namespace, cls.getClassLoader());
+    }
+    public static void addExtensions(ExtensionRegistry registry,
+                                     Class<?> parentType,
+                                     Class<?> cls,
+                                     String namespace,
+                                     ClassLoader loader) throws JAXBException {
         
         JAXBExtensionHelper helper = new JAXBExtensionHelper(cls, namespace);
         boolean found = false;
         Class<?> extCls = cls;
         try {
             Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(cls)
+ ".ObjectFactory",
-                                                   true, cls.getClassLoader());
+                                                   true, loader);
             Method methods[] = ReflectionUtil.getDeclaredMethods(objectFactory);
             for (Method method : methods) {
                 if (method.getParameterTypes().length == 1
@@ -188,7 +195,7 @@ public class JAXBExtensionHelper implements ExtensionSerializer, ExtensionDeseri
                         }
                         QName elementType = new QName(ns, name);
                         if (!ExtensibilityElement.class.isAssignableFrom(extCls)) {
-                            extCls = createExtensionClass(cls, elementType);
+                            extCls = createExtensionClass(cls, elementType, loader);
                             helper.setExtensionClass(extCls);
                         }
                         registry.registerDeserializer(parentType, elementType, helper); 
@@ -225,7 +232,7 @@ public class JAXBExtensionHelper implements ExtensionSerializer, ExtensionDeseri
                     }
                     QName elementType = new QName(ns, name);
                     if (!ExtensibilityElement.class.isAssignableFrom(extCls)) {
-                        extCls = createExtensionClass(cls, elementType);
+                        extCls = createExtensionClass(cls, elementType, loader);
                         helper.setExtensionClass(extCls);
                     }
                     registry.registerDeserializer(parentType, elementType, helper); 
@@ -445,11 +452,11 @@ public class JAXBExtensionHelper implements ExtensionSerializer, ExtensionDeseri
     };
     
     //CHECKSTYLE:OFF - very complicated ASM code
-    private static Class<?> createExtensionClass(Class<?> cls, QName qname) {
+    private static Class<?> createExtensionClass(Class<?> cls, QName qname, ClassLoader
loader) {
         
         String className = ASMHelper.periodToSlashes(cls.getName());
         ASMHelper helper = new ASMHelper();
-        Class<?> extClass = helper.findClass(className + "Extensibility", cls);
+        Class<?> extClass = helper.findClass(className + "Extensibility", loader);
         if (extClass != null) {
             return extClass;
         }
@@ -685,7 +692,7 @@ public class JAXBExtensionHelper implements ExtensionSerializer, ExtensionDeseri
         cw.visitEnd();
 
         byte[] bytes = cw.toByteArray();
-        return helper.loadClass(className + "Extensibility", cls, bytes);
+        return helper.loadClass(className + "Extensibility", loader, bytes);
     }    
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e3ac9e98/services/xkms/xkms-itests/src/test/java/org/apache/cxf/xkms/itests/BasicIntegrationTest.java
----------------------------------------------------------------------
diff --git a/services/xkms/xkms-itests/src/test/java/org/apache/cxf/xkms/itests/BasicIntegrationTest.java
b/services/xkms/xkms-itests/src/test/java/org/apache/cxf/xkms/itests/BasicIntegrationTest.java
index 1d5e92a..150ae78 100644
--- a/services/xkms/xkms-itests/src/test/java/org/apache/cxf/xkms/itests/BasicIntegrationTest.java
+++ b/services/xkms/xkms-itests/src/test/java/org/apache/cxf/xkms/itests/BasicIntegrationTest.java
@@ -92,7 +92,7 @@ public class BasicIntegrationTest {
             features(xkmsFeatures, "cxf-xkms-service", "cxf-xkms-client", "cxf-xkms-ldap"),
             configureConsole().ignoreLocalConsole(),
 
-            //KarafDistributionOption.keepRuntimeFolder(),
+            //org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder(),
             //CoreOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
         };
     }


Mime
View raw message