cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [03/10] cxf git commit: [CXF-6812]:WebTargetImpl should always check if client is closed first
Date Wed, 16 Mar 2016 15:05:57 GMT
[CXF-6812]:WebTargetImpl should always check if client is closed first


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

Branch: refs/heads/3.0.x-fixes
Commit: 03fe259c39d635194a6d9628a83f6e5c7acd7877
Parents: 1a37737
Author: Jim Ma <ema@apache.org>
Authored: Wed Mar 2 13:56:14 2016 +0800
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Mar 16 10:59:51 2016 -0400

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/spec/ClientImpl.java    | 11 ++++++++---
 .../cxf/jaxrs/client/cache/ClientCacheTest.java     | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/03fe259c/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
index 316dd69..4f089d6 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
@@ -153,7 +153,7 @@ public class ClientImpl implements Client {
     
     private void checkClosed() {
         if (closed) {
-            throw new IllegalStateException();
+            throw new IllegalStateException("client is closed");
         }
     }
 
@@ -359,12 +359,14 @@ public class ClientImpl implements Client {
 
         @Override
         public WebTarget path(String path) {
+            checkClosed();
             checkNull(path);
             return newWebTarget(getUriBuilder().path(path));
         }
 
         @Override
         public WebTarget queryParam(String name, Object... values) {
+            checkClosed();
             checkNullValues(name, values);
             UriBuilder thebuilder = getUriBuilder();
             if (values == null || values.length == 1 && values[0] == null) {
@@ -377,6 +379,7 @@ public class ClientImpl implements Client {
         
         @Override
         public WebTarget matrixParam(String name, Object... values) {
+            checkClosed();
             checkNullValues(name, values);
             
             UriBuilder thebuilder = getUriBuilder();
@@ -395,6 +398,7 @@ public class ClientImpl implements Client {
 
         @Override
         public WebTarget resolveTemplate(String name, Object value, boolean encodeSlash)
{
+            checkClosed();
             checkNull(name, value);
             return newWebTarget(getUriBuilder().resolveTemplate(name, value, encodeSlash));
         }
@@ -412,6 +416,7 @@ public class ClientImpl implements Client {
 
         @Override
         public WebTarget resolveTemplates(Map<String, Object> templatesMap, boolean
encodeSlash) {
+            checkClosed();
             checkNullMap(templatesMap);
             
             if (templatesMap.isEmpty()) {
@@ -422,6 +427,7 @@ public class ClientImpl implements Client {
 
         @Override
         public WebTarget resolveTemplatesFromEncoded(Map<String, Object> templatesMap)
{
+            checkClosed();
             checkNullMap(templatesMap);
             if (templatesMap.isEmpty()) {
                 return this;
@@ -429,8 +435,7 @@ public class ClientImpl implements Client {
             return newWebTarget(getUriBuilder().resolveTemplatesFromEncoded(templatesMap));
         }
         
-        private WebTarget newWebTarget(UriBuilder newBuilder) {
-            checkClosed();
+        private WebTarget newWebTarget(UriBuilder newBuilder) {            
             boolean complete = false;
             if (targetClient != null) {
                 try {

http://git-wip-us.apache.org/repos/asf/cxf/blob/03fe259c/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/cache/ClientCacheTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/cache/ClientCacheTest.java
b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/cache/ClientCacheTest.java
index e3ef126..bbe6f7c 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/cache/ClientCacheTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/cache/ClientCacheTest.java
@@ -21,10 +21,12 @@ package org.apache.cxf.jaxrs.client.cache;
 
 import java.io.InputStream;
 import java.io.Serializable;
+import java.util.HashMap;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.WebTarget;
@@ -158,6 +160,20 @@ public class ClientCacheTest extends Assert {
             feature.close();
         }    
     }
+
+    @Test
+    public void testClientClosed() {
+        Client client = ClientBuilder.newClient();        
+        try {
+            WebTarget target = client.target(ADDRESS);
+            client.close();
+            target.resolveTemplatesFromEncoded(new HashMap<String, Object>());
+            fail("IllegalStateException is expected");
+        } catch (java.lang.IllegalStateException e) {
+            assertTrue(e.getMessage().contains("client is closed"));
+        }
+    } 
+    
     
     private static Invocation.Builder setAsLocal(final Invocation.Builder client) {
         WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);


Mime
View raw message