cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1546034 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 27 Nov 2013 13:49:55 GMT
Author: sergeyb
Date: Wed Nov 27 13:49:54 2013
New Revision: 1546034

URL: http://svn.apache.org/r1546034
Log:
[CXF-5426] Avoiding the explicit casts when reading data with Response and WebClient

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1546034&r1=1546033&r2=1546034&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed Nov 27 13:49:54 2013
@@ -376,13 +376,13 @@ public final class ResponseImpl extends 
                     entity = null;
                 } 
                 
-                return cls.cast(lastEntity);
+                return castLastEntity();
             } catch (Exception ex) {
                 reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
             }
         } else if (entity != null && cls.isAssignableFrom(entity.getClass())) {
             lastEntity = entity;
-            return cls.cast(lastEntity);
+            return castLastEntity();
         } else if (entityStreamAvailable) {
             reportMessageHandlerProblem("NO_MSG_READER", cls, mediaType, null);
         } 
@@ -392,6 +392,11 @@ public final class ResponseImpl extends 
         
     }
     
+    @SuppressWarnings("unchecked")
+    private <T> T castLastEntity() {
+        return (T)lastEntity;
+    }
+    
     public InputStream convertEntityToStreamIfPossible() {
         String stringEntity = null;
         if (entity instanceof String || entity instanceof Number) {

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1546034&r1=1546033&r2=1546034&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Wed Nov
27 13:49:54 2013
@@ -386,7 +386,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);
     }
     
     /**
@@ -399,7 +399,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);
     }
     
     /**
@@ -413,9 +413,13 @@ 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1546034&r1=1546033&r2=1546034&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Nov 27 13:49:54 2013
@@ -1310,6 +1310,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