cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1153199 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/
Date Tue, 02 Aug 2011 17:05:54 GMT
Author: dkulp
Date: Tue Aug  2 17:05:53 2011
New Revision: 1153199

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

........
  r1153195 | dkulp | 2011-08-02 13:00:48 -0400 (Tue, 02 Aug 2011) | 1 line
  
  [CXF-3702] Make proxies implement closeable
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java
    cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
    cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java
    cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java?rev=1153199&r1=1153198&r2=1153199&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
Tue Aug  2 17:05:53 2011
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxws;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
@@ -67,8 +68,8 @@ public class JaxWsClientProxy extends or
     
     private static final Logger LOG = LogUtils.getL7dLogger(JaxWsClientProxy.class);
 
-    private final Binding binding;
-    private final EndpointReferenceBuilder builder;
+    private Binding binding;
+    private EndpointReferenceBuilder builder;
 
     public JaxWsClientProxy(Client c, Binding b) {
         super(c);
@@ -76,6 +77,11 @@ public class JaxWsClientProxy extends or
         setupEndpointAddressContext(getClient().getEndpoint());
         this.builder = new EndpointReferenceBuilder((JaxWsEndpointImpl)getClient().getEndpoint());
     }
+    public void close() throws IOException {
+        super.close();
+        binding = null;
+        builder = null;
+    }
 
     private void setupEndpointAddressContext(Endpoint endpoint) {
         // NOTE for jms transport the address would be null
@@ -86,6 +92,9 @@ public class JaxWsClientProxy extends or
     }
 
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
 
         Endpoint endpoint = getClient().getEndpoint();
         String address = endpoint.getEndpointInfo().getAddress();
@@ -101,7 +110,8 @@ public class JaxWsClientProxy extends or
         if (oi == null) {
             // check for method on BindingProvider and Object
             if (method.getDeclaringClass().equals(BindingProvider.class)
-                || method.getDeclaringClass().equals(Object.class)) {
+                || method.getDeclaringClass().equals(Object.class)
+                || method.getDeclaringClass().equals(Closeable.class)) {
                 try {
                     return method.invoke(this, params);
                 } catch (InvocationTargetException e) {
@@ -256,25 +266,40 @@ public class JaxWsClientProxy extends or
     }
 
     public Map<String, Object> getRequestContext() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return new WrappedMessageContext(this.getClient().getRequestContext(),
                                          null,
                                          Scope.APPLICATION);
     }
     public Map<String, Object> getResponseContext() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return new WrappedMessageContext(this.getClient().getResponseContext(),
                                                           null,
                                                           Scope.APPLICATION);
     }
 
     public Binding getBinding() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return binding;
     }
 
     public EndpointReference getEndpointReference() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return builder.getEndpointReference();
     }
 
     public <T extends EndpointReference> T getEndpointReference(Class<T> clazz)
{
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return builder.getEndpointReference(clazz);
     }    
 }

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java?rev=1153199&r1=1153198&r2=1153199&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.java
Tue Aug  2 17:05:53 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxws;
 
