cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1133420 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/ test/java/org/apache/cxf/jaxrs/utils/
Date Wed, 08 Jun 2011 15:17:40 GMT
Author: sergeyb
Date: Wed Jun  8 15:17:29 2011
New Revision: 1133420

URL: http://svn.apache.org/viewvc?rev=1133420&view=rev
Log:
[CXF-3579] Checking XmlJavaTypeAdapters when creating parameter beans

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/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.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=1133420&r1=1133419&r2=1133420&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 15:17:29 2011
@@ -66,7 +66,6 @@ import org.apache.cxf.common.util.Packag
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -431,7 +430,7 @@ public abstract class AbstractJAXBProvid
             || JAXBElement.class.isAssignableFrom(type)
             || objectFactoryOrIndexAvailable(type)
             || (type != genericType && objectFactoryForType(genericType))
-            || getAdapter(type, anns) != null;
+            || org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(type, anns) != null;
     
     }
     
@@ -502,32 +501,17 @@ public abstract class AbstractJAXBProvid
         } else {
             theType = type;
         }
-        XmlJavaTypeAdapter adapter = getAdapter(theType, anns);
+        XmlJavaTypeAdapter adapter = org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theType,
anns);
         theType = org.apache.cxf.jaxrs.utils.JAXBUtils.getTypeFromAdapter(adapter, theType,
false);
         
         return theType;
     }
     
     protected static Object checkAdapter(Object obj, Class<?> cls, Annotation[] anns,
boolean marshal) {
-        XmlJavaTypeAdapter adapter = getAdapter(cls, anns);
+        XmlJavaTypeAdapter adapter = org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(cls,
anns);
         return org.apache.cxf.jaxrs.utils.JAXBUtils.useAdapter(obj, adapter, marshal); 
     }
     
-    protected static XmlJavaTypeAdapter getAdapter(Class<?> objectClass, Annotation[]
anns) {
-        XmlJavaTypeAdapter typeAdapter = AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class);
-        if (typeAdapter == null) {
-            typeAdapter = objectClass.getAnnotation(XmlJavaTypeAdapter.class);
-            if (typeAdapter == null) {
-                // lets just try the 1st interface for now
-                Class<?>[] interfaces = objectClass.getInterfaces();
-                typeAdapter = interfaces.length > 0 
-                    ? interfaces[0].getAnnotation(XmlJavaTypeAdapter.class) : null;
-            }
-        }
-        return typeAdapter;
-    }
-    
-    
     protected Schema getSchema() {
         return schema;
     }

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=1133420&r1=1133419&r2=1133420&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 15:17:29 2011
@@ -153,7 +153,7 @@ public class JAXBElementProvider extends
             }
             if (isCollection) {
                 response = ((CollectionWrapper)response).getCollectionOrArray(theType, type,

-                                                         getAdapter(theGenericType, anns));

+                                 org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theGenericType,
anns)); 
             } else {
                 response = checkAdapter(response, type, anns, false);
             }
@@ -284,7 +284,8 @@ public class JAXBElementProvider extends
         }
         os.write(startTag.getBytes());
         if (firstObj != null) {
-            XmlJavaTypeAdapter adapter = getAdapter(firstObj.getClass(), anns);
+            XmlJavaTypeAdapter adapter = 
+                org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns);
             marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true), 
                                     actualClass, genericType, encoding, os, m, 
                                     qname.getNamespaceURI());

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=1133420&r1=1133419&r2=1133420&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 15:17:29 2011
@@ -201,7 +201,7 @@ public class JSONProvider extends Abstra
             }
             if (isCollection) {
                 response = ((CollectionWrapper)response).getCollectionOrArray(theType, type,

-                                                         getAdapter(theGenericType, anns));

+                               org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theGenericType,
anns)); 
             } else {
                 response = checkAdapter(response, type, anns, false);
             }
@@ -357,7 +357,8 @@ public class JSONProvider extends Abstra
         
         os.write(startTag.getBytes());
         if (firstObj != null) {
-            XmlJavaTypeAdapter adapter = getAdapter(firstObj.getClass(), anns);
+            XmlJavaTypeAdapter adapter = 
+                org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns);
             marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true),
                                     actualClass, genericType, encoding, os);
             while (it.hasNext()) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1133420&r1=1133419&r2=1133420&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Jun  8 15:17:29 2011
