cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r786586 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Date Fri, 19 Jun 2009 17:14:44 GMT
Author: dkulp
Date: Fri Jun 19 17:14:44 2009
New Revision: 786586

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

........
  r785621 | sergeyb | 2009-06-17 10:25:52 -0400 (Wed, 17 Jun 2009) | 2 lines
  
  CXF-2297 : adding a negative Aegis test
........
  r785866 | bimargulies | 2009-06-17 20:31:35 -0400 (Wed, 17 Jun 2009) | 1 line
  
  Fix Aegis support for JAX-RS to deal with generics.
........

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/AbstractAegisProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun 19 17:14:44 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785624,785651,785734,786142,786514
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786514

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 19 17:14:44 2009
@@ -1 +1 @@
-/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784184,784893-785620,785622-785624,785651,785734,785932,786142,786514
+/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784184,784893-785866,785932,786142,786514

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java?rev=786586&r1=786585&r2=786586&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
Fri Jun 19 17:14:44 2009
@@ -20,6 +20,9 @@
 package org.apache.cxf.jaxrs.provider;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.HashSet;
 import java.util.Map;
@@ -63,10 +66,30 @@
             }
         }
         
-        return getClassContext(type);
+        return getClassContext(type, genericType);
     }
     
-    private AegisContext getClassContext(Class<?> type) {
+    
+    private void addType(Set<Class<?>> rootClasses, Type cls, boolean allowArray)
{
+        if (cls instanceof Class) {
+            if (((Class)cls).isArray() && !allowArray) {
+                rootClasses.add(((Class)cls).getComponentType());
+            } else {
+                rootClasses.add((Class)cls);
+            }
+        } else if (cls instanceof ParameterizedType) {
+            for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
+                addType(rootClasses, t2, false);
+            }
+        } else if (cls instanceof GenericArrayType) {
+            GenericArrayType gt = (GenericArrayType)cls;
+            Class ct = (Class) gt.getGenericComponentType();
+            ct = Array.newInstance(ct, 0).getClass();
+
+            rootClasses.add(ct);
+        }
+    }
+    private AegisContext getClassContext(Class<?> type, Type genericType) {
         synchronized (classContexts) {
             AegisContext context = classContexts.get(type);
             if (context == null) {
@@ -75,6 +98,9 @@
                 context.setReadXsiTypes(true);
                 Set<Class<?>> rootClasses = new HashSet<Class<?>>();
                 rootClasses.add(type);
+                if (!(genericType instanceof Class)) {
+                    addType(rootClasses, genericType, true);
+                }
                 context.setRootClasses(rootClasses);
                 context.initialize();
                 classContexts.put(type, context);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java?rev=786586&r1=786585&r2=786586&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Fri Jun 19 17:14:44 2009
@@ -21,11 +21,16 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
 import org.apache.cxf.jaxrs.fortest.AegisTestBean;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -74,4 +79,44 @@
         String xml = new String(bytes, "utf-8");
         assertEquals(SIMPLE_BEAN_XML, xml);
     }
+    
+    private static interface InterfaceWithMap {
+        Map<AegisTestBean, String> mapFunction();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    @org.junit.Ignore
+    public void testReadWriteComplexMap() throws Exception {
+        Map<AegisTestBean, String> map = new HashMap<AegisTestBean, String>();
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        map.put(bean, "hovercraft");
+        
+        MessageBodyWriter<Object> writer = new AegisElementProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        writer.writeTo(bean, null, null, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+                
+        MessageBodyReader<Object> reader = new AegisElementProvider();         
+        byte[] simpleBytes = xml.getBytes("utf-8");
+        
+        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
+        Method method = iwithMapClass.getMethod("mapFunction");
+        Type mapType = method.getGenericReturnType();
+        
+        Object beanObject = reader.readFrom((Class)Map.class, mapType, null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        Map<AegisTestBean, String> map2 = (Map)beanObject;
+        AegisTestBean bean2 = map2.keySet().iterator().next();
+        assertEquals("hovercraft", bean2.getStrValue());
+        assertEquals(Boolean.TRUE, bean2.getBoolValue());
+        
+        
+    }
+    
+    
 }



Mime
View raw message