Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ECB5B10769 for ; Wed, 27 Nov 2013 13:50:27 +0000 (UTC) Received: (qmail 54663 invoked by uid 500); 27 Nov 2013 13:50:25 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 54524 invoked by uid 500); 27 Nov 2013 13:50:21 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 54497 invoked by uid 99); 27 Nov 2013 13:50:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Nov 2013 13:50:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Nov 2013 13:50:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2C576238889B; Wed, 27 Nov 2013 13:49:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131127134955.2C576238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 responseClass = (Class)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 invoke(String httpMethod, Object body, Class 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 invoke(String httpMethod, Object body, Class requestClass, Class 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 castResponse(Response r, Class 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");