cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1491934 - in /cxf/branches/2.5.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 20:08:06 GMT
Author: sergeyb
Date: Tue Jun 11 20:08:05 2013
New Revision: 1491934

URL: http://svn.apache.org/r1491934
Log:
Merged revisions 1491834 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1491834 | sergeyb | 2013-06-11 16:21:48 +0100 (Tue, 11 Jun 2013) | 9 lines
  
  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.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java

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

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

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1491934&r1=1491933&r2=1491934&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Tue Jun 11 20:08:05 2013
@@ -55,6 +55,7 @@ public class ClassResourceInfo extends A
     private boolean createdFromModel; 
     private String consumesTypes;
     private String producesTypes;
+    private ClassResourceInfo parent;
     
     public ClassResourceInfo(Class<?> theResourceClass) {
         this(theResourceClass, false);
@@ -71,6 +72,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();
         }
@@ -128,12 +130,27 @@ public class ClassResourceInfo extends A
         if (cri == null && !enableStatic) {
             cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, false,
enableStatic);
             if (cri != null) {
-                subResources.putIfAbsent(key, cri);
+                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());
     }
@@ -206,11 +223,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;
@@ -225,19 +237,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(
+                 (Produces)AnnotationUtils.getClassAnnotation(getServiceClass(), Produces.class));
+        } else {
+            return parent.getProduceMime();
         }
-        return JAXRSUtils.getProduceTypes(
-             (Produces)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(
+                 (Consumes)AnnotationUtils.getClassAnnotation(getServiceClass(), Consumes.class));
+        } else {
+            return parent.getConsumeMime();
         }
-        return JAXRSUtils.getConsumeTypes(
-             (Consumes)AnnotationUtils.getClassAnnotation(getServiceClass(), Consumes.class));
     }
     
     public Path getPath() {
@@ -273,4 +293,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.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=1491934&r1=1491933&r2=1491934&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
Tue Jun 11 20:08:05 2013
@@ -47,7 +47,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;
@@ -73,6 +73,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 {
@@ -93,7 +103,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());
         
@@ -199,4 +209,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