You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/10/22 22:20:58 UTC

svn commit: r1534771 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/

Author: sergeyb
Date: Tue Oct 22 20:20:58 2013
New Revision: 1534771

URL: http://svn.apache.org/r1534771
Log:
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.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.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:r1534768

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/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1534771&r1=1534770&r2=1534771&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Tue Oct 22 20:20:58 2013
@@ -414,7 +414,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};
@@ -454,7 +454,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.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1534771&r1=1534770&r2=1534771&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Tue Oct 22 20:20:58 2013
@@ -65,6 +65,8 @@ public class BookServer extends Abstract
         p.setEnableBuffering(true);
         p.setReportByteArraySize(true);
         providers.add(p);
+        providers.add(new BookStore.PrimitiveIntArrayReaderWriter());
+        providers.add(new BookStore.PrimitiveDoubleArrayReaderWriter());
         providers.add(new BookStore.StringArrayBodyReaderWriter());
         providers.add(new BookStore.StringListBodyReaderWriter());
         providers.add(new ContentTypeModifyingMBW());

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1534771&r1=1534770&r2=1534771&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Oct 22 20:20:58 2013
@@ -147,6 +147,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("/redirect")
     public Response getBookRedirect(@QueryParam("redirect") Boolean done,
                                     @QueryParam("sameuri") Boolean sameuri) {
@@ -1636,6 +1650,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.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=1534771&r1=1534770&r2=1534771&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 Tue Oct 22 20:20:58 2013
@@ -1079,6 +1079,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();