cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r795915 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt/frontend...
Date Mon, 20 Jul 2009 16:53:51 GMT
Author: sergeyb
Date: Mon Jul 20 16:53:51 2009
New Revision: 795915

URL: http://svn.apache.org/viewvc?rev=795915&view=rev
Log:
Merged revisions 795907 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r795907 | sergeyb | 2009-07-20 17:41:42 +0100 (Mon, 20 Jul 2009) | 1 line
  
  JAX-RS : minor modifications to support Sets and base Collections
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul 20 16:53:51 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907

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

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Mon Jul 20 16:53:51 2009
@@ -469,14 +469,16 @@
         }
         
         @SuppressWarnings("unchecked")
-        public <T> Object getCollectionOrArray(Class<T> type, boolean isArray)
{
+        public <T> Object getCollectionOrArray(Class<T> type, Class<?>
origType) {
             List<?> theList = getList();
-            if (isArray) {
+            if (origType.isArray()) {
                 T[] values = (T[])Array.newInstance(type, theList.size());
                 for (int i = 0; i < theList.size(); i++) {
                     values[i] = (T)theList.get(i);
                 }
                 return values;
+            } else if (origType == Set.class) {
+                return new HashSet(theList);
             } else {
                 return theList;
             }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Mon Jul 20 16:53:51 2009
@@ -150,7 +150,7 @@
                 response = doUnmarshal(unmarshaller, type, is, mt);
             }
             if (isCollection) {
-                response = ((CollectionWrapper)response).getCollectionOrArray(theType, type.isArray());

+                response = ((CollectionWrapper)response).getCollectionOrArray(theType, type);

             }
             
             response = checkAdapter(response, anns, false);
@@ -203,7 +203,7 @@
         throws IOException {
         try {
             Object actualObject = checkAdapter(obj, anns, true);
-            Class<?> actualClass = actualObject.getClass();
+            Class<?> actualClass = obj != actualObject ? actualObject.getClass() :
cls;
             String encoding = getEncoding(m, headers);
             if (InjectionUtils.isSupportedCollectionOrArray(actualClass)) {
                 actualClass = InjectionUtils.getActualType(genericType);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Mon Jul 20 16:53:51 2009
@@ -218,7 +218,7 @@
         try {
             
             Object actualObject = checkAdapter(obj, anns, true);
-            Class<?> actualClass = actualObject.getClass();
+            Class<?> actualClass = obj != actualObject ? actualObject.getClass() :
cls;
             if (cls == genericType) {
                 genericType = actualClass;
             }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Mon Jul 20 16:53:51 2009
@@ -519,9 +519,7 @@
     }
 
     public static boolean isSupportedCollectionOrArray(Class<?> type) {
-        return List.class.isAssignableFrom(type)
-            || Set.class.isAssignableFrom(type)
-            || type.isArray();
+        return Collection.class.isAssignableFrom(type) || type.isArray();
     }
 
     @SuppressWarnings("unchecked")
@@ -545,12 +543,12 @@
     
     static Class<?> getCollectionType(Class<?> rawType) {
         Class<?> type = null;
-        if (List.class.isAssignableFrom(rawType)) {
-            type = ArrayList.class;
-        } else if (SortedSet.class.isAssignableFrom(rawType)) {
+        if (SortedSet.class.isAssignableFrom(rawType)) {
             type = TreeSet.class;
         } else if (Set.class.isAssignableFrom(rawType)) {
             type = HashSet.class;
+        } else if (Collection.class.isAssignableFrom(rawType)) {
+            type = ArrayList.class;
         }
         return type;
         

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Mon Jul 20 16:53:51 2009
@@ -28,9 +28,13 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBContext;
@@ -60,7 +64,21 @@
 public class JAXBElementProviderTest extends Assert {
 
     @Test
+    public void testIsWriteableList() throws Exception {
+        testIsWriteableCollection("getBooks");
+    }
+    
+    @Test
     public void testIsWriteableCollection() throws Exception {
+        testIsWriteableCollection("getBookCollection");
+    }
+    
+    @Test
+    public void testIsWriteableSet() throws Exception {
+        testIsWriteableCollection("getBookSet");
+    }
+    
+    private void testIsWriteableCollection(String mName) throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
         provider.setCollectionWrapperName("foo");
         Method m = CollectionsResource.class.getMethod("getBooks", new Class[0]);
@@ -70,20 +88,32 @@
     
     @Test
     public void testWriteCollection() throws Exception {
-        doWriteUnqualifiedCollection(true, false);
+        doWriteUnqualifiedCollection(true, "getBookCollection", "setBookCollection", 
+                                     Collection.class);
+    }
+    
+    @Test
+    public void testWriteList() throws Exception {
+        doWriteUnqualifiedCollection(true, "getBooks", "setBooks", List.class);
+    }
+    
+    @Test
+    public void testWriteSet() throws Exception {
+        doWriteUnqualifiedCollection(true, "getBookSet", "setBookSet", Set.class);
     }
     
     @Test
     public void testWriteCollectionJaxbName() throws Exception {
-        doWriteUnqualifiedCollection(false, false);
+        doWriteUnqualifiedCollection(false, "getBooks", "setBooks", List.class);
     }
     
     @Test
     public void testWriteArray() throws Exception {
-        doWriteUnqualifiedCollection(true, true);
+        doWriteUnqualifiedCollection(true, "getBooksArray", "setBooksArray", Book[].class);
     }
     
-    public void doWriteUnqualifiedCollection(boolean setName, boolean isArray) throws Exception
{
+    public void doWriteUnqualifiedCollection(boolean setName, String mName, String setterName,

+                                             Class<?> type) throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
         if (setName) {
             provider.setCollectionWrapperName("Books");
@@ -91,12 +121,14 @@
         List<Book> books = new ArrayList<Book>();
         books.add(new Book("CXF in Action", 123L));
         books.add(new Book("CXF Rocks", 124L));
-        String mName = isArray ? "getBooksArray" : "getBooks";
+        Object o = type.isArray() ? books.toArray() : type == Set.class 
+            ? new HashSet<Book>(books) : books;
+        
         Method m = CollectionsResource.class.getMethod(mName, new Class[0]);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        provider.writeTo(isArray ? books.toArray() : books, m.getReturnType(), m.getGenericReturnType(),
+        provider.writeTo(o, m.getReturnType(), m.getGenericReturnType(),
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
Object>(), bos);
-        doReadUnqualifiedCollection(bos.toString());
+        doReadUnqualifiedCollection(bos.toString(), setterName, type);
     }
     
     @Test
@@ -117,25 +149,34 @@
     public void testReadUnqualifiedCollection() throws Exception {
         String data = "<Books><Book><id>123</id><name>CXF in
Action</name>"
             + "</Book><Book><id>124</id><name>CXF Rocks</name></Book></Books>";
-        doReadUnqualifiedCollection(data);
+        doReadUnqualifiedCollection(data, "setBooks", List.class);
     }
     
     @SuppressWarnings("unchecked")
-    private void doReadUnqualifiedCollection(String data) throws Exception {
+    private void doReadUnqualifiedCollection(String data, String mName, Class<?> type)
throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
-        Method m = CollectionsResource.class.getMethod("setBooks", 
-                                                       new Class[]{List.class});
+        Method m = CollectionsResource.class.getMethod(mName, 
+                                                       new Class[]{type});
         ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
-        List<Book> books = (List<Book>)provider.readFrom(
+        Object o = provider.readFrom(
                       (Class)m.getParameterTypes()[0], m.getGenericParameterTypes()[0],
                        new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String,
String>(), is);
-        assertNotNull(books);
-        assertEquals(2, books.size());
-        Book b1 = books.get(0);
+        assertNotNull(o);
+        Book b1 = null;
+        Book b2 = null;
+        if (type.isArray()) {
+            assertEquals(2, ((Book[])o).length);
+            b1 = ((Book[])o)[0];
+            b2 = ((Book[])o)[1];
+        } else {
+            List<Book> books = type == Set.class ? new ArrayList<Book>(new TreeSet((Set)o))
: (List<Book>)o;
+            b1 = books.get(0);
+            b2 = books.get(1);
+        }
+        
         assertEquals(123, b1.getId());
         assertEquals("CXF in Action", b1.getName());
         
-        Book b2 = books.get(1);
         assertEquals(124, b2.getId());
         assertEquals("CXF Rocks", b2.getName());    
     }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
Mon Jul 20 16:53:51 2009
@@ -29,7 +29,7 @@
 
 
 @XmlRootElement(name = "Book")
-public class Book {
+public class Book implements Comparable<Book> {
     private String name;
     private long id;
     private Map<Long, Chapter> chapters = new HashMap<Long, Chapter>();
@@ -81,4 +81,10 @@
         return other.name.equals(name) && other.id == id;
         
     }
+
+    public int compareTo(Book b) {
+        Long i1 = new Long(getId());
+        Long i2 = new Long(b.getId());
+        return i1.compareTo(i2);
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
Mon Jul 20 16:53:51 2009
@@ -18,10 +18,11 @@
  */
 package org.apache.cxf.jaxrs.resources;
 
+import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 import javax.ws.rs.GET;
-
 import javax.ws.rs.POST;
 
 public class CollectionsResource {
@@ -31,6 +32,16 @@
     }
     
     @GET
+    public Collection<Book> getBookCollection() {
+        return null;
+    }
+    
+    @GET
+    public Set<Book> getBookSet() {
+        return null;
+    }
+    
+    @GET
     public List<TagVO2> getTags() {
         return null;
     }
@@ -45,10 +56,22 @@
     }
     
     @POST
+    public void setBooksArray(Book[] books) {
+    }
+    
+    @POST
     public void setTags(List<TagVO2> tags) {
     }
     
     @POST
     public void setTagsArray(TagVO2[] tags) {
     }
+    
+    @POST
+    public void setBookCollection(Collection<Book> books) {
+    }
+    
+    @POST
+    public void setBookSet(Set<Book> books) {
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
Mon Jul 20 16:53:51 2009
@@ -19,6 +19,7 @@
 package org.apache.cxf.jaxrs.utils;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +40,7 @@
     
     @Test
     public void testCollectionType() {
+        assertEquals(ArrayList.class, InjectionUtils.getCollectionType(Collection.class));
         assertEquals(ArrayList.class, InjectionUtils.getCollectionType(List.class));
         assertEquals(HashSet.class, InjectionUtils.getCollectionType(Set.class));
         assertEquals(TreeSet.class, InjectionUtils.getCollectionType(SortedSet.class));
@@ -49,6 +51,7 @@
         assertFalse(InjectionUtils.isSupportedCollectionOrArray(Map.class));
         assertTrue(InjectionUtils.isSupportedCollectionOrArray(String[].class));
         assertTrue(InjectionUtils.isSupportedCollectionOrArray(List.class));
+        assertTrue(InjectionUtils.isSupportedCollectionOrArray(Collection.class));
         assertTrue(InjectionUtils.isSupportedCollectionOrArray(Set.class));
         assertTrue(InjectionUtils.isSupportedCollectionOrArray(SortedSet.class));
     }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java?rev=795915&r1=795914&r2=795915&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java
Mon Jul 20 16:53:51 2009
@@ -47,7 +47,8 @@
                         MultivaluedMap<String, Object> headers, OutputStream os) 
         throws IOException, WebApplicationException {
         JAXBElementProvider jaxb = new JAXBElementProvider();
-        jaxb.writeTo(o.getEntity(), c, InjectionUtils.getActualType(t), anns, m, headers,
os);
+        jaxb.writeTo(o.getEntity(), o.getEntity().getClass(), InjectionUtils.getActualType(t),

+                     anns, m, headers, os);
     }
 
 



Mime
View raw message