cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1546039 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 27 Nov 2013 14:09:27 GMT
Author: sergeyb
Date: Wed Nov 27 14:09:27 2013
New Revision: 1546039

URL: http://svn.apache.org/r1546039
Log:
Merged revisions 1546034 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1546034 | sergeyb | 2013-11-27 13:49:54 +0000 (Wed, 27 Nov 2013) | 1 line
  
  [CXF-5426] Avoiding the explicit casts when reading data with Response and WebClient
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1546034

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1546039&r1=1546038&r2=1546039&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Wed Nov 27 14:09:27 2013
@@ -378,7 +378,7 @@ public class WebClient extends AbstractC
         @SuppressWarnings("unchecked")
         Class<T> responseClass = (Class<T>)responseType.getRawType();
         Response r = doInvoke(httpMethod, body, null, responseClass, responseType.getType());
-        return responseClass.cast(responseClass == Response.class ? r : r.getEntity());
+        return castResponse(r, responseClass);
     }
     
 
@@ -392,7 +392,7 @@ public class WebClient extends AbstractC
      */
     public <T> T invoke(String httpMethod, Object body, Class<T> responseClass)
{
         Response r = doInvoke(httpMethod, body, null, responseClass, responseClass);
-        return responseClass.cast(responseClass == Response.class ? r : r.getEntity());
+        return castResponse(r, responseClass);
     }
     
     /**
@@ -406,9 +406,14 @@ public class WebClient extends AbstractC
      */
     public <T> T invoke(String httpMethod, Object body, Class<?> requestClass,
Class<T> responseClass) {
         Response r = doInvoke(httpMethod, body, requestClass, null, responseClass, responseClass);
-        return responseClass.cast(responseClass == Response.class ? r : r.getEntity());
+        return castResponse(r, responseClass);
     }
     
+    @SuppressWarnings("unchecked")
+    private <T> T castResponse(Response r, Class<T> responseClass) {
+        return (T)(responseClass == Response.class ? r : r.getEntity());
+    }
+
     /**
      * Does HTTP POST invocation and returns typed response object
      * @param body request body, can be null

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1546039&r1=1546038&r2=1546039&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed Nov 27 14:09:27 2013
@@ -330,7 +330,7 @@ public final class ResponseImpl extends 
                         entity = null;
                     } 
                     
-                    return cls.cast(lastEntity);
+                    return castLastEntity();
                 } catch (Exception ex) {
                     throw new MessageProcessingException(ex);
                 }
@@ -339,7 +339,7 @@ public final class ResponseImpl extends 
             }
         } else if (entity != null && cls.isAssignableFrom(entity.getClass())) {
             lastEntity = entity;
-            return cls.cast(lastEntity);
+            return castLastEntity();
         }
         
         throw new IllegalStateException("The entity is not backed by an input stream, entity
class is : "
@@ -347,6 +347,11 @@ public final class ResponseImpl extends 
         
     }
     
+    @SuppressWarnings("unchecked")
+    private <T> T castLastEntity() {
+        return (T)lastEntity;
+    }
+    
     protected boolean responseStreamCanBeClosed(Class<?> cls) {
         return cls != InputStream.class
             && MessageUtils.isTrue(responseMessage.getContextualProperty("response.stream.auto.close"));

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1546039&r1=1546038&r2=1546039&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Nov 27 14:09:27 2013
@@ -1298,6 +1298,26 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testBookExistsWebClientPrimitiveBoolean() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/check/123");
+        wc.accept("text/plain");
+        assertTrue(wc.get(boolean.class));
+    }
+    
+    @Test
+    public void testBookExistsProxyPrimitiveBoolean() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        assertTrue(store.checkBook(123L));
+    }
+    
+    @Test
+    public void testBookExistsWebClientBooleanObject() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/check/123");
+        wc.accept("text/plain");
+        assertTrue(wc.get(Boolean.class));
+    }
+    
+    @Test
     public void testBookExistsMalformedMt() throws Exception {
         WebClient wc = 
             WebClient.create("http://localhost:" + PORT + "/bookstore/books/check/malformedmt/123");



Mime
View raw message