11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3333
3434import org .springframework .beans .BeanUtils ;
3535import org .springframework .http .HttpStatus ;
36- import org .springframework .util .Assert ;
3736import org .springframework .util .CollectionUtils ;
3837import org .springframework .util .ObjectUtils ;
3938import org .springframework .util .StringUtils ;
@@ -251,15 +250,15 @@ protected boolean isContextRequired() {
251250 return false ;
252251 }
253252
253+
254254 /**
255255 * Convert model to request parameters and redirect to the given URL.
256256 * @see #appendQueryProperties
257257 * @see #sendRedirect
258258 */
259259 @ Override
260- protected void renderMergedOutputModel (
261- Map <String , Object > model , HttpServletRequest request , HttpServletResponse response )
262- throws IOException {
260+ protected void renderMergedOutputModel (Map <String , Object > model , HttpServletRequest request ,
261+ HttpServletResponse response ) throws IOException {
263262
264263 String targetUrl = createTargetUrl (model , request );
265264 targetUrl = updateTargetUrl (targetUrl , model , request , response );
@@ -269,11 +268,13 @@ protected void renderMergedOutputModel(
269268 UriComponents uriComponents = UriComponentsBuilder .fromUriString (targetUrl ).build ();
270269 flashMap .setTargetRequestPath (uriComponents .getPath ());
271270 flashMap .addTargetRequestParams (uriComponents .getQueryParams ());
271+ FlashMapManager flashMapManager = RequestContextUtils .getFlashMapManager (request );
272+ if (flashMapManager == null ) {
273+ throw new IllegalStateException ("FlashMapManager not found despite output FlashMap having been set" );
274+ }
275+ flashMapManager .saveOutputFlashMap (flashMap , request , response );
272276 }
273277
274- FlashMapManager flashMapManager = RequestContextUtils .getFlashMapManager (request );
275- flashMapManager .saveOutputFlashMap (flashMap , request , response );
276-
277278 sendRedirect (request , response , targetUrl , this .http10Compatible );
278279 }
279280
@@ -305,7 +306,6 @@ protected final String createTargetUrl(Map<String, Object> model, HttpServletReq
305306 Map <String , String > variables = getCurrentRequestUriVariables (request );
306307 targetUrl = replaceUriTemplateVariables (targetUrl .toString (), model , variables , enc );
307308 }
308-
309309 if (this .exposeModelAttributes ) {
310310 appendQueryProperties (targetUrl , model , enc );
311311 }
@@ -328,15 +328,17 @@ protected StringBuilder replaceUriTemplateVariables(
328328 throws UnsupportedEncodingException {
329329
330330 StringBuilder result = new StringBuilder ();
331- Matcher m = URI_TEMPLATE_VARIABLE_PATTERN .matcher (targetUrl );
331+ Matcher matcher = URI_TEMPLATE_VARIABLE_PATTERN .matcher (targetUrl );
332332 int endLastMatch = 0 ;
333- while (m .find ()) {
334- String name = m .group (1 );
335- Object value = model .containsKey (name ) ? model .remove (name ) : currentUriVariables .get (name );
336- Assert .notNull (value , "Model has no value for '" + name + "'" );
337- result .append (targetUrl .substring (endLastMatch , m .start ()));
333+ while (matcher .find ()) {
334+ String name = matcher .group (1 );
335+ Object value = (model .containsKey (name ) ? model .remove (name ) : currentUriVariables .get (name ));
336+ if (value == null ) {
337+ throw new IllegalArgumentException ("Model has no value for key '" + name + "'" );
338+ }
339+ result .append (targetUrl .substring (endLastMatch , matcher .start ()));
338340 result .append (UriUtils .encodePathSegment (value .toString (), encodingScheme ));
339- endLastMatch = m .end ();
341+ endLastMatch = matcher .end ();
340342 }
341343 result .append (targetUrl .substring (endLastMatch , targetUrl .length ()));
342344 return result ;
@@ -345,7 +347,7 @@ protected StringBuilder replaceUriTemplateVariables(
345347 @ SuppressWarnings ("unchecked" )
346348 private Map <String , String > getCurrentRequestUriVariables (HttpServletRequest request ) {
347349 Map <String , String > uriVars =
348- (Map <String , String >) request .getAttribute (HandlerMapping .URI_TEMPLATE_VARIABLES_ATTRIBUTE );
350+ (Map <String , String >) request .getAttribute (HandlerMapping .URI_TEMPLATE_VARIABLES_ATTRIBUTE );
349351 return (uriVars != null ) ? uriVars : Collections .<String , String > emptyMap ();
350352 }
351353
@@ -442,7 +444,6 @@ protected boolean isEligibleProperty(String key, Object value) {
442444 if (isEligibleValue (value )) {
443445 return true ;
444446 }
445-
446447 if (value .getClass ().isArray ()) {
447448 int length = Array .getLength (value );
448449 if (length == 0 ) {
@@ -456,7 +457,6 @@ protected boolean isEligibleProperty(String key, Object value) {
456457 }
457458 return true ;
458459 }
459-
460460 if (value instanceof Collection ) {
461461 Collection coll = (Collection ) value ;
462462 if (coll .isEmpty ()) {
@@ -469,7 +469,6 @@ protected boolean isEligibleProperty(String key, Object value) {
469469 }
470470 return true ;
471471 }
472-
473472 return false ;
474473 }
475474
@@ -505,7 +504,7 @@ protected String urlEncode(String input, String encodingScheme) throws Unsupport
505504 * @return the updated URL or the same as URL as the one passed in
506505 */
507506 protected String updateTargetUrl (String targetUrl , Map <String , Object > model ,
508- HttpServletRequest request , HttpServletResponse response ) {
507+ HttpServletRequest request , HttpServletResponse response ) {
509508
510509 RequestContext requestContext = null ;
511510 if (getWebApplicationContext () != null ) {
@@ -517,14 +516,12 @@ protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
517516 requestContext = new RequestContext (request , response , wac .getServletContext (), model );
518517 }
519518 }
520-
521519 if (requestContext != null ) {
522520 RequestDataValueProcessor processor = requestContext .getRequestDataValueProcessor ();
523521 if (processor != null ) {
524522 targetUrl = processor .processUrl (request , targetUrl );
525523 }
526524 }
527-
528525 return targetUrl ;
529526 }
530527
@@ -536,12 +533,10 @@ protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
536533 * @param http10Compatible whether to stay compatible with HTTP 1.0 clients
537534 * @throws IOException if thrown by response methods
538535 */
539- protected void sendRedirect (
540- HttpServletRequest request , HttpServletResponse response , String targetUrl , boolean http10Compatible )
541- throws IOException {
536+ protected void sendRedirect (HttpServletRequest request , HttpServletResponse response ,
537+ String targetUrl , boolean http10Compatible ) throws IOException {
542538
543539 String encodedRedirectURL = response .encodeRedirectURL (targetUrl );
544-
545540 if (http10Compatible ) {
546541 if (this .statusCode != null ) {
547542 response .setStatus (this .statusCode .value ());
0 commit comments