wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r903963 - in /incubator/wink/trunk/wink-server/src: main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java
Date Thu, 28 Jan 2010 05:30:31 GMT
Author: bluk
Date: Thu Jan 28 05:30:30 2010
New Revision: 903963

URL: http://svn.apache.org/viewvc?rev=903963&view=rev
Log:
Fix for missing Allow header in 405 responses

Thanks to Lior Harel for reporting the issue.

Modified:
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java?rev=903963&r1=903962&r2=903963&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
Thu Jan 28 05:30:30 2010
@@ -37,9 +37,11 @@
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
 
 import org.apache.wink.common.RuntimeContext;
 import org.apache.wink.common.WinkApplication;
+import org.apache.wink.common.http.HttpHeadersEx;
 import org.apache.wink.common.http.HttpStatus;
 import org.apache.wink.common.internal.application.ApplicationValidator;
 import org.apache.wink.common.internal.i18n.Messages;
@@ -48,6 +50,7 @@
 import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
 import org.apache.wink.common.internal.uritemplate.UriTemplateMatcher;
 import org.apache.wink.common.internal.uritemplate.UriTemplateProcessor;
+import org.apache.wink.common.internal.utils.HeaderUtils;
 import org.apache.wink.common.internal.utils.MediaTypeUtils;
 import org.apache.wink.common.internal.utils.SoftConcurrentMap;
 import org.slf4j.Logger;
@@ -415,7 +418,12 @@
         if (methodRecords.size() == 0) {
             logger.info(Messages.getMessage("noMethodInClassSupportsHTTPMethod"), resource
                 .getResourceClass().getName(), context.getRequest().getMethod());
-            throw new WebApplicationException(HttpStatus.METHOD_NOT_ALLOWED.getCode());
+            Set<String> httpMethods = getOptions(resource);
+            ResponseBuilder builder = Response.status(HttpStatus.METHOD_NOT_ALLOWED.getCode());
+            // add 'Allow' header to the response
+            String allowHeader = HeaderUtils.buildOptionsHeader(httpMethods);
+            builder.header(HttpHeadersEx.ALLOW, allowHeader);
+            throw new WebApplicationException(builder.build());
         }
 
         // filter by consumes

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java?rev=903963&r1=903962&r2=903963&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java
(original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/FindResourceMethodTest.java
Thu Jan 28 05:30:30 2010
@@ -952,6 +952,10 @@
             MockRequestConstructor.constructMockRequest("DELETE", "/mixed/1", "application/xml");
         response = invoke(request);
         assertEquals(HttpStatus.METHOD_NOT_ALLOWED.getCode(), response.getStatus());
+        assertTrue(response.getHeader("allow").toString().contains("HEAD"));
+        assertTrue(response.getHeader("allow").toString().contains("OPTIONS"));
+        assertTrue(response.getHeader("allow").toString().contains("GET"));
+        assertTrue(response.getHeader("allow").toString().contains("POST"));
 
         request =
             MockRequestConstructor.constructMockRequest("POST",
@@ -1001,6 +1005,7 @@
         request = MockRequestConstructor.constructMockRequest("GET", "/noHttpMethod", "text/plain");
         response = invoke(request);
         assertEquals(HttpStatus.METHOD_NOT_ALLOWED.getCode(), response.getStatus());
+        assertEquals(response.getHeader("allow"), "OPTIONS");
     }
 
     // // -- Helpers --



Mime
View raw message