cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [02/13] cxf git commit: [CXF-6998] Search for ApplicationPath in super classes since its not inherited. This closes #154
Date Tue, 09 Aug 2016 01:34:18 GMT
[CXF-6998] Search for ApplicationPath in super classes since its not inherited. This closes
#154


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8e41f31c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8e41f31c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8e41f31c

Branch: refs/heads/master-jaxrs-2.1
Commit: 8e41f31c855c03eeeed670b53547e5b989fcfdc9
Parents: 07707cd
Author: John D. Ament <johndament@apache.org>
Authored: Sun Aug 7 18:49:16 2016 -0400
Committer: reta <drreta@gmail.com>
Committed: Mon Aug 8 19:38:38 2016 -0400

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 16 ++++++++---
 .../cxf/jaxrs/utils/ResourceUtilsTest.java      | 29 ++++++++++++++++++++
 .../sci/JaxrsServletContainerInitializer.java   |  3 +-
 3 files changed, 43 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8e41f31c/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index 2125869..32fd44e 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -851,7 +851,7 @@ public final class ResourceUtils {
         JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
         String address = "/";
         if (!ignoreAppPath) {
-            ApplicationPath appPath = app.getClass().getAnnotation(ApplicationPath.class);
+            ApplicationPath appPath = locateApplicationPath(app.getClass());
             if (appPath != null) {
                 address = appPath.value();
             }
@@ -939,21 +939,29 @@ public final class ResourceUtils {
         }
         return true;
     }
-    
+
+    public static ApplicationPath locateApplicationPath(Class<?> appClass) {
+        ApplicationPath appPath = appClass.getAnnotation(ApplicationPath.class);
+        if (appPath == null && appClass.getSuperclass() != Application.class) {
+            return locateApplicationPath(appClass.getSuperclass());
+        }
+        return appPath;
+    }
+
     private static boolean isValidApplicationClass(Class<?> c, Set<Object> singletons)
{
         if (!isValidResourceClass(c)) {
             return false;
         }
         for (Object s : singletons) {
             if (c == s.getClass()) {
-                LOG.info("Ignoring per-request resource class " + c.getName() 
+                LOG.info("Ignoring per-request resource class " + c.getName()
                          + " as it is also registered as singleton");
                 return false;
             }
         }
         return true;
     }
-    
+
     //TODO : consider moving JAXBDataBinding.createContext to JAXBUtils
     public static JAXBContext createJaxbContext(Set<Class<?>> classes, Class<?>[]
extraClass, 
                                           Map<String, Object> contextProperties) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/8e41f31c/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
index e1a8ff8..ff873e7 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
@@ -26,14 +26,17 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.jaxrs.Customer;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.Parameter;
@@ -158,6 +161,18 @@ public class ResourceUtilsTest extends Assert {
         assertNotNull(ori);
         assertEquals("GET", ori.getHttpMethod());
     }
+
+    @Test
+    public void shouldCreateApplicationWhichInheritsApplicationPath() throws Exception {
+        JAXRSServerFactoryBean application = ResourceUtils.createApplication(new SuperApplication(),
false);
+        assertEquals("/base", application.getAddress());
+    }
+
+    @Test
+    public void shouldCreateApplicationWhichOverridesApplicationPath() throws Exception {
+        JAXRSServerFactoryBean application = ResourceUtils.createApplication(new CustomApplication(),
false);
+        assertEquals("/custom", application.getAddress());
+    }
     
     public interface IProductResource {
         @Path("/parts")
@@ -218,4 +233,18 @@ public class ResourceUtilsTest extends Assert {
             return null;
         }
     }
+
+    @ApplicationPath("/base")
+    private static class BaseApplication extends Application {
+
+    }
+
+    private static class SuperApplication extends BaseApplication {
+
+    }
+
+    @ApplicationPath("/custom")
+    private static class CustomApplication extends BaseApplication {
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/8e41f31c/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
----------------------------------------------------------------------
diff --git a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
index 38eeeec..d98122a 100644
--- a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
+++ b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/sci/JaxrsServletContainerInitializer.java
@@ -40,6 +40,7 @@ import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
 @HandlesTypes({ Application.class, Provider.class, Path.class })
 public class JaxrsServletContainerInitializer implements ServletContainerInitializer {  
@@ -71,7 +72,7 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial
             }
             // Servlet name is the application class name
             servletName = appClass.getName();
-            ApplicationPath appPath = appClass.getAnnotation(ApplicationPath.class);
+            ApplicationPath appPath = ResourceUtils.locateApplicationPath(appClass);
             // If ApplicationPath is available - use its value as a mapping otherwise get
it from 
             // a servlet registration with an application implementation class name 
             if (appPath != null) {


Mime
View raw message