cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r735722 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/main/resources/sche...
Date Mon, 19 Jan 2009 15:07:38 GMT
Author: sergeyb
Date: Mon Jan 19 07:07:37 2009
New Revision: 735722

URL: http://svn.apache.org/viewvc?rev=735722&view=rev
Log:
CXF-1982: dynamic subresource resolution

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.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/Messages.properties
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterface.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
    cxf/trunk/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml
    cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon Jan
19 07:07:37 2009
@@ -33,6 +33,7 @@
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -126,64 +127,59 @@
         }
         
         if (ori.isSubResourceLocator()) {
-            //the result becomes the object that will handle the request
-            if (result != null) {
-                if (result instanceof MessageContentsList) {
-                    result = ((MessageContentsList)result).get(0);
-                } else if (result instanceof List) {
-                    result = ((List)result).get(0);
-                } else if (result.getClass().isArray()) {
-                    result = ((Object[])result)[0];
-                } 
-            }
-            List<Object> newResourceObjects = new ArrayList<Object>();
-            newResourceObjects.add(result);
-        
-            Message msg = exchange.getInMessage();
-            MultivaluedMap<String, String> values = new MetadataMap<String, String>();
                
-            String subResourcePath = (String)msg.get(JAXRSInInterceptor.RELATIVE_PATH);
-            String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD); 
-            String contentType = (String)msg.get(Message.CONTENT_TYPE);
-            if (contentType == null) {
-                contentType = "*/*";
-            }
-            List<MediaType> acceptContentType = 
-                (List<MediaType>)msg.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
-
-            ClassResourceInfo subCri = JAXRSUtils.findSubResourceClass(cri, result.getClass());
-            if (subCri == null) {
-                org.apache.cxf.common.i18n.Message errorM = 
-                    new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",  
-                                                           BUNDLE, 
-                                                           subResourcePath);
-                LOG.severe(errorM.toString());
-                throw new WebApplicationException(404);
-            }
-            
-            OperationResourceInfo subOri = null;
             try {
-                subOri = JAXRSUtils.findTargetMethod(subCri, 
-                                                     subResourcePath, 
-                                                     httpMethod, 
-                                                     values, 
-                                                     contentType, 
-                                                     acceptContentType);
+                Message msg = exchange.getInMessage();
+                MultivaluedMap<String, String> values = new MetadataMap<String,
String>();                 
+                String subResourcePath = (String)msg.get(JAXRSInInterceptor.RELATIVE_PATH);
+                String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD); 
+                String contentType = (String)msg.get(Message.CONTENT_TYPE);
+                if (contentType == null) {
+                    contentType = "*/*";
+                }
+                List<MediaType> acceptContentType = 
+                    (List<MediaType>)msg.getExchange().get(Message.ACCEPT_CONTENT_TYPE);
+                
+                result = checkResultObject(result, subResourcePath); 
+                
+                List<Object> newResourceObjects = new ArrayList<Object>();
+                newResourceObjects.add(result);
+            
+                ClassResourceInfo subCri = cri.getSubResource(
+                     methodToInvoke.getReturnType(), 
+                     ClassHelper.getRealClass(result));
+                if (subCri == null) {
+                    org.apache.cxf.common.i18n.Message errorM = 
+                        new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",  
+                                                               BUNDLE, 
+                                                               subResourcePath);
+                    LOG.severe(errorM.toString());
+                    throw new WebApplicationException(404);
+                }
+                
+                OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(subCri, 
+                                                         subResourcePath, 
+                                                         httpMethod, 
+                                                         values, 
+                                                         contentType, 
+                                                         acceptContentType);
+                
+                
+                exchange.put(OperationResourceInfo.class, subOri);
+                msg.put(JAXRSInInterceptor.RELATIVE_PATH, 
+                        values.getFirst(URITemplate.FINAL_MATCH_GROUP));
+                msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
+                // work out request parameters for the sub-resouce class. Here we
+                // presume Inputstream has not been consumed yet by the root resource class.
+                //I.e., only one place either in the root resource or sub-resouce class can
+                //have a parameter that read from entitybody.
+                List<Object> newParams = JAXRSUtils.processParameters(subOri, values,
msg);
+                msg.setContent(List.class, newParams);
+                
+                return this.invoke(exchange, newParams, newResourceObjects);
             } catch (WebApplicationException ex) {
                 Response excResponse = JAXRSUtils.convertFaultToResponse(ex, baseAddress);
                 return new MessageContentsList(excResponse);
             }
