cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1516827 - in /cxf/branches/2.7.x-fixes: ./ api/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/
Date Fri, 23 Aug 2013 12:13:19 GMT
Author: cschneider
Date: Fri Aug 23 12:13:18 2013
New Revision: 1516827

URL: http://svn.apache.org/r1516827
Log:
CXF-5228 backport

Added:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyClassLoader.java
      - copied, changed from r1516768, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java
Removed:
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyHelper.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Reverse-merged /cxf/trunk:r1516724-1516735,1516754-1516760
  Merged /cxf/trunk:r1516747

Copied: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyClassLoader.java
(from r1516768, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java)
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyClassLoader.java?p2=cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyClassLoader.java&p1=cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java&r1=1516768&r2=1516827&rev=1516827&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyClassLoader.java
Fri Aug 23 12:13:18 2013
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.jaxrs.client;
+package org.apache.cxf.common.util;
 
 import java.net.URL;
 import java.util.HashSet;

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyHelper.java?rev=1516827&r1=1516826&r2=1516827&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyHelper.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ProxyHelper.java
Fri Aug 23 12:13:18 2013
@@ -42,10 +42,44 @@ public class ProxyHelper {
     }
     
     protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler
handler) {
-        return Proxy.newProxyInstance(loader, interfaces, handler);
+        ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces);
+        return Proxy.newProxyInstance(combinedLoader, interfaces, handler);
     }
-    
-    
+
+    /**
+     * Return a classloader that can see all the given interfaces If the given loader can
see all interfaces
+     * then it is used. If not then a combined classloader of all interface classloaders
is returned.
+     * 
+     * @param loader use supplied class loader
+     * @param interfaces
+     * @return classloader that sees all interfaces
+     */
+    private ClassLoader getClassLoaderForInterfaces(ClassLoader loader, Class<?>[]
interfaces) {
+        if (canSeeAllInterfaces(loader, interfaces)) {
+            return loader;
+        }
+        ProxyClassLoader combined = new ProxyClassLoader();
+        for (Class<?> currentInterface : interfaces) {
+            combined.addLoader(currentInterface.getClassLoader());
+        }
+        return combined;
+    }
+
+    private boolean canSeeAllInterfaces(ClassLoader loader, Class<?>[] interfaces)
{
+        for (Class<?> currentInterface : interfaces) {
+            String ifName = currentInterface.getName();
+            try {
+                Class<?> ifClass = Class.forName(ifName, false, loader);
+                if (ifClass != currentInterface) {
+                    return false;
+                }
+            } catch (ClassNotFoundException e) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler
handler) {
         return HELPER.getProxyInternal(loader, interfaces, handler);
     }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=1516827&r1=1516826&r2=1516827&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Fri Aug 23 12:13:18 2013
@@ -307,22 +307,9 @@ public class JAXRSClientFactoryBean exte
             }
             initClient(proxyImpl, ep, actualState == null);    
             
-            Client actualClient = null;
-            try {
-                ClassLoader theLoader = proxyLoader == null ? cri.getServiceClass().getClassLoader()

-                                                            : proxyLoader;
-                actualClient = (Client)ProxyHelper.getProxy(theLoader,
-                                        new Class[]{cri.getServiceClass(), 
-                                                    Client.class, 
-                                                    InvocationHandlerAware.class}, 
-                                        proxyImpl);
-            } catch (Exception ex) {
-                actualClient = (Client)ProxyHelper.getProxy(Thread.currentThread().getContextClassLoader(),
-                                                    new Class[]{cri.getServiceClass(), 
-                                                                Client.class, 
-                                                                InvocationHandlerAware.class},

-                                     proxyImpl);
-            }
+            ClassLoader theLoader = proxyLoader == null ? cri.getServiceClass().getClassLoader()
: proxyLoader;
+            Class<?>[] ifaces = new Class[]{cri.getServiceClass(), Client.class, InvocationHandlerAware.class};
+            Client actualClient = (Client)ProxyHelper.getProxy(theLoader, ifaces, proxyImpl);
 
             notifyLifecycleManager(actualClient);
             this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED,
actualClient, ep);



Mime
View raw message