cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1336221 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/
Date Wed, 09 May 2012 14:20:06 GMT
Author: sergeyb
Date: Wed May  9 14:20:06 2012
New Revision: 1336221

URL: http://svn.apache.org/viewvc?rev=1336221&view=rev
Log:
Merged revisions 1336216 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1336216 | sergeyb | 2012-05-09 15:11:15 +0100 (Wed, 09 May 2012) | 1 line
  
  [CXF-4290] Adding an option to specify a custom loader for creating proxies
........

Added:
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java
      - copied unchanged from r1336216, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ProxyClassLoader.java
Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1336216

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1336221&r1=1336220&r2=1336221&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed May  9 14:20:06 2012
@@ -78,22 +78,28 @@ public class ClientProxyImpl extends Abs
     private static final String SLASH = "/";
     
     private ClassResourceInfo cri;
+    private ClassLoader proxyLoader;
     private boolean inheritHeaders;
     private boolean isRoot;
     private Map<String, Object> valuesMap = Collections.emptyMap();
     
-    public ClientProxyImpl(URI baseURI, ClassResourceInfo cri, boolean isRoot, 
-                           boolean inheritHeaders, Object... varValues) {
-        super(baseURI);
-        this.cri = cri;
-        this.isRoot = isRoot;
-        this.inheritHeaders = inheritHeaders;
-        initValuesMap(varValues);
+    public ClientProxyImpl(URI baseURI,
+                           ClassLoader loader,
+                           ClassResourceInfo cri, 
+                           boolean isRoot, 
+                           boolean inheritHeaders, 
+                           Object... varValues) {
+        this(new LocalClientState(baseURI), loader, cri, isRoot, inheritHeaders, varValues);
     }
     
-    public ClientProxyImpl(ClientState initialState, ClassResourceInfo cri, boolean isRoot,

-                           boolean inheritHeaders, Object... varValues) {
+    public ClientProxyImpl(ClientState initialState,
+                           ClassLoader loader,
+                           ClassResourceInfo cri, 
+                           boolean isRoot, 
+                           boolean inheritHeaders, 
+                           Object... varValues) {
         super(initialState);
+        this.proxyLoader = loader;
         this.cri = cri;
         this.isRoot = isRoot;
         this.inheritHeaders = inheritHeaders;
@@ -174,9 +180,10 @@ public class ClientProxyImpl extends Abs
             
             ClientState newState = getState().newState(uri, subHeaders, 
                  getTemplateParametersMap(ori.getURITemplate(), pathParams));
-            ClientProxyImpl proxyImpl = new ClientProxyImpl(newState, subCri, false, inheritHeaders);
+            ClientProxyImpl proxyImpl = 
+                new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders);
             proxyImpl.setConfiguration(getConfiguration());
-            return JAXRSClientFactory.create(m.getReturnType(), proxyImpl);
+            return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl);
         } 
         
         headers.putAll(paramHeaders);

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=1336221&r1=1336220&r2=1336221&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
Wed May  9 14:20:06 2012
@@ -49,6 +49,19 @@ public final class JAXRSClientFactory {
     }
     
     /**
+     * Creates a proxy using a custom class loader
+     * @param baseAddress baseAddress
+     * @param loader class loader
+     * @param cls resource class, if not interface then a CGLIB proxy will be created
+     * @return typed proxy
+     */
+    public static <T> T create(String baseAddress, Class<T> cls, ClassLoader
loader) {
+        JAXRSClientFactoryBean bean = getBean(baseAddress, cls, null);
+        bean.setClassLoader(loader);
+        return bean.create(cls);
+    }
+    
+    /**
      * Creates a proxy
      * @param baseURI baseURI
      * @param cls resource class, if not interface then a CGLIB proxy will be created
@@ -282,9 +295,11 @@ public final class JAXRSClientFactory {
         return proxy;
     }
     
-    static <T> T create(Class<T> cls, InvocationHandler handler) {
+    static <T> T createProxy(Class<T> cls, ClassLoader loader, InvocationHandler
handler) {
         
-        return cls.cast(ProxyHelper.getProxy(cls.getClassLoader(), new Class[]{cls, Client.class},
handler));
+        return cls.cast(ProxyHelper.getProxy(loader == null ? cls.getClassLoader() : loader,

+                                             new Class[]{cls, Client.class}, 
+                                             handler));
     }
     
     private static JAXRSClientFactoryBean getBean(String baseAddress, Class<?> cls,
String configLocation) {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=1336221&r1=1336220&r2=1336221&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Wed May  9 14:20:06 2012
@@ -51,6 +51,7 @@ public class JAXRSClientFactoryBean exte
     private boolean threadSafe;
     private long timeToKeepState;
     private Class serviceClass;
+    private ClassLoader proxyLoader;
     
     public JAXRSClientFactoryBean() {
         this(new JAXRSServiceFactoryBean());
@@ -63,6 +64,15 @@ public class JAXRSClientFactoryBean exte
     }
     
     /**
+     * Sets the custom class loader to be used 
+     * for creating proxies 
+     * @param loader
+     */
+    public void setClassLoader(ClassLoader loader) {
+        proxyLoader = loader;
+    }
+    
+    /**
      * Indicates if a single proxy or WebClient instance can be reused 
      * by multiple threads.
      *   
@@ -275,22 +285,28 @@ public class JAXRSClientFactoryBean exte
             ClientState actualState = getActualState();
             if (actualState == null) {
                 proxyImpl = 
-                    new ClientProxyImpl(URI.create(getAddress()), cri, isRoot, inheritHeaders,
varValues);
+                    new ClientProxyImpl(URI.create(getAddress()), proxyLoader, cri, isRoot,

+                                        inheritHeaders, varValues);
             } else {
                 proxyImpl = 
-                    new ClientProxyImpl(actualState, cri, isRoot, inheritHeaders, varValues);
+                    new ClientProxyImpl(actualState, proxyLoader, cri, isRoot, 
+                                        inheritHeaders, varValues);
             }
             initClient(proxyImpl, ep, actualState == null);    
             
             Client actualClient = null;
             try {
-                actualClient = (Client)ProxyHelper.getProxy(cri.getServiceClass().getClassLoader(),
-                                        new Class[]{cri.getServiceClass(), Client.class,

+                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,

+                                                    new Class[]{cri.getServiceClass(), 
+                                                                Client.class, 
                                                                 InvocationHandlerAware.class},

                                      proxyImpl);
             }

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java?rev=1336221&r1=1336220&r2=1336221&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
Wed May  9 14:20:06 2012
@@ -52,6 +52,22 @@ public class JAXRSClientFactoryBeanTest 
     }
     
     @Test
+    public void testCreateClientCustomLoader() throws Exception {
+        ProxyClassLoader loader = new ProxyClassLoader();
+        loader.addLoader(BookStore.class.getClassLoader());
+        
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("http://bar");
+        bean.setResourceClass(BookStore.class);
+        bean.setClassLoader(loader);
+        BookStore client = (BookStore)bean.createWithValues(BookStore.class);
+        assertNotNull(client);
+        // tricky to test the loader has been used correctly with Maven 
+        // given that the system loader loads all the test classes  
+        
+    }
+    
+    @Test
     public void testCreateClientWithUserResource() throws Exception {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setAddress("http://bar");
@@ -198,4 +214,6 @@ public class JAXRSClientFactoryBeanTest 
 
     }
     
-}
+
+    
+}
\ No newline at end of file



Mime
View raw message