You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2017/03/22 19:19:17 UTC

cxf git commit: [CXF-6852] Some work on auto-cleanup of classloader for dynamic client

Repository: cxf
Updated Branches:
  refs/heads/master 013e6c800 -> e4cb2ea43


[CXF-6852] Some work on auto-cleanup of classloader for dynamic client


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

Branch: refs/heads/master
Commit: e4cb2ea437185caa28b95a2344ffa8aa0ba516b7
Parents: 013e6c8
Author: Daniel Kulp <dk...@apache.org>
Authored: Wed Mar 22 14:32:31 2017 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Wed Mar 22 15:19:07 2017 -0400

----------------------------------------------------------------------
 .../endpoint/dynamic/DynamicClientFactory.java  | 27 +++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e4cb2ea4/rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java b/rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
index 600a2f8..1640cfc 100644
--- a/rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
+++ b/rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
@@ -284,6 +284,25 @@ public class DynamicClientFactory {
         return createClient(wsdlUrl.toString(), service, classLoader, port, bindingFiles);
     }
 
+    static class DynamicClientImpl extends ClientImpl implements AutoCloseable {
+        final ClassLoader cl;
+        final ClassLoader orig;
+        DynamicClientImpl(Bus bus, Service svc, QName port, 
+                          EndpointImplFactory endpointImplFactory,
+                          ClassLoader l) {
+            super(bus, svc, port, endpointImplFactory);
+            cl = l;
+            orig = Thread.currentThread().getContextClassLoader();
+        }
+        @Override
+        public void close() throws Exception {
+            destroy();
+            if (Thread.currentThread().getContextClassLoader() == cl) {
+                Thread.currentThread().setContextClassLoader(orig);
+            }
+        }
+    }
+    
     public Client createClient(String wsdlUrl, QName service,
                                ClassLoader classLoader, QName port,
                                List<String> bindingFiles) {
@@ -298,9 +317,6 @@ public class DynamicClientFactory {
         sf.setAllowElementRefs(allowRefs);
         Service svc = sf.create();
 
-        ClientImpl client = new ClientImpl(bus, svc, port,
-                                           getEndpointImplFactory());
-
         //all SI's should have the same schemas
         SchemaCollection schemas = svc.getServiceInfos().get(0).getXmlSchemaCollection();
 
@@ -378,7 +394,7 @@ public class DynamicClientFactory {
             throw new IllegalStateException("Internal error; a directory returns a malformed URL: "
                                             + mue.getMessage(), mue);
         }
-        ClassLoader cl = ClassLoaderUtils.getURLClassLoader(urls, classLoader);
+        final ClassLoader cl = ClassLoaderUtils.getURLClassLoader(urls, classLoader);
 
         JAXBContext context;
         Map<String, Object> contextProperties = jaxbContextProperties;
@@ -402,6 +418,9 @@ public class DynamicClientFactory {
         databinding.setContext(context);
         svc.setDataBinding(databinding);
 
+        ClientImpl client = new DynamicClientImpl(bus, svc, port,
+                                                  getEndpointImplFactory(), cl);
+
         ServiceInfo svcfo = client.getEndpoint().getEndpointInfo().getService();
 
         // Setup the new classloader!