cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1133405 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 08 Jun 2011 14:03:58 GMT
Author: sergeyb
Date: Wed Jun  8 14:03:57 2011
New Revision: 1133405

URL: http://svn.apache.org/viewvc?rev=1133405&view=rev
Log:
[CXF-3578] Better checks for XmlJavaTypeAdapter annotation on input

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.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/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1133405&r1=1133404&r2=1133405&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Wed Jun  8 14:03:57 2011
@@ -509,8 +509,8 @@ public abstract class AbstractJAXBProvid
     }
     
     protected static Object checkAdapter(Object obj, Class<?> cls, Annotation[] anns,
boolean marshal) {
-        return org.apache.cxf.jaxrs.utils.JAXBUtils.useAdapter(obj, getAdapter(obj.getClass(),
anns), 
-                                                               marshal); 
+        XmlJavaTypeAdapter adapter = getAdapter(cls, anns);
+        return org.apache.cxf.jaxrs.utils.JAXBUtils.useAdapter(obj, adapter, marshal); 
     }
     
     protected static XmlJavaTypeAdapter getAdapter(Class<?> objectClass, Annotation[]
anns) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1133405&r1=1133404&r2=1133405&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Wed Jun  8 14:03:57 2011
@@ -132,8 +132,8 @@ public class JAXBElementProvider extends
             checkContentLength();
             
             boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type);
-            Class<?> theType = isCollection ? InjectionUtils.getActualType(genericType)
: type;
-            theType = getActualType(theType, genericType, anns);
+            Class<?> theGenericType = isCollection ? InjectionUtils.getActualType(genericType)
: type;
+            Class<?> theType = getActualType(theGenericType, genericType, anns);
 
             Unmarshaller unmarshaller = createUnmarshaller(theType, genericType, isCollection);
             addAttachmentUnmarshaller(unmarshaller);
@@ -153,7 +153,7 @@ public class JAXBElementProvider extends
             }
             if (isCollection) {
                 response = ((CollectionWrapper)response).getCollectionOrArray(theType, type,

-                                                         getAdapter(theType, anns)); 
+                                                         getAdapter(theGenericType, anns));

             } else {
                 response = checkAdapter(response, type, anns, false);
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1133405&r1=1133404&r2=1133405&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Wed Jun  8 14:03:57 2011
@@ -180,8 +180,8 @@ public class JSONProvider extends Abstra
         
         try {
             boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type);
-            Class<?> theType = isCollection ? InjectionUtils.getActualType(genericType)
: type;
-            theType = getActualType(theType, genericType, anns);
+            Class<?> theGenericType = isCollection ? InjectionUtils.getActualType(genericType)
: type;
+            Class<?> theType = getActualType(theGenericType, genericType, anns);
             
             Unmarshaller unmarshaller = createUnmarshaller(theType, genericType, isCollection);
             
@@ -201,7 +201,7 @@ public class JSONProvider extends Abstra
             }
             if (isCollection) {
                 response = ((CollectionWrapper)response).getCollectionOrArray(theType, type,

-                                                         getAdapter(theType, anns)); 
+                                                         getAdapter(theGenericType, anns));

             } else {
                 response = checkAdapter(response, type, anns, false);
             }

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=1133405&r1=1133404&r2=1133405&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 Wed
Jun  8 14:03:57 2011
@@ -588,6 +588,23 @@ public class BookStore {
         return new BookInfo2(doGetBook("123"));
     }
     
+    @GET
+    @Path("/books/interface/adapter-list")
+    public List<? extends BookInfoInterface> getBookAdapterInterfaceList() throws Exception
{
+        List<BookInfoInterface> list = new ArrayList<BookInfoInterface>();
+        list.add(new BookInfo2(doGetBook("123")));
+        return list;
+    }
+    
+    @GET
+    @Path("/books/adapter-list")
+    @XmlJavaTypeAdapter(BookInfoAdapter.class)
+    public List<? extends BookInfo> getBookAdapterList() throws Exception {
+        List<BookInfo> list = new ArrayList<BookInfo>();
+        list.add(new BookInfo(doGetBook("123")));
+        return list;
+    }
+    
     @PathParam("bookId")
     public void setBookId(String id) {
         currentBookId = id;
@@ -928,8 +945,8 @@ public class BookStore {
         cds.put(cd1.getId(), cd1);
     }
     
-    @XmlJavaTypeAdapter(BookInfoAdapter.class)
-    private static interface BookInfoInterface {
+    @XmlJavaTypeAdapter(BookInfoAdapter2.class)
+    static interface BookInfoInterface {
         String getName();
         
         long getId();
@@ -977,6 +994,18 @@ public class BookStore {
         }
     }
         
+    public static class BookInfoAdapter2 extends XmlAdapter<Book, BookInfo2> {
+        @Override
+        public Book marshal(BookInfo2 v) throws Exception {
+            return new Book(v.getName(), v.getId());
+        }
+
+        @Override
+        public BookInfo2 unmarshal(Book b) throws Exception {
+            return new BookInfo2(b);
+        }
+    }
+    
     public static class BookInfoAdapter extends XmlAdapter<Book, BookInfo> {
 
         @Override

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=1133405&r1=1133404&r2=1133405&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
Wed Jun  8 14:03:57 2011
@@ -56,6 +56,8 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.provider.XSLTJaxbProvider;
+import org.apache.cxf.systest.jaxrs.BookStore.BookInfo;
+import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -1027,6 +1029,39 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookAdapterInterfaceList() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        List<? extends BookInfoInterface> list =  store.getBookAdapterInterfaceList();
+        assertEquals(1, list.size());
+        BookInfoInterface info = list.get(0);
+        assertEquals(123L, info.getId());
+    }
+    
+    @Test
+    public void testGetBookAdapterInterfaceProxy() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        WebClient.getConfig(store).getHttpConduit().getClient().setReceiveTimeout(10000000L);
+        BookInfoInterface info = store.getBookAdapterInterface();
+        assertEquals(123L, info.getId());
+    }
+    
+    @Test
+    public void testGetBookAdapterInfoList() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        List<? extends BookInfo> list =  store.getBookAdapterList();
+        assertEquals(1, list.size());
+        BookInfo info = list.get(0);
+        assertEquals(123L, info.getId());
+    }
+    
+    @Test
+    public void testGetBookAdapterInfoProxy() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        BookInfo info = store.getBookAdapter();
+        assertEquals(123L, info.getId());
+    }
+    
+    @Test
     public void testGetBook123FromSub() throws Exception {
         getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/interface/subresource",
                                "resources/expected_get_book123.txt",



Mime
View raw message