1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 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.
16
16
17
17
package org .springframework .web .filter ;
18
18
19
+ import javax .servlet .DispatcherType ;
19
20
import javax .servlet .FilterChain ;
20
21
import javax .servlet .http .HttpServletRequest ;
21
22
import javax .servlet .http .HttpServletResponse ;
@@ -51,6 +52,7 @@ public void forceEncodingAlwaysSetsEncoding() throws Exception {
51
52
request .setCharacterEncoding (ENCODING );
52
53
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
53
54
given (request .getAttribute (filteredName (FILTER_NAME ))).willReturn (null );
55
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
54
56
55
57
HttpServletResponse response = mock (HttpServletResponse .class );
56
58
FilterChain filterChain = mock (FilterChain .class );
@@ -71,6 +73,7 @@ public void encodingIfEmptyAndNotForced() throws Exception {
71
73
given (request .getCharacterEncoding ()).willReturn (null );
72
74
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
73
75
given (request .getAttribute (filteredName (FILTER_NAME ))).willReturn (null );
76
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
74
77
75
78
MockHttpServletResponse response = new MockHttpServletResponse ();
76
79
@@ -92,6 +95,7 @@ public void doesNotIfEncodingIsNotEmptyAndNotForced() throws Exception {
92
95
given (request .getCharacterEncoding ()).willReturn (ENCODING );
93
96
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
94
97
given (request .getAttribute (filteredName (FILTER_NAME ))).willReturn (null );
98
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
95
99
96
100
MockHttpServletResponse response = new MockHttpServletResponse ();
97
101
@@ -112,6 +116,7 @@ public void withBeanInitialization() throws Exception {
112
116
given (request .getCharacterEncoding ()).willReturn (null );
113
117
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
114
118
given (request .getAttribute (filteredName (FILTER_NAME ))).willReturn (null );
119
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
115
120
116
121
MockHttpServletResponse response = new MockHttpServletResponse ();
117
122
@@ -135,6 +140,7 @@ public void withIncompleteInitialization() throws Exception {
135
140
given (request .getCharacterEncoding ()).willReturn (null );
136
141
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
137
142
given (request .getAttribute (filteredName (CharacterEncodingFilter .class .getName ()))).willReturn (null );
143
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
138
144
139
145
MockHttpServletResponse response = new MockHttpServletResponse ();
140
146
@@ -156,6 +162,7 @@ public void setForceEncodingOnRequestOnly() throws Exception {
156
162
request .setCharacterEncoding (ENCODING );
157
163
given (request .getAttribute (WebUtils .ERROR_REQUEST_URI_ATTRIBUTE )).willReturn (null );
158
164
given (request .getAttribute (filteredName (FILTER_NAME ))).willReturn (null );
165
+ given (request .getDispatcherType ()).willReturn (DispatcherType .REQUEST );
159
166
160
167
HttpServletResponse response = mock (HttpServletResponse .class );
161
168
FilterChain filterChain = mock (FilterChain .class );
0 commit comments