cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1491834 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
Date Tue, 11 Jun 2013 15:21:48 GMT
Author: sergeyb
Date: Tue Jun 11 15:21:48 2013
New Revision: 1491834

URL: http://svn.apache.org/r1491834
Log:
Merged revisions 1389470 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1389470 | sergeyb | 2012-09-24 17:15:58 +0100 (Mon, 24 Sep 2012) | 1 line
  
  [CXF-4455] Minor update to get Application name-bindings applied to root resources, as well
as an update to get the inheritance between sub and root resources working better
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1389470

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-blocked' - no diff available.

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1491834&r1=1491833&r2=1491834&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Tue Jun 11 15:21:48 2013
@@ -57,6 +57,7 @@ public class ClassResourceInfo extends A
     private boolean createdFromModel; 
     private String consumesTypes;
     private String producesTypes;
+    private ClassResourceInfo parent;
     
     public ClassResourceInfo(ClassResourceInfo cri) {
         super(cri.getBus());       
@@ -69,6 +70,7 @@ public class ClassResourceInfo extends A
             this.paramFields = cri.paramFields;
             this.paramMethods = cri.paramMethods;
             this.enableStatic = true;
+            this.parent = cri.parent;
         } else {
             throw new IllegalArgumentException();
         }
@@ -102,7 +104,7 @@ public class ClassResourceInfo extends A
     
     // The following constructors are used by tests only
     public ClassResourceInfo(Class<?> theResourceClass) {
-        this(theResourceClass, false);
+        this(theResourceClass, true);
     }
     
     public ClassResourceInfo(Class<?> theResourceClass, boolean theRoot) {
@@ -136,12 +138,24 @@ public class ClassResourceInfo extends A
                 ClassResourceInfo tmpCri = subResources.putIfAbsent(key, cri);
                 if (tmpCri != null) {
                     cri = tmpCri;
+                    if (cri != this) {
+                        cri.setParent(this);
+                    }
                 }
             }
         }
         return cri;
     }
     
+    public void addSubClassResourceInfo(ClassResourceInfo cri) {
+        subResources.putIfAbsent(new SubresourceKey(cri.getResourceClass(), 
+                                            cri.getServiceClass()),
+                                 cri);
+        if (cri != this) {
+            cri.setParent(this);
+        }
+    }
+    
     public Collection<ClassResourceInfo> getSubResources() {
         return Collections.unmodifiableCollection(subResources.values());
     }
@@ -214,11 +228,6 @@ public class ClassResourceInfo extends A
         return !subResources.isEmpty();
     }
     
-    public void addSubClassResourceInfo(ClassResourceInfo cri) {
-        subResources.putIfAbsent(new SubresourceKey(cri.getResourceClass(), 
-                                            cri.getServiceClass()),
-                                 cri);
-    }
     
     public boolean isCreatedFromModel() {
         return createdFromModel;
@@ -233,19 +242,27 @@ public class ClassResourceInfo extends A
     }
     
     public List<MediaType> getProduceMime() {
-        if (producesTypes != null) {
-            return JAXRSUtils.parseMediaTypes(producesTypes);
+        if (root || parent == null) {
+            if (producesTypes != null) {
+                return JAXRSUtils.parseMediaTypes(producesTypes);
+            }
+            return JAXRSUtils.getProduceTypes(
+                 AnnotationUtils.getClassAnnotation(getServiceClass(), Produces.class));
+        } else {
+            return parent.getProduceMime();
         }
-        return JAXRSUtils.getProduceTypes(
-             AnnotationUtils.getClassAnnotation(getServiceClass(), Produces.class));
     }
     
     public List<MediaType> getConsumeMime() {
-        if (consumesTypes != null) {
-            return JAXRSUtils.parseMediaTypes(consumesTypes);
+        if (root || parent == null) {
+            if (consumesTypes != null) {
+                return JAXRSUtils.parseMediaTypes(consumesTypes);
+            }
+            return JAXRSUtils.getConsumeTypes(
+                 AnnotationUtils.getClassAnnotation(getServiceClass(), Consumes.class));
+        } else {
+            return parent.getConsumeMime();
         }
-        return JAXRSUtils.getConsumeTypes(
-             AnnotationUtils.getClassAnnotation(getServiceClass(), Consumes.class));
     }
     
     public Path getPath() {
@@ -281,4 +298,8 @@ public class ClassResourceInfo extends A
     public boolean isSingleton() {
         return resourceProvider != null && resourceProvider.isSingleton();
     }
+
+    void setParent(ClassResourceInfo parent) {
+        this.parent = parent;
+    }
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=1491834&r1=1491833&r2=1491834&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
Tue Jun 11 15:21:48 2013
@@ -48,7 +48,7 @@ public class ClassResourceInfoTest exten
     @Path("/bar")
     @Produces("test/bar")
     @Consumes("test/foo")
-    static class TestClass {
+    public static class TestClass {
         @Context UriInfo u;
         @Context HttpHeaders h;
         @Resource HttpServletRequest req;
@@ -74,6 +74,16 @@ public class ClassResourceInfoTest exten
         public void getIt() { 
             
         }
+      
+        @Path("/same")
+        public TestClass2 getThis() { 
+            return this;
+        }
+        
+        @Path("sub")
+        public TestClass3 getTestClass3() { 
+            return new TestClass3();
+        }
     }
     
     static class TestClass3 {
@@ -99,7 +109,7 @@ public class ClassResourceInfoTest exten
     
     @Test
     public void testGetHttpContexts() {
-        ClassResourceInfo c = new ClassResourceInfo(TestClass.class);
+        ClassResourceInfo c = new ClassResourceInfo(TestClass.class, false);
         List<Field> fields = c.getContextFields();
         assertEquals("Only root classes should check these fields", 0, fields.size());
         
@@ -191,4 +201,18 @@ public class ClassResourceInfoTest exten
         assertEquals(2, methods.size());
         assertTrue(methods.contains("HEAD") && methods.contains("GET"));
     }
+    
+    @Test
+    public void testSubresourceInheritProduces() {
+        ClassResourceInfo c = ResourceUtils.createClassResourceInfo(
+                                  TestClass2.class, TestClass2.class, true, true);
+        assertEquals("test/bar", c.getProduceMime().get(0).toString());
+        ClassResourceInfo sub = c.getSubResource(TestClass2.class, TestClass3.class);
+        assertNotNull(sub);
+        assertEquals("test/bar", sub.getProduceMime().get(0).toString());
+        sub = c.getSubResource(TestClass2.class, TestClass2.class);
+        assertNotNull(sub);
+        assertEquals("test/bar", sub.getProduceMime().get(0).toString());
+    }
+    
 }



Mime
View raw message