cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [4/7] cxf git commit: [CXF-6852] Some work on auto-cleanup of classloader for dynamic client
Date Wed, 22 Mar 2017 20:20:15 GMT
[CXF-6852] Some work on auto-cleanup of classloader for dynamic client

# Conflicts:
#	rt/frontend/simple/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java


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

Branch: refs/heads/3.1.x-fixes
Commit: a4fad996752b933f0926a46dd0664c10bd1cfed2
Parents: b1227d6
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Mar 22 14:32:31 2017 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Mar 22 15:21:56 2017 -0400

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/a4fad996/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 2def391..d770095 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
@@ -283,6 +283,25 @@ public class DynamicClientFactory {
                                List<String> bindingFiles) {
         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,
@@ -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!


Mime
View raw message