diff --git a/spring-web/src/main/java/org/springframework/http/HttpMethod.java b/spring-web/src/main/java/org/springframework/http/HttpMethod.java index 87173fd381..c38c46fc7b 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -61,7 +61,7 @@ public enum HttpMethod { * @since 4.2.4 */ public boolean matches(String method) { - return name().equals(method); + return (this == resolve(method)); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index e3d859fc0a..773b7cf75b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -838,7 +838,8 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (HttpMethod.PATCH.matches(request.getMethod())) { + HttpMethod httpMethod = HttpMethod.resolve(request.getMethod()); + if (HttpMethod.PATCH == httpMethod || httpMethod == null) { processRequest(request, response); } else { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java index 46fab982b2..fcd27016d4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java @@ -94,6 +94,26 @@ public abstract class AbstractController extends WebContentGenerator implements private boolean synchronizeOnSession = false; + /** + * Create a new AbstractController which supports + * HTTP methods GET, HEAD and POST by default. + */ + public AbstractController() { + this(true); + } + + /** + * Create a new AbstractController. + * @param restrictDefaultSupportedMethods {@code true} if this + * controller should support HTTP methods GET, HEAD and POST by default, + * or {@code false} if it should be unrestricted + * @since 4.3 + */ + public AbstractController(boolean restrictDefaultSupportedMethods) { + super(restrictDefaultSupportedMethods); + } + + /** * Set if controller execution should be synchronized on the session, * to serialize parallel invocations from the same client. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java index 50cf151bff..3df9b642a3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,6 +90,11 @@ public class ServletForwardingController extends AbstractController implements B private String beanName; + public ServletForwardingController() { + super(false); + } + + /** * Set the name of the servlet to forward to, * i.e. the "servlet-name" of the target servlet in web.xml. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java index 8ca0ef0a29..2c353e0e32 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,6 +95,11 @@ public class ServletWrappingController extends AbstractController private Servlet servletInstance; + public ServletWrappingController() { + super(false); + } + + /** * Set the class of the servlet to wrap. * Needs to implement {@code javax.servlet.Servlet}.