Skip to content
Browse files

Merge pull request #473 from aparra/options_http

support to options http verb in the controller resources through of Opti...
  • Loading branch information...
2 parents 1612b8f + baa41dd commit ad1e326403642abc76244484b742674e31665cb1 @lucascs lucascs committed Oct 30, 2012
View
43 vraptor-core/src/main/java/br/com/caelum/vraptor/Options.java
@@ -0,0 +1,43 @@
+/***
+ * Copyright (c) 2009 Caelum - www.caelum.com.br/opensource
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package br.com.caelum.vraptor;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Supports the OPTIONS http method.
+ *
+ * @author Douglas Rodrigo Ferreira
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Options {
+
+ /**
+ * All paths that will be mapped to an annotated Resource method.
+ * @return
+ */
+ String[] value() default {};
+
+}
+
View
4 vraptor-core/src/main/java/br/com/caelum/vraptor/resource/HttpMethod.java
@@ -24,13 +24,13 @@
import br.com.caelum.vraptor.Delete;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Head;
+import br.com.caelum.vraptor.Options;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Put;
import br.com.caelum.vraptor.Trace;
public enum HttpMethod {
- // TODO: options?
- GET(Get.class), POST(Post.class), PUT(Put.class), DELETE(Delete.class), TRACE(Trace.class), HEAD(Head.class);
+ GET(Get.class), POST(Post.class), PUT(Put.class), DELETE(Delete.class), TRACE(Trace.class), HEAD(Head.class), OPTIONS(Options.class);
private static final String METHOD_PARAMETER = "_method";
private final Class<? extends Annotation> type;
View
14 ...r-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java
@@ -44,6 +44,7 @@
import br.com.caelum.vraptor.Delete;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Head;
+import br.com.caelum.vraptor.Options;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.core.Converters;
@@ -329,6 +330,10 @@ public void remove() {
public void head() {
}
+ @Options("/clients/options")
+ public void options() {
+ }
+
public void add() {
}
@@ -411,6 +416,15 @@ public void shouldAcceptAResultWithASpecificWebMethod() throws SecurityException
}
+
+ @Test
+ public void shouldAcceptAResultWithOptionsWebMethod() throws SecurityException, NoSuchMethodException {
+ List<Route> routes = parser.rulesFor(new DefaultResourceClass(ClientsController.class));
+ Route route = getRouteMatching(routes, "/clients/options");
+
+ assertThat(route.allowedMethods(), is(EnumSet.of(HttpMethod.OPTIONS)));
+ }
+
static class NiceClients extends ClientsController {
@Override

0 comments on commit ad1e326

Please sign in to comment.
Something went wrong with that request. Please try again.