cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1499985 - in /cxf/branches/2.5.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/
Date Fri, 05 Jul 2013 12:28:24 GMT
Author: sergeyb
Date: Fri Jul  5 12:28:24 2013
New Revision: 1499985

URL: http://svn.apache.org/r1499985
Log:
Merged revisions 1499979 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1499979 | sergeyb | 2013-07-05 14:02:06 +0200 (Fri, 05 Jul 2013) | 20 lines
  
  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.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1499969
  Merged /cxf/trunk:r1499962-1499964
  Merged /cxf/branches/2.6.x-fixes:r1499979

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-blocked' - no diff available.

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1499985&r1=1499984&r2=1499985&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Fri Jul  5 12:28:24 2013
@@ -325,6 +325,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.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1499985&r1=1499984&r2=1499985&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Jul  5 12:28:24 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.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1499985&r1=1499984&r2=1499985&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Fri Jul  5 12:28:24 2013
@@ -47,6 +47,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();
         Map<String, String> jaxbElementClassMap = new HashMap<String, String>();

         jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1499985&r1=1499984&r2=1499985&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Jul  5 12:28:24 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;
@@ -81,6 +87,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 {
     }
 
     @GET
+    @Path("/bookarray")
+    public String[] getBookStringArray() {
+        return new String[]{"Good book"};
+    }
+    
+    @GET
+    @Path("/booklist")
+    public List<String> getBookListArray() {
+        return Collections.singletonList("Good book");
+    }
+    
+    @GET
     @Path("emptybook")
     @Produces({"application/xml", "application/json" })
     public Book getEmptyBook() {
@@ -1236,6 +1255,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.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1499985&r1=1499984&r2=1499985&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Jul  5 12:28:24 2013
@@ -758,6 +758,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();



Mime
View raw message