1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
26
26
27
27
import org .springframework .util .Assert ;
28
28
import org .springframework .util .StringUtils ;
29
+ import org .springframework .web .util .WebUtils ;
29
30
30
31
/**
31
32
* {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods,
44
45
* <i>before</i> this HiddenHttpMethodFilter in your {@code web.xml} filter chain.
45
46
*
46
47
* @author Arjen Poutsma
48
+ * @author Juergen Hoeller
47
49
* @since 3.0
48
50
*/
49
51
public class HiddenHttpMethodFilter extends OncePerRequestFilter {
@@ -67,15 +69,16 @@ public void setMethodParam(String methodParam) {
67
69
protected void doFilterInternal (HttpServletRequest request , HttpServletResponse response , FilterChain filterChain )
68
70
throws ServletException , IOException {
69
71
70
- String paramValue = request .getParameter (this .methodParam );
71
- if ("POST" .equals (request .getMethod ()) && StringUtils .hasLength (paramValue )) {
72
- String method = paramValue .toUpperCase (Locale .ENGLISH );
73
- HttpServletRequest wrapper = new HttpMethodRequestWrapper (request , method );
74
- filterChain .doFilter (wrapper , response );
75
- }
76
- else {
77
- filterChain .doFilter (request , response );
72
+ HttpServletRequest requestToUse = request ;
73
+
74
+ if ("POST" .equals (request .getMethod ()) && request .getAttribute (WebUtils .ERROR_EXCEPTION_ATTRIBUTE ) == null ) {
75
+ String paramValue = request .getParameter (this .methodParam );
76
+ if (StringUtils .hasLength (paramValue )) {
77
+ requestToUse = new HttpMethodRequestWrapper (request , paramValue );
78
+ }
78
79
}
80
+
81
+ filterChain .doFilter (requestToUse , response );
79
82
}
80
83
81
84
@@ -89,7 +92,7 @@ private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper
89
92
90
93
public HttpMethodRequestWrapper (HttpServletRequest request , String method ) {
91
94
super (request );
92
- this .method = method ;
95
+ this .method = method . toUpperCase ( Locale . ENGLISH ) ;
93
96
}
94
97
95
98
@ Override
0 commit comments