Add support for HTTP PATCH method

The HTTP PATCH method is now supported whereever HTTP methods are used.
Annotated controllers can be mapped to RequestMethod.PATCH.

On the client side the RestTemplate execute(..) and exchange(..)
methods can be used with HttpMethod.PATCH. In terms of HTTP client
libraries, Apache HttpComponents HttpClient version 4.2 or later is
required (see HTTPCLIENT-1191). The JDK HttpURLConnection does not
support the HTTP PATCH method.

Issue: SPR-7985
This commit is contained in:
Rossen Stoyanchev
2012-06-22 16:47:33 -04:00
parent f05e2bc56f
commit a0747458e7
18 changed files with 211 additions and 98 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestAttributes;
@@ -767,6 +768,25 @@ public abstract class FrameworkServlet extends HttpServletBean {
}
/**
* Override the parent class implementation in order to intercept PATCH
* requests.
*
* @see #doPatch(HttpServletRequest, HttpServletResponse)
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String method = request.getMethod();
if (method.equalsIgnoreCase(RequestMethod.PATCH.name())) {
doPatch(request, response);
}
else {
super.service(request, response);
}
}
/**
* Delegate GET requests to processRequest/doService.
* <p>Will also be invoked by HttpServlet's default implementation of <code>doHead</code>,
@@ -803,6 +823,16 @@ public abstract class FrameworkServlet extends HttpServletBean {
processRequest(request, response);
}
/**
* Delegate PATCH requests to {@link #processRequest}.
* @see #doService
*/
protected final void doPatch(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Delegate DELETE requests to {@link #processRequest}.
* @see #doService