cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1491866 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
Date Tue, 11 Jun 2013 16:26:46 GMT
Author: sergeyb
Date: Tue Jun 11 16:26:46 2013
New Revision: 1491866

URL: http://svn.apache.org/r1491866
Log:
[CXF-5073] Some more fixes to avoid endless recursions

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1491866&r1=1491865&r2=1491866&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Tue Jun 11 16:26:46 2013
@@ -563,12 +563,22 @@ public final class ResourceUtils {
         }
         
         for (ClassResourceInfo sub : resource.getSubResources()) {
-            if (resource != sub) {
+            if (!isRecursiveSubResource(resource, sub)) {
                 getAllTypesForResource(sub, types, jaxbOnly);
             }
         }
     }
     
+    private static boolean isRecursiveSubResource(ClassResourceInfo parent, ClassResourceInfo
sub) {
+        if (parent == null) {
+            return false;
+        }
+        if (parent == sub) {
+            return true;
+        }
+        return isRecursiveSubResource(parent.getParent(), sub);
+    }
+    
     private static void checkJaxbType(Class<?> type, 
                                       Type genericType, 
                                       ResourceTypes types,

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java?rev=1491866&r1=1491865&r2=1491866&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
Tue Jun 11 16:26:46 2013
@@ -26,6 +26,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.jaxrs.Customer;
@@ -117,4 +120,40 @@ public class ResourceUtilsTest extends A
         assertTrue(types.containsKey(Book.class));
         assertTrue(types.containsKey(Chapter.class));
     }
+    @Test
+    public void testGetAllJaxbClasses2() {
+        ClassResourceInfo cri1 = 
+            ResourceUtils.createClassResourceInfo(IProductResource.class, IProductResource.class,
true, true);
+        Map<Class<?>, Type> types = 
+            ResourceUtils.getAllRequestResponseTypes(Collections.singletonList(cri1), true)
+                .getAllTypes();
+        assertEquals(2, types.size());
+        assertTrue(types.containsKey(Book.class));
+        assertTrue(types.containsKey(Chapter.class));
+    }
+    
+    public interface IProductResource {
+        @Path("/parts")
+        IPartsResource getParts();
+    }
+    
+    public interface IPartsResource {
+        @Path("/{i}/")
+        IPartsResource2 elementAt(@PathParam("i") String i);
+        @Path("/parts")
+        IPartsResource getParts();
+        @Path("/products")
+        IProductResource getProducts();
+        @Path("chapter")
+        Chapter get();
+    }
+    
+    public interface IPartsResource2 {
+        @Path("/{i}/")
+        IPartsResource elementAt(@PathParam("i") String i);
+        @Path("/products")
+        IProductResource getProducts();
+        @GET
+        Book get();
+    }
 }



Mime
View raw message