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:15:53 UTC
svn commit: r1534768 - in /cxf/trunk:
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:15:52 2013
New Revision: 1534768
URL: http://svn.apache.org/r1534768
Log:
[CXF-5328] Minor update to support the providers accepting primitive arrays
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.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/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1534768&r1=1534767&r2=1534768&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Tue Oct 22 20:15:52 2013
@@ -287,7 +287,7 @@ public abstract 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};
@@ -327,7 +327,7 @@ public abstract 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1534768&r1=1534767&r2=1534768&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Tue Oct 22 20:15:52 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1534768&r1=1534767&r2=1534768&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Oct 22 20:15:52 2013
@@ -148,6 +148,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) {
@@ -1653,6 +1667,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/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=1534768&r1=1534767&r2=1534768&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 Tue Oct 22 20:15:52 2013
@@ -1086,6 +1086,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();