@@ -426,6 +426,11 @@ public final class InjectionUtils {
                                     ParameterType pType, Message message, boolean decoded)
{
         Object bean = null;
         try {
+            if (paramType.isInterface()) {
+                paramType = org.apache.cxf.jaxrs.utils.JAXBUtils.getValueTypeFromAdapter(paramType,
+                                                                                        
paramType, 
+                                                                                        
paramAnns);
+            }
             bean = paramType.newInstance();
         } catch (IllegalAccessException ex) {
             reportServerError("CLASS_ACCESS_FAILURE", paramType.getName());

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java?rev=1133420&r1=1133419&r2=1133420&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java Wed
Jun  8 15:17:29 2011
@@ -32,7 +32,7 @@ public final class JAXBUtils {
     public static Object convertWithAdapter(Object obj, 
                                             Annotation[] anns) {
         return useAdapter(obj, 
-                          AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class),
+                          getAdapter(obj.getClass(), anns),
                           false, 
                           obj);
     }
@@ -41,7 +41,7 @@ public final class JAXBUtils {
                                                    Class<?> defaultClass,
                                                    Annotation[] anns) {
         try {
-            XmlJavaTypeAdapter adapter = AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class);
+            XmlJavaTypeAdapter adapter = getAdapter(expectedBoundType, anns);
             if (adapter != null) {
                 Class<?> boundType = JAXBUtils.getTypeFromAdapter(adapter, null, true);
                 if (boundType != null && boundType.isAssignableFrom(expectedBoundType))
{
@@ -53,6 +53,20 @@ public final class JAXBUtils {
         }
         return defaultClass; 
     }
+
+    public static XmlJavaTypeAdapter getAdapter(Class<?> objectClass, Annotation[]
anns) {
+        XmlJavaTypeAdapter typeAdapter = AnnotationUtils.getAnnotation(anns, XmlJavaTypeAdapter.class);
+        if (typeAdapter == null) {
+            typeAdapter = objectClass.getAnnotation(XmlJavaTypeAdapter.class);
+            if (typeAdapter == null) {
+                // lets just try the 1st interface for now
+                Class<?>[] interfaces = objectClass.getInterfaces();
+                typeAdapter = interfaces.length > 0 
+                    ? interfaces[0].getAnnotation(XmlJavaTypeAdapter.class) : null;
+            }
+        }
+        return typeAdapter;
+    }
     
     public static Class<?> getTypeFromAdapter(XmlJavaTypeAdapter adapter, Class<?>
theType,
                                               boolean boundType) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1133420&r1=1133419&r2=1133420&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Wed Jun 
8 15:17:29 2011
@@ -62,8 +62,12 @@ import org.apache.cxf.jaxrs.impl.PathSeg
 
 public class Customer extends AbstractCustomer implements CustomerInfo {
     
+    public static interface CustomerBeanInterface {
+        
+    }
+    
     @XmlRootElement(name = "CustomerBean")
-    public static class CustomerBean {
+    public static class CustomerBean implements CustomerBeanInterface {
         private String a;
         private Long b;
         private List<String> c;
@@ -186,6 +190,12 @@ public class Customer extends AbstractCu
         
     }
     
+    public void testXmlAdapter3(@QueryParam("") 
+                                @XmlJavaTypeAdapter(CustomerBeanAdapter3.class) 
+                                CustomerBeanInterface cb) {
+         
+    }
+    
     public void testPathBean(@PathParam("") CustomerBean cb) {
         
     }
@@ -475,4 +485,15 @@ public class Customer extends AbstractCu
         }
         
     }
+    
+    public class CustomerBeanAdapter3 extends XmlAdapter<CustomerBean, CustomerBeanInterface>
{
+        public CustomerBean marshal(CustomerBeanInterface v) throws Exception {
+            return null;
+        }
+
+        public CustomerBeanInterface unmarshal(CustomerBean v) throws Exception {
+            return v;
+        }
+    }
+    
 };

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1133420&r1=1133419&r2=1133420&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Wed Jun  8 15:17:29 2011
@@ -883,6 +883,21 @@ public class JAXRSUtilsTest extends Asse
         assertEquals("aValue", bean.getA());
     }
     
+    @Test
+    public void testXmlAdapterBean3() throws Exception {
+        Class[] argType = {Customer.CustomerBeanInterface.class};
+        Method m = Customer.class.getMethod("testXmlAdapter3", argType);
+        Message messageImpl = createMessage();
+        messageImpl.put(Message.QUERY_STRING, "a=aValue");
+
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null), 
+                                                           null, messageImpl);
+        assertEquals(1, params.size());
+        
+        Customer.CustomerBean bean = (Customer.CustomerBean)params.get(0);
+        assertEquals("aValue", bean.getA());
+    }
+    
     
     @Test
     public void testPathParametersBean() throws Exception {



Mime
View raw message