axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r546993 - /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
Date Wed, 13 Jun 2007 18:30:02 GMT
Author: gawor
Date: Wed Jun 13 11:30:01 2007
New Revision: 546993

URL: http://svn.apache.org/viewvc?view=rev&rev=546993
Log:
when creating a dynamic proxy ensure that all the interfaces of the proxy are loadable by
the same classloader

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java?view=diff&rev=546993&r1=546992&r2=546993
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/ServiceDelegate.java
Wed Jun 13 11:30:01 2007
@@ -237,10 +237,29 @@
                     "Unable to getPort for port QName " + portName.toString());
         }
 
-        JAXWSProxyHandler proxyHandler = new JAXWSProxyHandler(this, sei, endpointDesc);
-
-        Class[] seiClazz = new Class[] { sei, org.apache.axis2.jaxws.spi.BindingProvider.class
};
-        Object proxyClass = Proxy.newProxyInstance(getClassLoader(sei), seiClazz, proxyHandler);
+        String[] interfacesNames = 
+            new String [] {sei.getName(), org.apache.axis2.jaxws.spi.BindingProvider.class.getName()};
+        
+        // As required by java.lang.reflect.Proxy, ensure that the interfaces
+        // for the proxy are loadable by the same class loader. 
+        Class[] interfaces = null;
+        // First, let's try loading the interfaces with the SEI classLoader
+        ClassLoader classLoader = getClassLoader(sei);
+        try {
+            interfaces = loadClasses(classLoader, interfacesNames);
+        } catch (ClassNotFoundException e1) {
+            // Let's try with context classLoader now
+            classLoader = getContextClassLoader();
+            try {
+                interfaces = loadClasses(classLoader, interfacesNames);
+            } catch (ClassNotFoundException e2) {
+                // TODO: NLS
+                throw ExceptionFactory.makeWebServiceException("Unable to load proxy classes",
e2);
+            }
+        }
+        
+        JAXWSProxyHandler proxyHandler = new JAXWSProxyHandler(this, interfaces[0], endpointDesc);
+        Object proxyClass = Proxy.newProxyInstance(classLoader, interfaces, proxyHandler);
         return sei.cast(proxyClass);
     }
 
@@ -404,6 +423,65 @@
 
         return cl;
     }
+    
+    /** @return ClassLoader */
+    private static ClassLoader getContextClassLoader() {
+        // NOTE: This method must remain private because it uses AccessController
+        ClassLoader cl = null;
+        try {
+            cl = (ClassLoader)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws ClassNotFoundException {
+                            return Thread.currentThread().getContextClassLoader();
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw ExceptionFactory.makeWebServiceException(e.getException());
+        }
+
+        return cl;
+    }
+    
+    /**
+     * Return the class for this name
+     *
+     * @return Class
+     */
+    private static Class forName(final String className, final boolean initialize,
+                                 final ClassLoader classLoader) throws ClassNotFoundException
{
+        // NOTE: This method must remain protected because it uses AccessController
+        Class cl = null;
+        try {
+            cl = (Class)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws ClassNotFoundException {
+                            return Class.forName(className, initialize, classLoader);
+                        }
+                    }
+            );
+        } catch (PrivilegedActionException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("Exception thrown from AccessController: " + e);
+            }
+            throw (ClassNotFoundException)e.getException();
+        }
+
+        return cl;
+    }
+    
+    private static Class[] loadClasses(ClassLoader classLoader, String[] classNames)
+        throws ClassNotFoundException {
+        Class[] classes = new Class[classNames.length];
+        for (int i = 0; i < classNames.length; i++) {
+            classes[i] = forName(classNames[i], true, classLoader);
+        }
+        return classes;
+    }
+    
 }
 
 /**



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message