@@ -185,7 +185,44 @@ public final Object invokeHandlerMethod(Method handlerMethod, Object handler,
185
185
}
186
186
}
187
187
188
- @ SuppressWarnings ("unchecked" )
188
+ public final void updateModelAttributes (Object handler , Map <String , Object > mavModel ,
189
+ ExtendedModelMap implicitModel , NativeWebRequest webRequest ) throws Exception {
190
+
191
+ if (this .methodResolver .hasSessionAttributes () && this .sessionStatus .isComplete ()) {
192
+ for (String attrName : this .methodResolver .getActualSessionAttributeNames ()) {
193
+ this .sessionAttributeStore .cleanupAttribute (webRequest , attrName );
194
+ }
195
+ }
196
+
197
+ // Expose model attributes as session attributes, if required.
198
+ // Expose BindingResults for all attributes, making custom editors available.
199
+ Map <String , Object > model = (mavModel != null ? mavModel : implicitModel );
200
+ try {
201
+ for (String attrName : new HashSet <String >(model .keySet ())) {
202
+ Object attrValue = model .get (attrName );
203
+ boolean isSessionAttr =
204
+ this .methodResolver .isSessionAttribute (attrName , (attrValue != null ? attrValue .getClass () : null ));
205
+ if (isSessionAttr && !this .sessionStatus .isComplete ()) {
206
+ this .sessionAttributeStore .storeAttribute (webRequest , attrName , attrValue );
207
+ }
208
+ if (!attrName .startsWith (BindingResult .MODEL_KEY_PREFIX ) &&
209
+ (isSessionAttr || isBindingCandidate (attrValue ))) {
210
+ String bindingResultKey = BindingResult .MODEL_KEY_PREFIX + attrName ;
211
+ if (mavModel != null && !model .containsKey (bindingResultKey )) {
212
+ WebDataBinder binder = createBinder (webRequest , attrValue , attrName );
213
+ initBinder (handler , attrName , binder , webRequest );
214
+ mavModel .put (bindingResultKey , binder .getBindingResult ());
215
+ }
216
+ }
217
+ }
218
+ }
219
+ catch (InvocationTargetException ex ) {
220
+ // User-defined @InitBinder method threw an exception...
221
+ ReflectionUtils .rethrowException (ex .getTargetException ());
222
+ }
223
+ }
224
+
225
+
189
226
private Object [] resolveHandlerArguments (Method handlerMethod , Object handler ,
190
227
NativeWebRequest webRequest , ExtendedModelMap implicitModel ) throws Exception {
191
228
@@ -274,7 +311,7 @@ else if (SessionStatus.class.isAssignableFrom(paramType)) {
274
311
args [i ] = this .sessionStatus ;
275
312
}
276
313
else if (HttpEntity .class .isAssignableFrom (paramType )) {
277
- args [i ] = resolveHttpEntityRequest (methodParam , webRequest , handler );
314
+ args [i ] = resolveHttpEntityRequest (methodParam , webRequest );
278
315
}
279
316
else if (Errors .class .isAssignableFrom (paramType )) {
280
317
throw new IllegalStateException ("Errors/BindingResult argument declared " +
@@ -546,20 +583,22 @@ private Map resolveRequestHeaderMap(Class<? extends Map> mapType, NativeWebReque
546
583
*/
547
584
protected Object resolveRequestBody (MethodParameter methodParam , NativeWebRequest webRequest , Object handler )
548
585
throws Exception {
586
+
549
587
return readWithMessageConverters (methodParam , createHttpInputMessage (webRequest ), methodParam .getParameterType ());
550
588
}
551
589
552
- @ SuppressWarnings ( "unchecked" )
553
- private HttpEntity resolveHttpEntityRequest ( MethodParameter methodParam , NativeWebRequest webRequest , Object handler )
554
- throws Exception {
590
+ private HttpEntity resolveHttpEntityRequest ( MethodParameter methodParam , NativeWebRequest webRequest )
591
+ throws Exception {
592
+
555
593
HttpInputMessage inputMessage = createHttpInputMessage (webRequest );
556
594
Class <?> paramType = getHttpEntityType (methodParam );
557
595
Object body = readWithMessageConverters (methodParam , inputMessage , paramType );
558
- return new HttpEntity (body , inputMessage .getHeaders ());
596
+ return new HttpEntity < Object > (body , inputMessage .getHeaders ());
559
597
}
560
598
561
599
private Object readWithMessageConverters (MethodParameter methodParam , HttpInputMessage inputMessage , Class paramType )
562
- throws Exception {
600
+ throws Exception {
601
+
563
602
MediaType contentType = inputMessage .getHeaders ().getContentType ();
564
603
if (contentType == null ) {
565
604
StringBuilder builder = new StringBuilder (ClassUtils .getShortName (methodParam .getParameterType ()));
@@ -717,43 +756,6 @@ else if (this.methodResolver.isSessionAttribute(name, paramType)) {
717
756
return binder ;
718
757
}
719
758
720
- @ SuppressWarnings ("unchecked" )
721
- public final void updateModelAttributes (Object handler , Map <String , Object > mavModel ,
722
- ExtendedModelMap implicitModel , NativeWebRequest webRequest ) throws Exception {
723
-
724
- if (this .methodResolver .hasSessionAttributes () && this .sessionStatus .isComplete ()) {
725
- for (String attrName : this .methodResolver .getActualSessionAttributeNames ()) {
726
- this .sessionAttributeStore .cleanupAttribute (webRequest , attrName );
727
- }
728
- }
729
-
730
- // Expose model attributes as session attributes, if required.
731
- // Expose BindingResults for all attributes, making custom editors available.
732
- Map <String , Object > model = (mavModel != null ? mavModel : implicitModel );
733
- try {
734
- for (String attrName : new HashSet <String >(model .keySet ())) {
735
- Object attrValue = model .get (attrName );
736
- boolean isSessionAttr =
737
- this .methodResolver .isSessionAttribute (attrName , (attrValue != null ? attrValue .getClass () : null ));
738
- if (isSessionAttr && !this .sessionStatus .isComplete ()) {
739
- this .sessionAttributeStore .storeAttribute (webRequest , attrName , attrValue );
740
- }
741
- if (!attrName .startsWith (BindingResult .MODEL_KEY_PREFIX ) &&
742
- (isSessionAttr || isBindingCandidate (attrValue ))) {
743
- String bindingResultKey = BindingResult .MODEL_KEY_PREFIX + attrName ;
744
- if (mavModel != null && !model .containsKey (bindingResultKey )) {
745
- WebDataBinder binder = createBinder (webRequest , attrValue , attrName );
746
- initBinder (handler , attrName , binder , webRequest );
747
- mavModel .put (bindingResultKey , binder .getBindingResult ());
748
- }
749
- }
750
- }
751
- }
752
- catch (InvocationTargetException ex ) {
753
- // User-defined @InitBinder method threw an exception...
754
- ReflectionUtils .rethrowException (ex .getTargetException ());
755
- }
756
- }
757
759
758
760
/**
759
761
* Determine whether the given value qualifies as a "binding candidate", i.e. might potentially be subject to
0 commit comments