cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1021932 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/
Date Tue, 12 Oct 2010 21:28:01 GMT
Author: sergeyb
Date: Tue Oct 12 21:27:59 2010
New Revision: 1021932

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

........
  r1021916 | sergeyb | 2010-10-12 21:39:13 +0100 (Tue, 12 Oct 2010) | 1 line
  
  [CXF-3022] Some improvements to do with the generics support
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntity2.java
      - copied unchanged from r1021916, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntity2.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl2.java
      - copied unchanged from r1021916, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl2.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl3.java
      - copied unchanged from r1021916, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl3.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl4.java
      - copied unchanged from r1021916, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/GenericEntityImpl4.java
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/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1021916

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/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=1021932&r1=1021931&r2=1021932&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
Tue Oct 12 21:27:59 2010
@@ -114,6 +114,11 @@ public final class InjectionUtils {
             }
         }
         
+        Type[] bounds = var.getBounds();
+        if (bounds.length > pos && bounds[pos] != Object.class) {
+            return bounds[pos];
+        }
+                
         Type genericSubtype = serviceClass.getGenericSuperclass();
         if (genericSubtype == Object.class) {
             Type[] genInterfaces = serviceClass.getGenericInterfaces();
@@ -122,8 +127,9 @@ public final class InjectionUtils {
                 break;
             }
         }
-        return genericSubtype != Object.class ? InjectionUtils.getActualType(genericSubtype,
pos)
+        Type result = genericSubtype != Object.class ? InjectionUtils.getActualType(genericSubtype,
pos)
                                               : genericSubtype;
+        return result == null ? Object.class : result;
     }
     
     public static boolean invokeBooleanGetter(Object o, String name) {
@@ -200,16 +206,22 @@ public final class InjectionUtils {
             return null;
         }
         if (!ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
-            Class<?> cls =  (Class<?>)genericType;
+            if (genericType instanceof TypeVariable) {
+                genericType = getType(((TypeVariable)genericType).getBounds(), pos);
+            }
+            Class<?> cls = (Class<?>)genericType;
             return cls.isArray() ? cls.getComponentType() : cls;
         }
         ParameterizedType paramType = (ParameterizedType)genericType;
-        Type[] types = paramType.getActualTypeArguments();
+        Type t = getType(paramType.getActualTypeArguments(), pos);
+        return t instanceof Class ? (Class<?>)t : getActualType(t, pos);
+    }
+    
+    public static Type getType(Type[] types, int pos) {
         if (pos >= types.length) {
             throw new RuntimeException("No type can be found at position " + pos);
         }
-        Type t = types[pos];
-        return t instanceof Class ? (Class<?>)t : getActualType(t, pos);
+        return types[pos];    
     }
     
     public static Class<?> getRawType(Type genericType) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1021932&r1=1021931&r2=1021932&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Oct 12 21:27:59 2010
@@ -530,12 +530,17 @@ public final class JAXRSUtils {
         for (int i = 0; i < parameterTypes.length; i++) {
             Class<?> param = parameterTypes[i]; 
             Type genericParam = genericParameterTypes[i];
-            if (param == Object.class && genericParam instanceof TypeVariable) {
+            if (genericParam instanceof TypeVariable) {
                 genericParam = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),

                                                            (TypeVariable)genericParam);
+            }
+            if (param == Object.class) {
                 param = (Class)genericParam; 
+            } else if (genericParam == Object.class) {
+                genericParam = param;
             }
             
+            
             Object paramValue = processParameter(param, 
                                                  genericParam,
                                                  anns == null ? new Annotation[0] : anns[i],

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1021932&r1=1021931&r2=1021932&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Tue Oct 12 21:27:59 2010
@@ -30,6 +30,9 @@ import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.fortest.BookEntity;
 import org.apache.cxf.jaxrs.fortest.BookEntity2;
 import org.apache.cxf.jaxrs.fortest.GenericEntityImpl;
+import org.apache.cxf.jaxrs.fortest.GenericEntityImpl2;
+import org.apache.cxf.jaxrs.fortest.GenericEntityImpl3;
+import org.apache.cxf.jaxrs.fortest.GenericEntityImpl4;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -64,6 +67,62 @@ public class SelectMethodCandidatesTest 
     }
     
     @Test
+    public void testFindFromAbstractGenericInterface2() throws Exception {
+        doTestGenericSuperType(GenericEntityImpl2.class, "POST");
+    }
+    
+    @Test
+    public void testFindFromAbstractGenericImpl3() throws Exception {
+        doTestGenericSuperType(GenericEntityImpl3.class, "POST");
+    }
+    
+    @Test
+    public void testFindFromAbstractGenericImpl4() throws Exception {
+        JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setResourceClasses(GenericEntityImpl4.class);
+        sf.create();
+        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
+        String contentTypes = "text/xml";
+        String acceptContentTypes = "text/xml";
+        
+        Message m = new MessageImpl();
+        m.put(Message.CONTENT_TYPE, "text/xml");
+        Exchange ex = new ExchangeImpl();
+        ex.setInMessage(m);
+        m.setExchange(ex);
+        Endpoint e = EasyMock.createMock(Endpoint.class);
+        e.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).times(2);
+        e.get("org.apache.cxf.jaxrs.comparator");
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(e);
+        ex.put(Endpoint.class, e);
+        
+        MetadataMap<String, String> values = new MetadataMap<String, String>();
+        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/books",
values,
+                                                                    m);
+        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource, 
+                                                                m, 
+                                    "POST", values, contentTypes, 
+                                    JAXRSUtils.sortMediaTypes(acceptContentTypes),
+                                    true);
+        assertNotNull(ori);
+        assertEquals("resourceMethod needs to be selected", "postEntity",
+                     ori.getMethodToInvoke().getName());
+        
+        String value = "<Books><Book><name>The Book</name><id>2</id></Book></Books>";
+        m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
+        List<Object> params = JAXRSUtils.processParameters(ori, values, m);
+        assertEquals(1, params.size());
+        List<?> books = (List<?>)params.get(0);
+        assertEquals(1, books.size());
+        Book book = (Book)books.get(0);
+        assertNotNull(book);
+        assertEquals(2L, book.getId());
+        assertEquals("The Book", book.getName());
+    }
+    
+    @Test
     public void testFindFromAbstractGenericClass3() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(BookEntity.class);



Mime
View raw message