cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r786850 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Sat, 20 Jun 2009 16:24:47 GMT
Author: sergeyb
Date: Sat Jun 20 16:24:47 2009
New Revision: 786850

URL: http://svn.apache.org/viewvc?rev=786850&view=rev
Log:
JAXRS: avoiding loading model resource class if it is already been loaded elsewhere (ex, OSGI)

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=786850&r1=786849&r2=786850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Sat Jun 20 16:24:47 2009
@@ -247,6 +247,10 @@
         serviceFactory.setUserResources(resources);
     }
     
+    public void setModelBeansWithServiceClass(List<UserResource> resources, Class<?>
sClass) {
+        serviceFactory.setUserResourcesWithServiceClass(resources, sClass);
+    }
+    
     public void setModelRef(String modelRef) {
         List<UserResource> resources = ResourceUtils.getUserResources(modelRef);
         if (resources != null) {
@@ -254,4 +258,12 @@
         }
     }
     
+    public void setModelRefWithServiceClass(String modelRef, Class<?> sClass) {
+        List<UserResource> resources = ResourceUtils.getUserResources(modelRef);
+        if (resources != null) {
+            serviceFactory.setUserResourcesWithServiceClass(resources, sClass);
+        }
+    }
+    
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java?rev=786850&r1=786849&r2=786850&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
Sat Jun 20 16:24:47 2009
@@ -131,10 +131,7 @@
     }
     
     public void setUserResources(List<UserResource> resources) {
-        Map<String, UserResource> map = new HashMap<String, UserResource>();
-        for (UserResource ur : resources) {
-            map.put(ur.getName(), ur);
-        }
+        Map<String, UserResource> map = userResourcesAsMap(resources);
         for (UserResource ur : resources) {
             if (ur.getPath() != null) {
                 ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(map, ur, true);
@@ -145,6 +142,22 @@
         }
     }
     
+    public void setUserResourcesWithServiceClass(List<UserResource> resources, Class<?>
sClass) {
+        Map<String, UserResource> map = userResourcesAsMap(resources);
+        ClassResourceInfo cri = ResourceUtils.createServiceClassResourceInfo(map, sClass,
true);
+        if (cri != null) {
+            classResourceInfos.add(cri);
+        }
+    }
+    
+    private Map<String, UserResource> userResourcesAsMap(List<UserResource> resources)
{
+        Map<String, UserResource> map = new HashMap<String, UserResource>();
+        for (UserResource ur : resources) {
+            map.put(ur.getName(), ur);
+        }
+        return map;
+    }
+    
     protected ClassResourceInfo createResourceInfo(Class cls, boolean isRoot) {
         ClassResourceInfo classResourceInfo = 
             ResourceUtils.createClassResourceInfo(cls, cls, isRoot, enableStatic);

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=786850&r1=786849&r2=786850&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
Sat Jun 20 16:24:47 2009
@@ -119,6 +119,46 @@
 
     }
     
+    public static ClassResourceInfo createServiceClassResourceInfo(
+        Map<String, UserResource> resources, Class<?> sClass, boolean isRoot)
{
+        UserResource model = resources.get(sClass.getName());
+        if (model == null) {
+            throw new RuntimeException("Resource class " + sClass.getName() + " has no model
info");
+        }
+        ClassResourceInfo cri  = new ClassResourceInfo(sClass, sClass, isRoot, true, true);
+        URITemplate t = URITemplate.createTemplate(model.getPath());
+        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());
+            String rClassName = m.getReturnType().getName();
+            if (op.getVerb() == null) {
+                if (resources.containsKey(rClassName)) {
+                    ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri 
+                        : createServiceClassResourceInfo(resources, m.getReturnType(), false);
+                    if (subCri != null) {
+                        cri.addSubClassResourceInfo(subCri);
+                        md.bind(ori, m);
+                    }
+                }
+            } else {
+                md.bind(ori, m);
+            }
+        }
+        cri.setMethodDispatcher(md);
+        return checkMethodDispatcher(cri) ? cri : null;
+
+    }
+    
+    
     public static ClassResourceInfo createClassResourceInfo(
         final Class<?> rClass, final Class<?> sClass, boolean root, boolean enableStatic)
{
         ClassResourceInfo cri  = new ClassResourceInfo(rClass, sClass, root, enableStatic);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java?rev=786850&r1=786849&r2=786850&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java
Sat Jun 20 16:24:47 2009
@@ -80,6 +80,9 @@
             
             sf.setModelBeans(ur, ur2);
             
+            String modelRef = "classpath:/org/apache/cxf/systest/jaxrs/resources/resources2.xml";
+            sf.setModelRefWithServiceClass(modelRef, BookStoreNoAnnotationsInterface.class);
+            sf.setServiceBeans(new BookStoreNoAnnotationsImpl());
             sf.create();
 
         }
@@ -110,6 +113,12 @@
     }
     
     @Test
+    public void testGetBookInterface123() throws Exception {
+        getAndCompare("http://localhost:9080/bookstore2/books/123",
+                      "application/xml", 200);
+    }
+    
+    @Test
     public void testGetChapter() throws Exception {
         
         getAndCompareChapter("http://localhost:9080/bookstoreNoAnnotations/books/123/chapter",



Mime
View raw message