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/07/05 14:02:06 UTC
svn commit: r1499979 - in /cxf/branches/2.6.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Author: sergeyb
Date: Fri Jul 5 12:02:06 2013
New Revision: 1499979
URL: http://svn.apache.org/r1499979
Log:
Merged revisions 1499969 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
................
r1499969 | sergeyb | 2013-07-05 13:22:54 +0200 (Fri, 05 Jul 2013) | 13 lines
Merged revisions 1499962,1499964 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1499962 | sergeyb | 2013-07-05 13:06:46 +0200 (Fri, 05 Jul 2013) | 1 line
[CXF-5111] Support for GenericTypeArray
........
r1499964 | sergeyb | 2013-07-05 13:12:27 +0200 (Fri, 05 Jul 2013) | 1 line
[CXF-5111] Removing few annotations
........
................
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/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.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/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Jul 5 12:02:06 2013
@@ -0,0 +1,2 @@
+/cxf/branches/2.7.x-fixes:1499969
+/cxf/trunk:1499962-1499964
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=1499979&r1=1499978&r2=1499979&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 Fri Jul 5 12:02:06 2013
@@ -372,6 +372,9 @@ public final class ProviderFactory {
if (actualClass == null) {
continue;
}
+ if (expectedType.isArray()) {
+ expectedType = expectedType.getComponentType();
+ }
if (actualClass.isAssignableFrom(expectedType)) {
if (injectContext) {
injectContextValues(em, m);
Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1499979&r1=1499978&r2=1499979&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Fri Jul 5 12:02:06 2013
@@ -23,6 +23,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -211,6 +212,8 @@ public final class InjectionUtils {
bounds = wildcardType.getUpperBounds();
}
genericType = getType(bounds, pos);
+ } else if (genericType instanceof GenericArrayType) {
+ genericType = ((GenericArrayType)genericType).getGenericComponentType();
}
Class<?> cls = (Class<?>)genericType;
@@ -230,9 +233,7 @@ public final class InjectionUtils {
public static Class<?> getRawType(Type genericType) {
- if (genericType == null) {
- return null;
- } else if (genericType instanceof Class) {
+ if (genericType instanceof Class) {
return (Class<?>) genericType;
} else if (genericType instanceof ParameterizedType) {
ParameterizedType paramType = (ParameterizedType)genericType;
@@ -240,8 +241,9 @@ public final class InjectionUtils {
if (t instanceof Class) {
return (Class<?>)t;
}
+ } else if (genericType instanceof GenericArrayType) {
+ return getRawType(((GenericArrayType)genericType).getGenericComponentType());
}
- // it might be a TypeVariable, or a GenericArray.
return null;
}
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=1499979&r1=1499978&r2=1499979&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 Fri Jul 5 12:02:06 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.StringArrayBodyReaderWriter());
+ providers.add(new BookStore.StringListBodyReaderWriter());
JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<Object>();
Map<String, String> jaxbElementClassMap = new HashMap<String, String>();
jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");
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=1499979&r1=1499978&r2=1499979&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 Fri Jul 5 12:02:06 2013
@@ -23,12 +23,15 @@ package org.apache.cxf.systest.jaxrs;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
@@ -66,6 +69,8 @@ import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -74,6 +79,7 @@ import javax.xml.transform.dom.DOMSource
import org.apache.cxf.annotations.GZIP;
import org.apache.cxf.common.util.ProxyHelper;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.apache.cxf.jaxrs.ext.Nullable;
import org.apache.cxf.jaxrs.ext.Oneway;
@@ -82,6 +88,7 @@ import org.apache.cxf.jaxrs.ext.search.S
import org.apache.cxf.jaxrs.ext.search.SearchContext;
import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.phase.PhaseInterceptorChain;
@Path("/bookstore")
@@ -120,6 +127,18 @@ public class BookStore {
//System.out.println("PreDestroy called");
}
+ @GET
+ @Path("/bookarray")
+ public String[] getBookStringArray() {
+ return new String[]{"Good book"};
+ }
+
+ @GET
+ @Path("/booklist")
+ public List<String> getBookListArray() {
+ return Collections.singletonList("Good book");
+ }
+
@POST
@Path("/mapperonbus")
public void mapperOnBus() {
@@ -1270,6 +1289,64 @@ public class BookStore {
}
}
+
+ public static class StringArrayBodyReaderWriter
+ implements MessageBodyReader<String[]>, MessageBodyWriter<String[]> {
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return String[].class.isAssignableFrom(arg0);
+ }
+
+ public String[] readFrom(Class<String[]> arg0, Type arg1,
+ Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5)
+ throws IOException, WebApplicationException {
+ return new String[] {IOUtils.readStringFromStream(arg5)};
+ }
+
+ public long getSize(String[] arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return String[].class.isAssignableFrom(arg0);
+ }
+
+ public void writeTo(String[] arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
+ MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException,
+ WebApplicationException {
+ arg6.write(arg0[0].getBytes());
+ }
+
+ }
+
+ public static class StringListBodyReaderWriter
+ implements MessageBodyReader<List<String>>, MessageBodyWriter<List<String>> {
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return List.class.isAssignableFrom(arg0)
+ && String.class == InjectionUtils.getActualType(arg1);
+ }
+
+ public List<String> readFrom(Class<List<String>> arg0, Type arg1,
+ Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5)
+ throws IOException, WebApplicationException {
+ return Collections.singletonList(IOUtils.readStringFromStream(arg5));
+ }
+
+ public long getSize(List<String> arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return List.class.isAssignableFrom(arg0)
+ && String.class == InjectionUtils.getActualType(arg1);
+ }
+
+ public void writeTo(List<String> arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
+ MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException,
+ WebApplicationException {
+ arg6.write(arg0.get(0).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=1499979&r1=1499978&r2=1499979&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 Fri Jul 5 12:02:06 2013
@@ -802,6 +802,30 @@ public class JAXRSClientServerBookTest e
}
@Test
+ public void testGetStringArray() throws Exception {
+ String address = "http://localhost:" + PORT;
+ JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setProvider(new BookStore.StringArrayBodyReaderWriter());
+ bean.setAddress(address);
+ bean.setResourceClass(BookStore.class);
+ BookStore store = bean.create(BookStore.class);
+ String[] str = store.getBookStringArray();
+ assertEquals("Good book", str[0]);
+ }
+
+ @Test
+ public void testGetStringList() throws Exception {
+ String address = "http://localhost:" + PORT;
+ JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setProvider(new BookStore.StringListBodyReaderWriter());
+ bean.setAddress(address);
+ bean.setResourceClass(BookStore.class);
+ BookStore store = bean.create(BookStore.class);
+ List<String> str = store.getBookListArray();
+ assertEquals("Good book", str.get(0));
+ }
+
+ @Test
public void testEmptyPostProxy2() throws Exception {
String address = "http://localhost:" + PORT;
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();