-            
-            exchange.put(OperationResourceInfo.class, subOri);
-            msg.put(JAXRSInInterceptor.RELATIVE_PATH, values.getFirst(URITemplate.FINAL_MATCH_GROUP));
-            msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
-            // work out request parameters for the sub-resouce class. Here we
-            // presume Inputstream has not been consumed yet by the root resource class.
-            //I.e., only one place either in the root resource or sub-resouce class can
-            //have a parameter that read from entitybody.
-            List<Object> newParams = JAXRSUtils.processParameters(subOri, values, msg);
-            msg.setContent(List.class, newParams);
-            
-            return this.invoke(exchange, newParams, newResourceObjects);
         }
         
         return result;
@@ -215,5 +211,25 @@
         return serviceObject;
     }
     
-    
+    private static Object checkResultObject(Object result, String subResourcePath) {
+        if (result == null) {
+            org.apache.cxf.common.i18n.Message errorM = 
+                new org.apache.cxf.common.i18n.Message("NULL_SUBRESOURCE",  
+                                                       BUNDLE, 
+                                                       subResourcePath);
+            LOG.severe(errorM.toString());
+            throw new WebApplicationException(500);
+        }
+        
+        //the result becomes the object that will handle the request
+        if (result instanceof MessageContentsList) {
+            result = ((MessageContentsList)result).get(0);
+        } else if (result instanceof List) {
+            result = ((List)result).get(0);
+        } else if (result.getClass().isArray()) {
+            result = ((Object[])result)[0];
+        }
+        
+        return result;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Mon Jan 19 07:07:37 2009
@@ -68,7 +68,7 @@
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
     private List<String> schemaLocations;
-
+    
     public JAXRSServerFactoryBean() {
         this(new JAXRSServiceFactoryBean());
     }
@@ -83,6 +83,10 @@
         this.schemaLocations = schemas;    
     }
     
