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 5A8C918AAB for ; Fri, 6 Nov 2015 16:55:06 +0000 (UTC) Received: (qmail 25571 invoked by uid 500); 6 Nov 2015 16:55:06 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 25430 invoked by uid 500); 6 Nov 2015 16:55:06 -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 25419 invoked by uid 99); 6 Nov 2015 16:55:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Nov 2015 16:55:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 10AD3DFDD0; Fri, 6 Nov 2015 16:55:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <0febc425014d4dee8208c0e83fe72e0f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6670] Fixing a class cast issue Date: Fri, 6 Nov 2015 16:55:06 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/master 0d4cd0bbc -> bb4ddb5be [CXF-6670] Fixing a class cast issue Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/bb4ddb5b Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/bb4ddb5b Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/bb4ddb5b Branch: refs/heads/master Commit: bb4ddb5be95d3ce415bab2aec290ff09a3a572f6 Parents: 0d4cd0b Author: Sergey Beryozkin Authored: Fri Nov 6 16:54:49 2015 +0000 Committer: Sergey Beryozkin Committed: Fri Nov 6 16:54:49 2015 +0000 ---------------------------------------------------------------------- .../apache/cxf/jaxrs/utils/InjectionUtils.java | 10 ++++- .../apache/cxf/systest/jaxrs/BookServer.java | 39 ++++++++++++++------ .../org/apache/cxf/systest/jaxrs/BookStore.java | 5 ++- .../jaxrs/JAXRSClientServerBookTest.java | 5 ++- 4 files changed, 42 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/bb4ddb5b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java index 3850393..fa42c6f 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java @@ -357,6 +357,7 @@ public final class InjectionUtils { return null; } + @SuppressWarnings("unchecked") public static T handleParameter(String value, boolean decoded, Class pClass, @@ -385,11 +386,16 @@ public final class InjectionUtils { throw createParamConversionException(pType, nfe); } if (result != null) { - return pClass.cast(result); + T theResult = null; + if (pClass.isPrimitive()) { + theResult = (T)result; + } else { + theResult = pClass.cast(result); + } + return theResult; } if (pClass.isPrimitive()) { try { - @SuppressWarnings("unchecked") T ret = (T)PrimitiveUtils.read(value, pClass); // cannot us pClass.cast as the pClass is something like // Boolean.TYPE (representing the boolean primitive) and http://git-wip-us.apache.org/repos/asf/cxf/blob/bb4ddb5b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java index 8c7f992..9c1764d 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java @@ -124,7 +124,7 @@ public class BookServer extends AbstractBusTestServerBase { providers.add(new BlockingRequestFilter()); providers.add(new FaultyResponseFilter()); providers.add(new BlockedExceptionMapper()); - providers.add(new XmlBookParamConverter()); + providers.add(new ParamConverterImpl()); sf.setProviders(providers); List> inInts = new ArrayList>(); inInts.add(new CustomInFaultyInterceptor()); @@ -270,7 +270,7 @@ public class BookServer extends AbstractBusTestServerBase { } } - public static class XmlBookParamConverter implements ParamConverterProvider { + public static class ParamConverterImpl implements ParamConverterProvider { @Context private Providers providers; @@ -278,20 +278,35 @@ public class BookServer extends AbstractBusTestServerBase { @Override public ParamConverter getConverter(Class rawType, Type genericType, Annotation[] annotations) { - if (rawType != Book.class) { + if (rawType == Book.class) { + + MessageBodyReader mbr = providers.getMessageBodyReader(Book.class, + Book.class, + annotations, + MediaType.APPLICATION_XML_TYPE); + MessageBodyWriter mbw = providers.getMessageBodyWriter(Book.class, + Book.class, + annotations, + MediaType.APPLICATION_XML_TYPE); + return (ParamConverter)new XmlParamConverter(mbr, mbw); + } else if (rawType == byte.class) { + return (ParamConverter)new ByteConverter(); + } else { return null; } - MessageBodyReader mbr = providers.getMessageBodyReader(Book.class, - Book.class, - annotations, - MediaType.APPLICATION_XML_TYPE); - MessageBodyWriter mbw = providers.getMessageBodyWriter(Book.class, - Book.class, - annotations, - MediaType.APPLICATION_XML_TYPE); - return (ParamConverter)new XmlParamConverter(mbr, mbw); } + private static class ByteConverter implements ParamConverter { + @Override + public Byte fromString(String t) { + return new Byte(t); + } + + @Override + public String toString(Byte b) { + return b.toString(); + } + } private static class XmlParamConverter implements ParamConverter { private MessageBodyReader mbr; private MessageBodyWriter mbw; http://git-wip-us.apache.org/repos/asf/cxf/blob/bb4ddb5b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java index 4837784..cde5c7f 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java @@ -306,7 +306,10 @@ public class BookStore { @POST @Path("/echoxmlbookquery") @Produces("application/xml") - public Book echoXmlBookQuery(@QueryParam("book") Book book) { + public Book echoXmlBookQuery(@QueryParam("book") Book book, @QueryParam("id") byte id) { + if (book.getId() != (long)id) { + throw new RuntimeException(); + } return book; } http://git-wip-us.apache.org/repos/asf/cxf/blob/bb4ddb5b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java index 2bb461b..33ea415 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java @@ -135,11 +135,12 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testEchoXmlBookQuery() throws Exception { String address = "http://localhost:" + PORT; BookStore store = JAXRSClientFactory.create(address, BookStore.class, - Collections.singletonList(new BookServer.XmlBookParamConverter())); - Book b = store.echoXmlBookQuery(new Book("query", 125L)); + Collections.singletonList(new BookServer.ParamConverterImpl())); + Book b = store.echoXmlBookQuery(new Book("query", 125L), (byte)125); assertEquals(125L, b.getId()); assertEquals("query", b.getName()); } + @Test public void testGetBookRoot() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/;JSESSIONID=xxx";