Author: reto
Date: Wed Jan 27 14:03:01 2010
New Revision: 903644
URL: http://svn.apache.org/viewvc?rev=903644&view=rev
Log:
CLEREZZA-86: applied patch agron, and enhanced test
Modified:
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
Modified:
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java?rev=903644&r1=903643&r2=903644&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
Wed Jan 27 14:03:01 2010
@@ -59,7 +59,6 @@
import org.apache.clerezza.triaxrs.util.URITemplate;
import org.wymiwyg.wrhapi.HandlerException;
import org.wymiwyg.wrhapi.HeaderName;
-import org.wymiwyg.wrhapi.RequestURI;
/**
* @scr.component
@@ -235,17 +234,17 @@
Map<String, String> inheritedPathParams) throws
HandlerException,
UnsupportedFieldType {
Set<Method> result;
- if (remainingPath.equals("/") || (remainingPath.length() == 0))
{
- result = getResourceMethods(instance.getClass());
- for (Method method : result) {
- method2PathParams.put(method,
inheritedPathParams);
- }
- } else
if(remainingPath.equals(RequestURI.Type.NO_RESOURCE.toString())){
+ if(remainingPath == null){
result =
MethodUtil.getAnnotatedMethods(instance.getClass());
for (Method method : result){
method.getDeclaredAnnotations();
method2PathParams.put(method,
inheritedPathParams);
}
+ }else if (remainingPath.equals("/") || (remainingPath.length()
== 0)) {
+ result = getResourceMethods(instance.getClass());
+ for (Method method : result) {
+ method2PathParams.put(method,
inheritedPathParams);
+ }
} else {
SortedSet<MethodDescriptor> methodDescriptors =
getSubThingMethodDescriptors(instance
.getClass());
Modified:
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java?rev=903644&r1=903643&r2=903644&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
Wed Jan 27 14:03:01 2010
@@ -16,134 +16,137 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.clerezza.triaxrs;
-
-import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.clerezza.triaxrs.util.PathMatching;
-import org.wymiwyg.wrhapi.HandlerException;
-import org.wymiwyg.wrhapi.Response;
-
-/**
- * Manages a set of root-resources delivering a suitable root-resource given a
- * path.
- *
- * @author reto
- */
-public class RootResources {
-
- /**
- * @author mir
- *
- */
- public class ResourceAndPathMatching {
-
- private Object rootResource;
- private PathMatching pathMatching;
-
- public ResourceAndPathMatching(Object rootResource,
- PathMatching pathMatching) {
- this.rootResource = rootResource;
- this.pathMatching = pathMatching;
- }
-
- public Object getRootResource() {
- return rootResource;
- }
-
- public PathMatching getPathMatching() {
- return pathMatching;
- }
-
- }
-
- private static ThreadLocal<String> requestUri = new
ThreadLocal<String>() {
- };
-
- public static String getCurrentRequestUri() {
- return requestUri.get();
- }
-
- final static private Logger logger = LoggerFactory
- .getLogger(RootResources.class);
-
- /**
- * we store the resource descriptors
- */
- SortedSet<RootResourceDescriptor> rootResourceDescriptors = new
TreeSet<RootResourceDescriptor>();
-
- /**
- * adds a {...@link RootResourceDescriptor}
- *
- * @param descriptor
- */
- public void add(RootResourceDescriptor descriptor) {
- // TODO Flag an error if the set includes more than one instance
- // of the same class.
- rootResourceDescriptors.add(descriptor);
- }
-
- /**
- * removes a {...@link RootResourceDescriptor}
- *
- * @param descriptor
- */
- public void remove(RootResourceDescriptor descriptor) {
- rootResourceDescriptors.remove(descriptor);
- }
-
- /**
- *
- * @return the number of available root resources
- */
- public int size() {
- return rootResourceDescriptors.size();
- }
-
- /**
- * Get the best matching root-resource for a path
- *
- * @param uriPath
- * @return the matching root-resource or null if no root resources
matches
- */
- public RootResourceDescriptor getDescriptor(String uriPath) {
- for (RootResourceDescriptor descriptor :
rootResourceDescriptors) {
-
- PathMatching pathMatching =
descriptor.getUriTemplate().match(
- uriPath);
- if (pathMatching != null) {
- return descriptor;
- }
- }
- return null;
- }
-
- ResourceAndPathMatching getResourceAndPathMatching(WebRequest request)
- throws HandlerException,
NoMatchingRootResourceException {
- String uriPath =
request.getWrhapiRequest().getRequestURI().getPath();
- requestUri.set(uriPath);
- PathMatching pathMatching = null;
- RootResourceDescriptor descriptor = null;
- Iterator<RootResourceDescriptor> descriptorIter =
rootResourceDescriptors
- .iterator();
- while (descriptorIter.hasNext()) {
- descriptor = descriptorIter.next();
- pathMatching =
descriptor.getUriTemplate().match(uriPath);
- if (pathMatching != null) {
- break;
- }
- }
-
- if (pathMatching == null) {
- throw new NoMatchingRootResourceException();
- }
- return new
ResourceAndPathMatching(descriptor.getInstance(request,
- pathMatching.getParameters()), pathMatching);
- }
-}
+package org.apache.clerezza.triaxrs;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.triaxrs.util.PathMatching;
+import org.wymiwyg.wrhapi.HandlerException;
+
+/**
+ * Manages a set of root-resources delivering a suitable root-resource given a
+ * path.
+ *
+ * @author reto
+ */
+public class RootResources {
+
+ /**
+ * @author mir
+ *
+ */
+ public class ResourceAndPathMatching {
+
+ private Object rootResource;
+ private PathMatching pathMatching;
+
+ public ResourceAndPathMatching(Object rootResource,
+ PathMatching pathMatching) {
+ this.rootResource = rootResource;
+ this.pathMatching = pathMatching;
+ }
+
+ public Object getRootResource() {
+ return rootResource;
+ }
+
+ public PathMatching getPathMatching() {
+ return pathMatching;
+ }
+
+ }
+
+ private static ThreadLocal<String> requestUri = new
ThreadLocal<String>() {
+ };
+
+ public static String getCurrentRequestUri() {
+ return requestUri.get();
+ }
+
+ final static private Logger logger = LoggerFactory
+ .getLogger(RootResources.class);
+
+ /**
+ * we store the resource descriptors
+ */
+ SortedSet<RootResourceDescriptor> rootResourceDescriptors = new
TreeSet<RootResourceDescriptor>();
+
+ /**
+ * adds a {...@link RootResourceDescriptor}
+ *
+ * @param descriptor
+ */
+ public void add(RootResourceDescriptor descriptor) {
+ // TODO Flag an error if the set includes more than one instance
+ // of the same class.
+ rootResourceDescriptors.add(descriptor);
+ }
+
+ /**
+ * removes a {...@link RootResourceDescriptor}
+ *
+ * @param descriptor
+ */
+ public void remove(RootResourceDescriptor descriptor) {
+ rootResourceDescriptors.remove(descriptor);
+ }
+
+ /**
+ *
+ * @return the number of available root resources
+ */
+ public int size() {
+ return rootResourceDescriptors.size();
+ }
+
+ /**
+ * Get the best matching root-resource for a path
+ *
+ * @param uriPath
+ * @return the matching root-resource or null if no root resources
matches
+ */
+ public RootResourceDescriptor getDescriptor(String uriPath) {
+ for (RootResourceDescriptor descriptor :
rootResourceDescriptors) {
+
+ PathMatching pathMatching =
descriptor.getUriTemplate().match(
+ uriPath);
+ if (pathMatching != null) {
+ return descriptor;
+ }
+ }
+ return null;
+ }
+
+ ResourceAndPathMatching getResourceAndPathMatching(WebRequest request)
+ throws HandlerException,
NoMatchingRootResourceException {
+ String uriPath =
request.getWrhapiRequest().getRequestURI().getPath();
+ requestUri.set(uriPath);
+ PathMatching pathMatching = null;
+ RootResourceDescriptor descriptor = null;
+ Iterator<RootResourceDescriptor> descriptorIter =
rootResourceDescriptors
+ .iterator();
+ while (descriptorIter.hasNext()) {
+ descriptor = descriptorIter.next();
+ if (uriPath == null) {
+ PathMatching emptyPathMatching = new
PathMatching(new HashMap<String, String>(), uriPath);
+ return new
ResourceAndPathMatching(descriptor.getInstance(request,
+
emptyPathMatching.getParameters()), emptyPathMatching);
+ }
+ pathMatching =
descriptor.getUriTemplate().match(uriPath);
+ if (pathMatching != null) {
+ break;
+ }
+ }
+
+ if (pathMatching == null) {
+ throw new NoMatchingRootResourceException();
+ }
+ return new
ResourceAndPathMatching(descriptor.getInstance(request,
+ pathMatching.getParameters()), pathMatching);
+ }
+}
Modified:
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java?rev=903644&r1=903643&r2=903644&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/AutoGeneratedOptionsTest.java
Wed Jan 27 14:03:01 2010
@@ -57,6 +57,12 @@
private @interface TEST {
}
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ @HttpMethod("BAR")
+ private @interface TEST2 {
+ }
+
@Path("/")
public static class MyResource {
@@ -79,9 +85,20 @@
}
}
+ @Path("/somepath")
+ public static class MyResource2 {
+
+ @TEST2
+ @Produces("*/*")
+ public void propfind() {
+ }
+
+
+ }
+
@Test
public void testResponseToOptionsRequest() throws Exception {
- JaxRsHandler handler =
HandlerCreator.getHandler(MyResource.class);
+ JaxRsHandler handler =
HandlerCreator.getHandler(MyResource.class, MyResource2.class);
RequestURIImpl uri = new RequestURIImpl();
RequestImpl request = new RequestImpl();
ResponseImpl response = new ResponseImpl();
@@ -148,5 +165,6 @@
Assert.assertTrue(allow.contains("GET"));
Assert.assertTrue(allow.contains("POST"));
Assert.assertTrue(allow.contains("FOO"));
+ Assert.assertTrue(allow.contains("BAR"));
}
}