Permalink
Browse files

native support for OPTIONS requests

  • Loading branch information...
1 parent 6079135 commit b49ca1f8592315caef9b3cae5646af25c4e31318 @lucascs lucascs committed Sep 10, 2010
@@ -49,12 +49,12 @@ public ResourceMethod translate(RequestInfo info) {
String resourceName = info.getRequestedUri();
logger.debug("trying to access {}", resourceName);
-
+
HttpMethod method;
try {
method = HttpMethod.of(request);
} catch (IllegalArgumentException e) {
- throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), null);
+ throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod());
}
ResourceMethod resource = router.parse(resourceName, method, request);
@@ -47,24 +47,24 @@
private final ResourceNotFoundHandler resourceNotFoundHandler;
private final MethodNotAllowedHandler methodNotAllowedHandler;
- public ResourceLookupInterceptor(UrlToResourceTranslator translator, MethodInfo requestInfo,
+ public ResourceLookupInterceptor(UrlToResourceTranslator translator, MethodInfo methodInfo,
ResourceNotFoundHandler resourceNotFoundHandler, MethodNotAllowedHandler methodNotAllowedHandler,
- RequestInfo request) {
+ RequestInfo requestInfo) {
this.translator = translator;
- this.methodInfo = requestInfo;
+ this.methodInfo = methodInfo;
this.methodNotAllowedHandler = methodNotAllowedHandler;
this.resourceNotFoundHandler = resourceNotFoundHandler;
- this.requestInfo = request;
+ this.requestInfo = requestInfo;
}
- public void intercept(InterceptorStack invocation, ResourceMethod ignorableMethod, Object resourceInstance)
+ public void intercept(InterceptorStack stack, ResourceMethod ignorableMethod, Object resourceInstance)
throws InterceptionException {
try {
ResourceMethod method = translator.translate(requestInfo);
methodInfo.setResourceMethod(method);
- invocation.next(method, resourceInstance);
+ stack.next(method, resourceInstance);
} catch (ResourceNotFoundException e) {
resourceNotFoundHandler.couldntFind(requestInfo);
} catch (MethodNotAllowedException e) {
@@ -38,7 +38,9 @@ public void deny(RequestInfo request, Set<HttpMethod> allowedMethods) {
request.getResponse().addHeader(
"Allow", allowedMethods.toString().replaceAll("\\[|\\]", ""));
try {
- request.getResponse().sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ if (!"OPTIONS".equalsIgnoreCase(request.getRequest().getMethod())) {
+ request.getResponse().sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ }
} catch (IOException e) {
throw new InterceptionException(e);
}
@@ -27,7 +27,6 @@
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Put;
import br.com.caelum.vraptor.Trace;
-import br.com.caelum.vraptor.http.route.MethodNotAllowedException;
public enum HttpMethod {
// TODO: options?
Oops, something went wrong.

3 comments on commit b49ca1f

Contributor

douglasrodrigo commented on b49ca1f Oct 22, 2012

Hi guys, I would like to know if OPTIONS will be supported like the others verbs with an OPTION annotation and valid HttpMethod, I've been using VRaptor on my REST application, and I need to support preflight requests and my current solution was to create a custom MethodNotAllowedHandler adding cross domain policy headers like Access-Control-Allow-Origin.

Contributor

douglasrodrigo replied Oct 22, 2012

Great, I'll work on it.

Please sign in to comment.