+import java.io.Closeable;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.List;
@@ -112,9 +113,17 @@ public class JaxWsProxyFactoryBean exten
     }
 
     protected Class[] getImplementingClasses() {
-        Class cls = getClientFactoryBean().getServiceClass();
+        Class<?> cls = getClientFactoryBean().getServiceClass();
         Class ret[] = new Class[] {cls, BindingProvider.class};
         try {
+            cls.getMethod("close");
+        } catch (Exception e) {
+            //ignore - doesn't have a close method so we
+            //can implement Closeable
+            ret = new Class[] {cls, BindingProvider.class, Closeable.class};
+        }
+
+        try {
             Proxy.getProxyClass(cls.getClassLoader(), ret);
         } catch (Throwable t) {
             ret = new Class[] {cls};

Modified: cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java?rev=1153199&r1=1153198&r2=1153199&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxy.java
Tue Aug  2 17:05:53 2011
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.frontend;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -32,7 +34,7 @@ import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.service.model.BindingOperationInfo;
 
-public class ClientProxy implements InvocationHandler {
+public class ClientProxy implements InvocationHandler, Closeable {
 
     private static final Logger LOG = LogUtils.getL7dLogger(ClientProxy.class);
 
@@ -44,16 +46,26 @@ public class ClientProxy implements Invo
         endpoint = c.getEndpoint();
         client = c;
     }
+    public void close() throws IOException {
+        if (client != null) {
+            client.destroy();
+            client = null;
+            endpoint = null;
+        }
+    }
 
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-
-        MethodDispatcher dispatcher = (MethodDispatcher)endpoint.getService().get(
-                                                                                  MethodDispatcher.class
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
+        
+        MethodDispatcher dispatcher = (MethodDispatcher)endpoint.getService().get(MethodDispatcher.class
                                                                                       .getName());
         BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
         if (oi == null) {
             // check for method on BindingProvider and Object
-            if (method.getDeclaringClass().equals(Object.class)) {
+            if (method.getDeclaringClass().equals(Object.class)
+                || method.getDeclaringClass().equals(Closeable.class)) {
                 return method.invoke(this);
             }
 
@@ -70,6 +82,9 @@ public class ClientProxy implements Invo
 
     public Object invokeSync(Method method, BindingOperationInfo oi, Object[] params)
         throws Exception {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         Object rawRet[] = client.invoke(oi, params);
 
         if (rawRet != null && rawRet.length > 0) {
@@ -79,9 +94,15 @@ public class ClientProxy implements Invo
         }
     }
     public Map<String, Object> getRequestContext() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return client.getRequestContext();
     }
     public Map<String, Object> getResponseContext() {
+        if (client == null) {
+            throw new IllegalStateException("The client has been closed.");
+        }
         return client.getResponseContext();
     }
 
@@ -91,7 +112,7 @@ public class ClientProxy implements Invo
 
     @Override
     protected void finalize() throws Throwable {
-        client.destroy();
+        close();
         super.finalize();
     }
 

Modified: cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java?rev=1153199&r1=1153198&r2=1153199&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ClientProxyFactoryBean.java
Tue Aug  2 17:05:53 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.frontend;
 
+import java.io.Closeable;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -166,6 +167,7 @@ public class ClientProxyFactoryBean exte
             ClientProxy handler = clientClientProxy(c);
     
             Class classes[] = getImplementingClasses();
+            
             Object obj = Proxy.newProxyInstance(clientFactoryBean.getServiceClass().getClassLoader(),
                                                 classes,
                                                 handler);
@@ -179,8 +181,16 @@ public class ClientProxyFactoryBean exte
     }
 
     protected Class[] getImplementingClasses() {
-        Class cls = clientFactoryBean.getServiceClass();
-        return new Class[] {cls};
+        Class<?> cls = clientFactoryBean.getServiceClass();
+        try {
+            if (cls.getMethod("close") != null) {
+                return new Class[] {cls};
+            }
+        } catch (Exception e) {
+            //ignore - doesn't have a close method so we
+            //can implement Closeable
+        }
+        return new Class[] {cls, Closeable.class};
     }
 
     protected ClientProxy clientClientProxy(Client c) {

Modified: cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java?rev=1153199&r1=1153198&r2=1153199&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/lifecycle/LifeCycleTest.java
Tue Aug  2 17:05:53 2011
@@ -122,6 +122,17 @@ public class LifeCycleTest extends Asser
             }
         }
         assertTrue("clientDestroyed not called", destroyed.get());
+        
+        created.set(false);
+        destroyed.set(false);
+        
+        client = service.getSoapPort();
+        ((BindingProvider)client).getRequestContext()
+            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                 ADDRESSES[0]);
+        assertTrue("clientCreated not called", created.get());
+        ((java.io.Closeable)client).close();
+        assertTrue("clientDestroyed not called", destroyed.get());
     }
     
     @Test



Mime
View raw message