|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import org.springframework.web.util.WebUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods, |
|
|
|
* {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods, |
|
|
|
@ -44,6 +45,7 @@ import org.springframework.util.StringUtils; |
|
|
|
* <i>before</i> this HiddenHttpMethodFilter in your {@code web.xml} filter chain. |
|
|
|
* <i>before</i> this HiddenHttpMethodFilter in your {@code web.xml} filter chain. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
* @since 3.0 |
|
|
|
* @since 3.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class HiddenHttpMethodFilter extends OncePerRequestFilter { |
|
|
|
public class HiddenHttpMethodFilter extends OncePerRequestFilter { |
|
|
|
@ -67,15 +69,16 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter { |
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
|
|
throws ServletException, IOException { |
|
|
|
throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
String paramValue = request.getParameter(this.methodParam); |
|
|
|
HttpServletRequest requestToUse = request; |
|
|
|
if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) { |
|
|
|
|
|
|
|
String method = paramValue.toUpperCase(Locale.ENGLISH); |
|
|
|
if ("POST".equals(request.getMethod()) && request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) == null) { |
|
|
|
HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method); |
|
|
|
String paramValue = request.getParameter(this.methodParam); |
|
|
|
filterChain.doFilter(wrapper, response); |
|
|
|
if (StringUtils.hasLength(paramValue)) { |
|
|
|
} |
|
|
|
requestToUse = new HttpMethodRequestWrapper(request, paramValue); |
|
|
|
else { |
|
|
|
} |
|
|
|
filterChain.doFilter(request, response); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filterChain.doFilter(requestToUse, response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,7 +92,7 @@ public class HiddenHttpMethodFilter extends OncePerRequestFilter { |
|
|
|
|
|
|
|
|
|
|
|
public HttpMethodRequestWrapper(HttpServletRequest request, String method) { |
|
|
|
public HttpMethodRequestWrapper(HttpServletRequest request, String method) { |
|
|
|
super(request); |
|
|
|
super(request); |
|
|
|
this.method = method; |
|
|
|
this.method = method.toUpperCase(Locale.ENGLISH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|