cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6200] Experimenting with using a default model class
Date Mon, 26 Jan 2015 17:21:22 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes fbfc4b3cb -> 2c0ea1bdf


[CXF-6200] Experimenting with using a default model class


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

Branch: refs/heads/3.0.x-fixes
Commit: 2c0ea1bdf1d5faca4d7cf36045ded87747e25ecc
Parents: fbfc4b3
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Jan 26 17:10:09 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Jan 26 17:21:01 2015 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/JAXRSServiceFactoryBean.java      | 17 ++++-
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 73 +++++++++++---------
 .../cxf/jaxrs/utils/ResourceUtilsTest.java      |  4 +-
 3 files changed, 60 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/2c0ea1bd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
index b615bc3..6230e24 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
@@ -57,6 +57,8 @@ public class JAXRSServiceFactoryBean extends AbstractServiceFactoryBean
{
     private Executor executor;
     private boolean enableStatic;
     private QName serviceName;
+
+    private Class<?> defaultModelClass;
     
     public JAXRSServiceFactoryBean() {
     }
@@ -171,7 +173,10 @@ public class JAXRSServiceFactoryBean extends AbstractServiceFactoryBean
{
         Map<String, UserResource> map = userResourcesAsMap(resources);
         for (UserResource ur : resources) {
             if (ur.getPath() != null) {
-                ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(map, ur, true,
enableStatic,
+                ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(map, ur, 
+                                                                              defaultModelClass,

+                                                                              true, 
+                                                                              enableStatic,
                                                                               getBus());
                 if (cri != null) {
                     classResourceInfos.add(cri);
@@ -184,7 +189,7 @@ public class JAXRSServiceFactoryBean extends AbstractServiceFactoryBean
{
         Map<String, UserResource> map = userResourcesAsMap(resources);
         for (Class<?> sClass : sClasses) {
             ClassResourceInfo cri = ResourceUtils.createServiceClassResourceInfo(
-                map, map.get(sClass.getName()), sClass, true, enableStatic, getBus());
+                map, map.get(sClass.getName()), sClass, false, true, enableStatic, getBus());
             if (cri != null) {
                 classResourceInfos.add(cri);
             }
@@ -265,4 +270,12 @@ public class JAXRSServiceFactoryBean extends AbstractServiceFactoryBean
{
     public void setService(Service service) {
         super.setService(service);
     }
+
+    public Class<?> getDefaultModelClass() {
+        return defaultModelClass;
+    }
+
+    public void setDefaultModelClass(Class<?> defaultModelClass) {
+        this.defaultModelClass = defaultModelClass;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/2c0ea1bd/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 8555fa9..c549936 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
@@ -181,23 +181,20 @@ public final class ResourceUtils {
         return null;
     }
     
-    public static ClassResourceInfo createClassResourceInfo(Map<String, UserResource>
resources, 
-                                                            UserResource model, boolean isRoot,
boolean enableStatic) {
-        return createClassResourceInfo(resources, model, isRoot, enableStatic, 
-                                       BusFactory.getThreadDefaultBus());
-    }
-    
     public static ClassResourceInfo createClassResourceInfo(
-        Map<String, UserResource> resources, UserResource model, boolean isRoot, boolean
enableStatic,
+        Map<String, UserResource> resources, UserResource model,
+        Class<?> defaultClass,
+        boolean isRoot, boolean enableStatic,
         Bus bus) {
-        
-        Class<?> sClass = loadClass(model.getName());
-        return createServiceClassResourceInfo(resources, model, sClass, isRoot, enableStatic,
bus);
+        final boolean isDefaultClass = defaultClass != null;
+        Class<?> sClass = !isDefaultClass  ? loadClass(model.getName()) : defaultClass;
+        return createServiceClassResourceInfo(resources, model, sClass, isDefaultClass, 
+                                              isRoot, enableStatic, bus);
     }
     
     public static ClassResourceInfo createServiceClassResourceInfo(
         Map<String, UserResource> resources, UserResource model, 
-        Class<?> sClass, boolean isRoot, boolean enableStatic, Bus bus) {
+        Class<?> sClass, boolean isDefaultClass, boolean isRoot, boolean enableStatic,
Bus bus) {
         if (model == null) {
             throw new RuntimeException("Resource class " + sClass.getName() + " has no model
info");
         }
@@ -208,30 +205,44 @@ public final class ResourceUtils {
         cri.setURITemplate(t);
         MethodDispatcher md = new MethodDispatcher();
         Map<String, UserOperation> ops = model.getOperationsAsMap();
-        for (Method m : cri.getServiceClass().getMethods()) {
-            UserOperation op = ops.get(m.getName());
-            if (op == null || op.getName() == null) {
-                continue;
-            }
-            OperationResourceInfo ori = 
-                new OperationResourceInfo(m, cri, URITemplate.createTemplate(op.getPath()),
-                                          op.getVerb(), op.getConsumes(), op.getProduces(),
-                                          op.getParameters(),
-                                          op.isOneway());
-            String rClassName = m.getReturnType().getName();
-            if (op.getVerb() == null) {
-                if (resources.containsKey(rClassName)) {
-                    ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri 
-                        : createServiceClassResourceInfo(resources, resources.get(rClassName),
-                                                         m.getReturnType(), false, enableStatic,
bus);
-                    if (subCri != null) {
-                        cri.addSubClassResourceInfo(subCri);
-                        md.bind(ori, m);
+        if (!isDefaultClass) {
+            for (Method m : cri.getServiceClass().getMethods()) {
+                UserOperation op = ops.get(m.getName());
+                if (op == null || op.getName() == null) {
+                    continue;
+                }
+                OperationResourceInfo ori = 
+                    new OperationResourceInfo(m, cri, URITemplate.createTemplate(op.getPath()),
+                                              op.getVerb(), op.getConsumes(), op.getProduces(),
+                                              op.getParameters(),
+                                              op.isOneway());
+                String rClassName = m.getReturnType().getName();
+                if (op.getVerb() == null) {
+                    if (resources.containsKey(rClassName)) {
+                        ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri

+                            : createServiceClassResourceInfo(resources, resources.get(rClassName),
+                                                             m.getReturnType(), false, false,
enableStatic, bus);
+                        if (subCri != null) {
+                            cri.addSubClassResourceInfo(subCri);
+                            md.bind(ori, m);
+                        }
                     }
+                } else {
+                    md.bind(ori, m);
                 }
-            } else {
+            }
+        } else {
+            Method m = cri.getServiceClass().getMethods()[0];
+            for (Map.Entry<String, UserOperation> entry : ops.entrySet()) {
+                UserOperation op = entry.getValue();
+                OperationResourceInfo ori = 
+                    new OperationResourceInfo(m, cri, URITemplate.createTemplate(op.getPath()),
+                                              op.getVerb(), op.getConsumes(), op.getProduces(),
+                                              op.getParameters(),
+                                              op.isOneway());
                 md.bind(ori, m);
             }
+            
         }
         cri.setMethodDispatcher(md);
         return checkMethodDispatcher(cri) ? cri : null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/2c0ea1bd/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 a84a790..e1a8ff8 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
@@ -32,6 +32,7 @@ import javax.ws.rs.PathParam;
 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.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -71,7 +72,8 @@ public class ResourceUtilsTest extends Assert {
         
         Map<String, UserResource> resources = new HashMap<String, UserResource>();
         resources.put(ur.getName(), ur);
-        ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(resources, ur, true,
true);
+        ClassResourceInfo cri = 
+            ResourceUtils.createClassResourceInfo(resources, ur, null, true, true, BusFactory.getDefaultBus());
         assertNotNull(cri);
         assertEquals("/hashmap", cri.getURITemplate().getValue());
         Method method = 


Mime
View raw message