+    public void setStaticSubresourceResolution(boolean enableStatic) {
+        serviceFactory.setEnableStaticResolution(enableStatic);
+    }
+    
     public Server create() {
         try {
             Endpoint ep = createEndpoint();

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=735722&r1=735721&r2=735722&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
Mon Jan 19 07:07:37 2009
@@ -19,31 +19,21 @@
 
 package org.apache.cxf.jaxrs;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.ResourceBundle;
 import java.util.concurrent.Executor;
-import java.util.logging.Logger;
 
-import javax.ws.rs.Path;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.MethodDispatcher;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.AbstractServiceFactoryBean;
 import org.apache.cxf.service.invoker.Invoker;
@@ -54,9 +44,6 @@
  */
 public class JAXRSServiceFactoryBean extends AbstractServiceFactoryBean {
     
-    private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServiceFactoryBean.class);
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSServiceFactoryBean.class);
-
     protected List<ClassResourceInfo> classResourceInfos = 
         new ArrayList<ClassResourceInfo>();
     protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class,
ResourceProvider>();
@@ -64,10 +51,16 @@
     private Invoker invoker;
     private Executor executor;
     private Map<String, Object> properties;
-
+    private boolean enableStatic;
+    
     public JAXRSServiceFactoryBean() {
     }
 
+    
+    public void setEnableStaticResolution(boolean staticResolution) {
+        this.enableStatic = staticResolution;
+    }
+    
     @Override
     public Service create() {
         initializeServiceModel();
@@ -121,7 +114,7 @@
     public void setResourceClasses(List<Class> classes) {
         for (Class resourceClass : classes) {
             ClassResourceInfo classResourceInfo = 
-                createClassResourceInfo(resourceClass, resourceClass, true);
+                ResourceUtils.createClassResourceInfo(resourceClass, resourceClass, true,
enableStatic);
             if (classResourceInfo != null) {
                 classResourceInfos.add(classResourceInfo);
             }
@@ -139,7 +132,7 @@
             Class<?> realClass = ClassHelper.getRealClass(bean);
             
             ClassResourceInfo classResourceInfo = 
-                createClassResourceInfo(bean.getClass(), realClass, true);
+                ResourceUtils.createClassResourceInfo(bean.getClass(), realClass, true, enableStatic);
             if (classResourceInfo != null) {
                 classResourceInfos.add(classResourceInfo);
                 
@@ -193,67 +186,7 @@
         injectContexts();
     }
     
-    protected ClassResourceInfo createClassResourceInfo(
-        final Class<?> rClass, final Class<?> sClass, boolean root) {
-        ClassResourceInfo cri  = new ClassResourceInfo(rClass, sClass, root);
-
-        if (root) {
-            URITemplate t = URITemplate.createTemplate(cri, cri.getPath());
-            cri.setURITemplate(t);
-        }
-        
-        MethodDispatcher md = createOperation(cri);
-        cri.setMethodDispatcher(md);
-        return checkMethodDispatcher(cri) ? cri : null;
-    }
-
-    protected MethodDispatcher createOperation(ClassResourceInfo cri) {
-        MethodDispatcher md = new MethodDispatcher();
-        for (Method m : cri.getServiceClass().getMethods()) {
-            
-            Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(m);
-            
-            String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod);
-            Path path = (Path)AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
-            
-            if (httpMethod != null || path != null) {
-                md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m);
-                if (httpMethod == null) {
-                    // subresource locator
-                    Class subResourceClass = m.getReturnType();
-                    ClassResourceInfo subCri = createClassResourceInfo(
-                         subResourceClass, subResourceClass, false);
-                    if (checkMethodDispatcher(subCri)) {
-                        cri.addSubClassResourceInfo(subCri);
-                    }
-                }
-            }
-        }
-        
-        return md;
-    }
     
-    private OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod, 
-                                                      ClassResourceInfo cri, Path path, String
httpMethod) {
-        OperationResourceInfo ori = new OperationResourceInfo(m, cri);
-        URITemplate t = 
-            URITemplate.createTemplate(cri, path);
-        ori.setURITemplate(t);
-        ori.setHttpMethod(httpMethod);
-        ori.setAnnotatedMethod(annotatedMethod);
-        return ori;
-    }
-    
-       
-    private boolean checkMethodDispatcher(ClassResourceInfo cr) {
-        if (cr.getMethodDispatcher().getOperationResourceInfos().isEmpty()) {
-            LOG.warning(new org.apache.cxf.common.i18n.Message("NO_RESOURCE_OP_EXC", 
-                                                               BUNDLE, 
-                                                               cr.getClass().getName()).toString());
-            return false;
-        }
-        return true;
-    }
     
     
     protected Invoker createInvoker() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties Mon
Jan 19 07:07:37 2009
@@ -20,4 +20,5 @@
 #
 NO_RESOURCE_OP_EXC=No resource methods found for resource class {0}
 NO_SUBRESOURCE_FOUND=No subresource locator found for path {0}
+NULL_SUBRESOURCE=Null subresource locator is returned for path {0}
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Mon Jan 19 07:07:37 2009
@@ -23,8 +23,10 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
@@ -33,16 +35,19 @@
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
 public class ClassResourceInfo extends AbstractResourceInfo {
     
     private URITemplate uriTemplate;
     private MethodDispatcher methodDispatcher;
     private ResourceProvider resourceProvider;
-    private List<ClassResourceInfo> subClassResourceInfo = new ArrayList<ClassResourceInfo>();
+    private ConcurrentHashMap<SubresourceKey, ClassResourceInfo> subResources 
+        = new ConcurrentHashMap<SubresourceKey, ClassResourceInfo>();
    
     private List<Field> paramFields;
     private List<Method> paramMethods;
+    private boolean enableStatic;
     
     public ClassResourceInfo(Class<?> theResourceClass) {
         this(theResourceClass, false);
@@ -64,6 +69,41 @@
         }
     }
     
+    public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,

+                             boolean theRoot, boolean enableStatic) {
+        super(theResourceClass, theServiceClass, theRoot);
+        this.enableStatic = enableStatic;
+        if (theRoot) {
+            initParamFields();
+            initParamMethods();
+        }
+    }
+    
+    public ClassResourceInfo findResource(Class<?> typedClass, Class<?> instanceClass)
{
+        instanceClass = enableStatic ? typedClass : instanceClass;
+        SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
+        return subResources.get(key);
+    }
+    
+    public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass)
{
+        
+        instanceClass = enableStatic ? typedClass : instanceClass;
+        
+        SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
+        ClassResourceInfo cri = subResources.get(key);
+        if (cri == null && !enableStatic) {
+            cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, false,
enableStatic);
+            if (cri != null) {
+                subResources.putIfAbsent(key, cri);
+            }
+        }
+        return cri;
+    }
+    
+    public Collection<ClassResourceInfo> getSubResources() {
+        return Collections.unmodifiableCollection(subResources.values());
+    }
+    
     private void initParamFields() {
         if (getResourceClass() == null || !isRoot()) {
             return;
@@ -115,15 +155,13 @@
     }
 
     public boolean hasSubResources() {
-        return !subClassResourceInfo.isEmpty();
+        return !subResources.isEmpty();
     }
     
     public void addSubClassResourceInfo(ClassResourceInfo cri) {
-        subClassResourceInfo.add(cri);
-    }
-    
-    public List<ClassResourceInfo> getSubClassResourceInfo() {
-        return subClassResourceInfo;
+        subResources.putIfAbsent(new SubresourceKey(cri.getResourceClass(), 
+                                            cri.getServiceClass()),
+                                 cri);
     }
     
     public ResourceProvider getResourceProvider() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
Jan 19 07:07:37 2009
@@ -164,17 +164,6 @@
         return supportedMimeTypes;
     }
     
