Index: /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceLocator.java =================================================================== --- /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceLocator.java (revision 184) +++ /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceLocator.java (working copy) @@ -1,5 +1,13 @@ package org.resteasy; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URLDecoder; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + import org.resteasy.specimpl.PathSegmentImpl; import org.resteasy.specimpl.UriInfoImpl; import org.resteasy.spi.HttpRequest; @@ -11,13 +19,6 @@ import org.resteasy.util.GetRestful; import org.resteasy.util.HttpResponseCodes; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URLDecoder; -import java.util.concurrent.ConcurrentHashMap; - /** * @author Bill Burke * @version $Revision: 1 $ @@ -143,13 +144,16 @@ if (registry == null) { registry = new ResourceMethodRegistry(providerFactory); - Class subResourceClass = GetRestful.getSubResourceClass(target.getClass()); - if (subResourceClass == null) + List subResourceClasses = GetRestful.getSubResourceClass(target.getClass()); + if (subResourceClasses.isEmpty()) { - String msg = "Subresource class has no jax-rs annotations.: " + subResourceClass.getName(); + String msg = "Subresource class has no jax-rs annotations.: " + target.getClass().getName(); throw new Failure(msg, HttpResponseCodes.SC_INTERNAL_SERVER_ERROR); } - registry.addResourceFactory(null, null, subResourceClass, uriIndex + index.getOffset(), limited); + for(Class subResourceClass : subResourceClasses) + { + registry.addResourceFactory(null, null, subResourceClass, uriIndex + index.getOffset(), limited); + } cachedSubresources.putIfAbsent(target.getClass(), registry); } ResourceInvoker invoker = registry.getResourceInvoker(request, response, uriIndex + index.getOffset(), limited); Index: /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceMethodRegistry.java =================================================================== --- /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceMethodRegistry.java (revision 184) +++ /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/ResourceMethodRegistry.java (working copy) @@ -16,6 +16,7 @@ import javax.ws.rs.Path; import java.lang.reflect.Method; +import java.util.List; import java.util.Set; /** @@ -93,8 +94,8 @@ public void addResourceFactory(ResourceFactory ref, String base) { Class clazz = ref.getScannableClass(); - Class restful = GetRestful.getRootResourceClass(clazz); - if (restful == null) + List restfuls = GetRestful.getRootResourceClass(clazz); + if (restfuls.isEmpty()) { String msg = "Class is not a root resource. It, or one of its interfaces must be annotated with @Path: " + clazz.getName() + " implements: "; for (Class intf : clazz.getInterfaces()) @@ -103,7 +104,10 @@ } throw new RuntimeException(msg); } - addResourceFactory(ref, base, restful, 0, true); + for(Class restful : restfuls) + { + addResourceFactory(ref, base, restful, 0, true); + } } /** @@ -172,8 +176,11 @@ public void removeRegistrations(Class clazz, String base) { - Class restful = GetRestful.getRootResourceClass(clazz); - removeRegistration(base, restful); + List restfuls = GetRestful.getRootResourceClass(clazz); + for(Class restful : restfuls) + { + removeRegistration(base, restful); + } } private void removeRegistration(String base, Class clazz) Index: /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/util/GetRestful.java =================================================================== --- /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/util/GetRestful.java (revision 184) +++ /home/gdunkle.fedora/workspace/resteasy/resteasy-jaxrs/src/main/java/org/resteasy/util/GetRestful.java (working copy) @@ -1,9 +1,12 @@ package org.resteasy.util; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + import javax.ws.rs.HttpMethod; import javax.ws.rs.Path; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; /** * @author Bill Burke @@ -11,73 +14,117 @@ */ public class GetRestful { - /** - * Given a class, search itself and implemented interfaces for jax-rs annotations. - * - * @param clazz - * @return list of class and intertfaces that have jax-rs annotations - */ - public static Class getRootResourceClass(Class clazz) - { - if (clazz.isAnnotationPresent(Path.class)) - { - - return clazz; - } - // ok, no @Path or @HttpMethods so look in interfaces. - Class[] intfs = clazz.getInterfaces(); - for (Class intf : intfs) - { - if (intf.isAnnotationPresent(Path.class)) - { - return intf; - } - } - return null; - } + /** + * Given a class, search itself and implemented interfaces for jax-rs annotations. + * + * @param clazz + * @return list of class and intertfaces that have jax-rs annotations + */ + public static List getRootResourceClass(Class clazz) + { + List restfuls = new ArrayList(); + if (clazz.isAnnotationPresent(Path.class)) + { + restfuls.add(clazz); + } + // ok, no @Path or @HttpMethods so look in interfaces. + Class[] intfs = clazz.getInterfaces(); + for (Class intf : intfs) + { + if (intf.isAnnotationPresent(Path.class)) + { + restfuls.add(intf); + } + } + return restfuls; + } - /** - * Given a class, search itself and implemented interfaces for jax-rs annotations. - * - * @param clazz - * @return list of class and intertfaces that have jax-rs annotations - */ - public static Class getSubResourceClass(Class clazz) - { - if (clazz.isAnnotationPresent(Path.class)) - { - return clazz; - } - for (Method method : clazz.getMethods()) - { - if (method.isAnnotationPresent(Path.class)) return clazz; - for (Annotation ann : method.getAnnotations()) - { - if (ann.annotationType().isAnnotationPresent(HttpMethod.class)) return clazz; - } - } - // ok, no @Path or @HttpMethods so look in interfaces. - Class[] intfs = clazz.getInterfaces(); - for (Class intf : intfs) - { - if (intf.isAnnotationPresent(Path.class)) - { - return intf; - } - for (Method method : intf.getMethods()) - { - if (method.isAnnotationPresent(Path.class)) return intf; + /** + * Given a class, search itself and implemented interfaces for jax-rs annotations. + * + * @param clazz + * @return list of class and intertfaces that have jax-rs annotations + */ + public static List getSubResourceClass(Class clazz) + { + List restfuls = new ArrayList(); + if (clazz.isAnnotationPresent(Path.class)) + { + restfuls.add(clazz); + } + for (Method method : clazz.getMethods()) + { + if (method.isAnnotationPresent(Path.class)) + { + if (!restfuls.contains(clazz)) + { + restfuls.add(clazz); + } + else + { + break; + } + } for (Annotation ann : method.getAnnotations()) { - if (ann.annotationType().isAnnotationPresent(HttpMethod.class)) return intf; + if (ann.annotationType().isAnnotationPresent(HttpMethod.class)) + { + if (!restfuls.contains(clazz)) + { + restfuls.add(clazz); + } + else + { + break; + } + } } - } - } - return null; - } + } + // ok, no @Path or @HttpMethods so look in interfaces. + Class[] intfs = clazz.getInterfaces(); + for (Class intf : intfs) + { + if (intf.isAnnotationPresent(Path.class)) + { + if (!restfuls.contains(intf)) + { + restfuls.add(intf); + } + } + for (Method method : intf.getMethods()) + { + if (method.isAnnotationPresent(Path.class)) + { + if (!restfuls.contains(intf)) + { + restfuls.add(intf); + } + else + { + break; + } + } + for (Annotation ann : method.getAnnotations()) + { + if (ann.annotationType().isAnnotationPresent(HttpMethod.class)) + { + if (!restfuls.contains(intf)) + { + restfuls.add(intf); + } + else + { + break; + } + } + } + } + } + return restfuls; + } - public static boolean isRootResource(Class clazz) - { - return getRootResourceClass(clazz) != null; - } + public static boolean isRootResource(Class clazz) + { + return getRootResourceClass(clazz) != null; + } } \ No newline at end of file