From 3eff478c45997ae8914af1fe65b4bc6539ca9d0b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 24 Mar 2016 13:54:00 +0100 Subject: [PATCH] RequestMethodsRequestCondition uses common HttpMethod resolution Issue: SPR-13776 --- .../RequestMethodsRequestCondition.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java index d174251ccb2..a8f67d3a581 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java @@ -25,6 +25,7 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.cors.CorsUtils; @@ -103,7 +104,6 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi */ @Override public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) { - if (CorsUtils.isPreFlightRequest(request)) { return matchPreFlight(request); } @@ -131,30 +131,21 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi return matchRequestMethod(expectedMethod); } - private RequestMethodsRequestCondition matchRequestMethod(String httpMethod) { - RequestMethod requestMethod = getRequestMethod(httpMethod); - if (requestMethod != null) { + private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { + HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue); + if (httpMethod != null) { for (RequestMethod method : getMethods()) { - if (method.equals(requestMethod)) { + if (httpMethod.matches(method.name())) { return new RequestMethodsRequestCondition(method); } } - if (RequestMethod.HEAD.equals(requestMethod) && getMethods().contains(RequestMethod.GET)) { + if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) { return HEAD_CONDITION; } } return null; } - private RequestMethod getRequestMethod(String httpMethod) { - try { - return RequestMethod.valueOf(httpMethod); - } - catch (IllegalArgumentException ex) { - return null; - } - } - /** * Returns: *