-    public static ClassResourceInfo findSubResourceClass(ClassResourceInfo resource,
-                                                         Class subResourceClassType) {
-        for (ClassResourceInfo subCri : resource.getSubClassResourceInfo()) {
-            if (subCri.getResourceClass().isAssignableFrom(subResourceClassType)) {
-                return subCri;
-            }
-        }
-        return null;
-    }
-
-    
     @SuppressWarnings("unchecked")
     public static void handleSetters(OperationResourceInfo ori,
                                      Object requestObject,

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd Mon Jan 19 07:07:37 2009
@@ -59,6 +59,7 @@
           <xsd:attribute name="transportId" type="xsd:string"/>
           <xsd:attribute name="endpointName" type="xsd:QName" />
           <xsd:attribute name="serviceName" type="xsd:QName" />
+          <xsd:attribute name="staticSubresourceResolution" type="xsd:boolean" />
         </xsd:extension>
       </xsd:complexContent>
     </xsd:complexType>

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java
Mon Jan 19 07:07:37 2009
@@ -41,6 +41,7 @@
     @Test
     public void testNoSubResources() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setEnableStaticResolution(true);
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class);
         sf.create();
         
@@ -70,6 +71,7 @@
     @Test
     public void testSubResources() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setEnableStaticResolution(true);
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
         sf.create();
         
@@ -124,8 +126,8 @@
         }
         
         // Verify sub-resource ClassResourceInfo: Book
