Skip to content

Commit

Permalink
refs #302 - PATCH request
Browse files Browse the repository at this point in the history
- added PATCH annotation
  • Loading branch information
doctorrokter committed Jul 6, 2016
1 parent 6914019 commit 4fe1219
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -24,7 +24,7 @@
* @author Igor Polevoy
*/
public enum HttpMethod {
GET, POST, PUT, DELETE, HEAD, OPTIONS;
GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS;

/**
* Detects a method from annotation
Expand All @@ -41,6 +41,8 @@ public static HttpMethod method(Annotation annotation){
return PUT;
}else if(annotation instanceof DELETE){
return DELETE;
}else if(annotation instanceof PATCH){
return PATCH;
}else if (annotation instanceof HEAD) {
return HEAD;
}else if (annotation instanceof OPTIONS) {
Expand All @@ -58,6 +60,7 @@ static HttpMethod getMethod(HttpServletRequest request){
String requestMethod = request.getMethod();
requestMethod = requestMethod.equalsIgnoreCase("POST") && methodParam != null && methodParam.equalsIgnoreCase("DELETE")? "DELETE" : requestMethod;
requestMethod = requestMethod.equalsIgnoreCase("POST") && methodParam != null && methodParam.equalsIgnoreCase("PUT")? "PUT" : requestMethod;
requestMethod = requestMethod.equalsIgnoreCase("POST") && request.getHeader("X-HTTP-Method-Override") != null && request.getHeader("X-HTTP-Method-Override").equalsIgnoreCase("PATCH") ? "PATCH" : requestMethod;
return HttpMethod.valueOf(requestMethod.toUpperCase());
}
}
@@ -0,0 +1,15 @@
package org.javalite.activeweb.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Mark an action of a controller with this annotation to receive an HTTP POST request.
*
* @author Mikhail Chachkouski
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PATCH {}

0 comments on commit 4fe1219

Please sign in to comment.