Author: sergeyb Date: Tue Oct 22 20:38:03 2013 New Revision: 1534776 URL: http://svn.apache.org/r1534776 Log: Merged revisions 1534771 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
................ r1534771 | sergeyb | 2013-10-22 21:20:58 +0100 (Tue, 22 Oct 2013) | 9 lines Merged revisions 1534768 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1534768 | sergeyb | 2013-10-22 21:15:52 +0100 (Tue, 22 Oct 2013) | 1 line [CXF-5328] Minor update to support the providers accepting primitive arrays ........ ................ Modified: cxf/branches/2.6.x-fixes/ (props changed) cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/branches/2.7.x-fixes:r1534771 Merged /cxf/trunk:r1534768 Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1534776&r1=1534775&r2=1534776&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Tue Oct 22 20:38:03 2013 @@ -335,7 +335,7 @@ public final class ProviderFactory { Class<?> providerClass, boolean injectContext) { - Class<?> mapperClass = ClassHelper.getRealClass(em.getProvider()); + Class<?> mapperClass = ClassHelper.getRealClass(em.getProvider()); Type[] types = null; if (m != null && MessageUtils.isTrue(m.getContextualProperty(IGNORE_TYPE_VARIABLES))) { types = new Type[]{mapperClass}; @@ -375,7 +375,7 @@ public final class ProviderFactory { if (expectedType.isArray() && !actualClass.isArray()) { expectedType = expectedType.getComponentType(); } - if (actualClass.isAssignableFrom(expectedType)) { + if (actualClass.isAssignableFrom(expectedType) || actualClass == Object.class) { if (injectContext) { injectContextValues(em, m); } Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1534776&r1=1534775&r2=1534776&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original) +++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Tue Oct 22 20:38:03 2013 @@ -62,6 +62,8 @@ public class BookServer extends Abstract p.setProduceMediaTypes(Collections.singletonList("application/bar")); p.setEnableBuffering(true); providers.add(p); + providers.add(new BookStore.PrimitiveIntArrayReaderWriter()); + providers.add(new BookStore.PrimitiveDoubleArrayReaderWriter()); providers.add(new BookStore.StringArrayBodyReaderWriter()); providers.add(new BookStore.StringListBodyReaderWriter()); JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<Object>(); Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1534776&r1=1534775&r2=1534776&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original) +++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Oct 22 20:38:03 2013 @@ -134,6 +134,20 @@ public class BookStore { } @GET + @Path("/bookindexintarray") + @Produces("text/plain") + public int[] getBookIndexAsIntArray() { + return new int[]{1, 2, 3}; + } + + @GET + @Path("/bookindexdoublearray") + @Produces("text/plain") + public double[] getBookIndexAsDoubleArray() { + return new double[]{1, 2, 3}; + } + + @GET @Path("/booklist") public List<String> getBookListArray() { return Collections.singletonList("Good book"); @@ -1346,6 +1360,90 @@ public class BookStore { arg6.write(arg0.get(0).getBytes()); } + } + + public static class PrimitiveIntArrayReaderWriter + implements MessageBodyReader<int[]>, MessageBodyWriter<int[]> { + public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return int[].class.isAssignableFrom(arg0); + } + + public int[] readFrom(Class<int[]> arg0, Type arg1, + Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) + throws IOException, WebApplicationException { + String[] stringArr = IOUtils.readStringFromStream(arg5).split(","); + int[] intArr = new int[stringArr.length]; + for (int i = 0; i < stringArr.length; i++) { + intArr[i] = Integer.valueOf(stringArr[i]); + } + return intArr; + + } + + public long getSize(int[] arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { + return -1; + } + + public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return int[].class.isAssignableFrom(arg0); + } + + public void writeTo(int[] arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, + MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException, + WebApplicationException { + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < arg0.length; i++) { + sb.append(Integer.toString(arg0[i])); + if (i + 1 < arg0.length) { + sb.append(","); + } + } + arg6.write(sb.toString().getBytes()); + } + + } + public static class PrimitiveDoubleArrayReaderWriter + implements MessageBodyReader<Object>, MessageBodyWriter<Object> { + public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return double[].class.isAssignableFrom(arg0); + } + + public Object readFrom(Class<Object> arg0, Type arg1, + Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) + throws IOException, WebApplicationException { + String[] stringArr = IOUtils.readStringFromStream(arg5).split(","); + double[] intArr = new double[stringArr.length]; + for (int i = 0; i < stringArr.length; i++) { + intArr[i] = Double.valueOf(stringArr[i]); + } + return intArr; + + } + + public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { + return -1; + } + + public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return double[].class.isAssignableFrom(arg0); + } + + public void writeTo(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, + MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException, + WebApplicationException { + + double[] arr = (double[])arg0; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < arr.length; i++) { + sb.append(Double.toString(arr[i])); + if (i + 1 < arr.length) { + sb.append(","); + } + } + arg6.write(sb.toString().getBytes()); + } + } } Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1534776&r1=1534775&r2=1534776&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original) +++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Tue Oct 22 20:38:03 2013 @@ -814,6 +814,38 @@ public class JAXRSClientServerBookTest e } @Test + public void testGetPrimitiveIntArray() throws Exception { + String address = "http://localhost:" + PORT; + JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); + bean.setProvider(new BookStore.PrimitiveIntArrayReaderWriter()); + bean.setAddress(address); + bean.setResourceClass(BookStore.class); + BookStore store = bean.create(BookStore.class); + int[] arr = store.getBookIndexAsIntArray(); + assertEquals(3, arr.length); + assertEquals(1, arr[0]); + assertEquals(2, arr[1]); + assertEquals(3, arr[2]); + } + + @Test + public void testGetPrimitiveDoubleArray() throws Exception { + String address = "http://localhost:" + PORT; + JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); + bean.setProvider(new BookStore.PrimitiveDoubleArrayReaderWriter()); + bean.setAddress(address); + bean.setResourceClass(BookStore.class); + BookStore store = bean.create(BookStore.class); + WebClient.getConfig(store).getHttpConduit().getClient().setReceiveTimeout(1000000L); + double[] arr = store.getBookIndexAsDoubleArray(); + assertEquals(3, arr.length); + assertEquals(1, arr[0], 0.0); + assertEquals(2, arr[1], 0.0); + assertEquals(3, arr[2], 0.0); + } + + + @Test public void testGetStringList() throws Exception { String address = "http://localhost:" + PORT; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