-        assertEquals(2, rootCri.getSubClassResourceInfo().size());
-        ClassResourceInfo subCri = rootCri.getSubClassResourceInfo().get(0);        
+        assertEquals(1, rootCri.getSubResources().size());
+        ClassResourceInfo subCri = rootCri.getSubResources().iterator().next();        
         assertNull(subCri.getURITemplate());
         assertEquals(org.apache.cxf.jaxrs.resources.Book.class, subCri.getResourceClass());
         MethodDispatcher subMd = subCri.getMethodDispatcher();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
Mon Jan 19 07:07:37 2009
@@ -29,6 +29,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
@@ -50,18 +51,36 @@
         @Resource HttpServletResponse res;
         @Resource ServletContext c;
         int i;
+        
+        @GET
+        public void getIt() { 
+            
+        }
     }
     
     private static class TestClass1 extends TestClass {
+        @GET
+        public void getIt() { 
+            
+        }
     }
     
     private static class TestClass2 extends TestClass1 {
+        @GET
+        public void getIt() { 
+            
+        }
     }
     
     private static class TestClass3 {
         @Resource HttpServletRequest req;
         @Resource HttpServletResponse res;
         @Resource ServletContext c;
+        
+        @GET
+        public void getIt() { 
+            
+        }
     }
     
     @Test
@@ -134,4 +153,33 @@
         c = new ClassResourceInfo(TestClass2.class);
         assertEquals("test/foo", c.getConsumeMime().value()[0]);
     }
+    
+    @Test
+    public void testGetSameSubresource() {
+        ClassResourceInfo c = new ClassResourceInfo(TestClass.class);
+        assertEquals("No subresources expected", 0, c.getSubResources().size());
+        assertNull(c.findResource(TestClass.class, TestClass.class));
+        ClassResourceInfo c1 = c.getSubResource(TestClass.class, TestClass.class);
+        assertNotNull(c1);
+        assertSame(c1, c.findResource(TestClass.class, TestClass.class));
+        assertSame(c1, c.getSubResource(TestClass.class, TestClass.class));
+        assertEquals("Single subresources expected", 1, c.getSubResources().size());
+    }
+    
+    @Test
+    public void testGetSubresourceSubclass() {
+        ClassResourceInfo c = new ClassResourceInfo(TestClass.class);
+        assertEquals("No subresources expected", 0, c.getSubResources().size());
+        assertNull(c.findResource(TestClass.class, TestClass1.class));
+        ClassResourceInfo c1 = c.getSubResource(TestClass.class, TestClass1.class);
+        assertNotNull(c1);
+        assertSame(c1, c.findResource(TestClass.class, TestClass1.class));
+        assertNull(c.findResource(TestClass.class, TestClass2.class));
+        ClassResourceInfo c2 = c.getSubResource(TestClass.class, TestClass2.class);
+        assertNotNull(c2);
+        assertSame(c2, c.findResource(TestClass.class, TestClass2.class));
+        assertSame(c2, c.getSubResource(TestClass.class, TestClass2.class));
+        assertNotSame(c1, c2);
+        
+    }
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java Mon Jan 19 07:07:37
2009
@@ -74,7 +74,13 @@
         System.out.println("----invoking getChapter with chapterid: " + chapterid);
 
         return chapters.get(new Long(chapterid));
-    } 
+    }
+    
+    @Path("chaptersobject/sub/{chapterid}/")    
+    public Object getSubChapterObject(@PathParam("chapterid")int chapterid) {
+        return getSubChapter(chapterid);
+    }
+    
     
     final void init() {
         Chapter c1 = new Chapter();

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Mon Jan 19
07:07:37 2009
@@ -246,6 +246,11 @@
         }
     }
     
+    @Path("/booksubresourceobject/{bookId}/")
+    public Object getBookSubResourceObject(@PathParam("bookId") String id) throws BookNotFoundFault
{
+        return getBookSubResource(id);
+    }
+    
     @GET
     @Path("/booknames/{bookId}/")
     @Produces("text/*")

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java Mon Jan 19
07:07:37 2009
@@ -54,5 +54,11 @@
     public Chapter getItself() {
         return this;
     }
+    
+    @GET
+    @Produces("application/xml;charset=ISO-8859-1")
+    public Chapter get() {
+        return this;
+    }
 
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Jan 19 07:07:37 2009
@@ -42,7 +42,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
     }
     
     @Test
@@ -290,6 +290,13 @@
     }
     
     @Test
+    public void testGetBook123FromSubObject() throws Exception {
+        getAndCompareAsStrings(
+            "http://localhost:9080/bookstore/booksubresourceobject/123/chaptersobject/sub/1",
+            "resources/expected_get_chapter1.txt", "application/xml", 200);
+    }
+    
+    @Test
     public void testGetChapter() throws Exception {
         
         getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/1",

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
Mon Jan 19 07:07:37 2009
@@ -61,5 +61,11 @@
         getBook(endpointAddress, "bob", "bobspassword", 403);
     }
     
-       
+    @Test
+    public void testGetBookSubresource() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/bookstorestorage/subresource"; 
+        getBook(endpointAddress, "foo", "bar", 200); 
+        getBook(endpointAddress, "bob", "bobspassword", 403);
+    }   
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterface.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterface.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterface.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookInterface.java
Mon Jan 19 07:07:37 2009
@@ -49,4 +49,11 @@
     @Secured("ROLE_ADMIN")
     Book getThatBook() throws BookNotFoundFault;
     
+    @Path("/subresource")
+    SecureBookInterface getBookSubResource() throws BookNotFoundFault;
+    
+    @GET
+    @Produces("application/xml")
+    @Secured("ROLE_ADMIN")
+    Book getDefaultBook() throws BookNotFoundFault;
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
Mon Jan 19 07:07:37 2009
@@ -22,6 +22,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.annotation.Resource;
 import javax.ws.rs.Path;
 
 import org.apache.cxf.systest.jaxrs.Book;
@@ -30,7 +31,8 @@
 @Path("/bookstorestorage/")
 public class SecureBookStore implements SecureBookInterface {
     private Map<Long, Book> books = new HashMap<Long, Book>();
-  
+    private SecureBookInterface subresource;
+    
     public SecureBookStore() {
         Book book = new Book();
         book.setId(123L);
@@ -38,6 +40,11 @@
         books.put(book.getId(), book);
     }
     
+    @Resource
+    public void setBookStore(SecureBookInterface sb) {
+        subresource = sb;
+    }
+    
     public Book getThatBook(Long id) {
         return books.get(id);
     }
@@ -52,4 +59,12 @@
     public Book getThatBook() throws BookNotFoundFault {
         return books.get(123L);
     }
+
+    public SecureBookInterface getBookSubResource() throws BookNotFoundFault {
+        return subresource;
+    }
+
+    public Book getDefaultBook() throws BookNotFoundFault {
+        return books.get(123L);
+    }
 }

Modified: cxf/trunk/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs_atom/WEB-INF/beans.xml Mon Jan 19 07:07:37
2009
@@ -39,7 +39,8 @@
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
   
   <jaxrs:server id="atomservice"
-		        address="/">
+		        address="/" 
+		        staticSubresourceResolution="true">
     <jaxrs:serviceBeans>
       <ref bean="atomstore"/>
       <ref bean="atomstore2"/>

Modified: cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml?rev=735722&r1=735721&r2=735722&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml Mon Jan 19 07:07:37
2009
@@ -53,7 +53,11 @@
     </jaxrs:providers>		   
   </jaxrs:server>
 
-  <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.security.SecureBookStore"/>
+  <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.security.SecureBookStore">
+     <property name="bookStore" ref="bookstore2"/>
+  </bean>
+  
+  <bean id="bookstore2" class="org.apache.cxf.systest.jaxrs.security.SecureBookStore"/>
 
   <security:global-method-security secured-annotations="enabled"/>
   



Mime
View raw message