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 ;
@@ -250,15 +249,15 @@ protected boolean isContextRequired() {
250249 return false ;
251250 }
252251
252+
253253 /**
254254 * Convert model to request parameters and redirect to the given URL.
255255 * @see #appendQueryProperties
256256 * @see #sendRedirect
257257 */
258258 @ Override
259- protected void renderMergedOutputModel (
260- Map <String , Object > model , HttpServletRequest request , HttpServletResponse response )
261- throws IOException {
259+ protected void renderMergedOutputModel (Map <String , Object > model , HttpServletRequest request ,
260+ HttpServletResponse response ) throws IOException {
262261
263262 String targetUrl = createTargetUrl (model , request );
264263 targetUrl = updateTargetUrl (targetUrl , model , request , response );
@@ -268,11 +267,13 @@ protected void renderMergedOutputModel(
268267 UriComponents uriComponents = UriComponentsBuilder .fromUriString (targetUrl ).build ();
269268 flashMap .setTargetRequestPath (uriComponents .getPath ());
270269 flashMap .addTargetRequestParams (uriComponents .getQueryParams ());
270+ FlashMapManager flashMapManager = RequestContextUtils .getFlashMapManager (request );
271+ if (flashMapManager == null ) {
272+ throw new IllegalStateException ("FlashMapManager not found despite output FlashMap having been set" );
273+ }
274+ flashMapManager .saveOutputFlashMap (flashMap , request , response );
271275 }
272276
273- FlashMapManager flashMapManager = RequestContextUtils .getFlashMapManager (request );
274- flashMapManager .saveOutputFlashMap (flashMap , request , response );
275-
276277 sendRedirect (request , response , targetUrl , this .http10Compatible );
277278 }
278279
@@ -304,7 +305,6 @@ protected final String createTargetUrl(Map<String, Object> model, HttpServletReq
304305 Map <String , String > variables = getCurrentRequestUriVariables (request );
305306 targetUrl = replaceUriTemplateVariables (targetUrl .toString (), model , variables , enc );
306307 }
307-
308308 if (this .exposeModelAttributes ) {
309309 appendQueryProperties (targetUrl , model , enc );
310310 }
@@ -327,15 +327,17 @@ protected StringBuilder replaceUriTemplateVariables(
327327 throws UnsupportedEncodingException {
328328
329329 StringBuilder result = new StringBuilder ();
330- Matcher m = URI_TEMPLATE_VARIABLE_PATTERN .matcher (targetUrl );
330+ Matcher matcher = URI_TEMPLATE_VARIABLE_PATTERN .matcher (targetUrl );
331331 int endLastMatch = 0 ;
332- while (m .find ()) {
333- String name = m .group (1 );
334- Object value = model .containsKey (name ) ? model .remove (name ) : currentUriVariables .get (name );
335- Assert .notNull (value , "Model has no value for '" + name + "'" );
336- result .append (targetUrl .substring (endLastMatch , m .start ()));
332+ while (matcher .find ()) {
333+ String name = matcher .group (1 );
334+ Object value = (model .containsKey (name ) ? model .remove (name ) : currentUriVariables .get (name ));
335+ if (value == null ) {
336+ throw new IllegalArgumentException ("Model has no value for key '" + name + "'" );
337+ }
338+ result .append (targetUrl .substring (endLastMatch , matcher .start ()));
337339 result .append (UriUtils .encodePathSegment (value .toString (), encodingScheme ));
338- endLastMatch = m .end ();
340+ endLastMatch = matcher .end ();
339341 }
340342 result .append (targetUrl .substring (endLastMatch , targetUrl .length ()));
341343 return result ;
@@ -344,7 +346,7 @@ protected StringBuilder replaceUriTemplateVariables(
344346 @ SuppressWarnings ("unchecked" )
345347 private Map <String , String > getCurrentRequestUriVariables (HttpServletRequest request ) {
346348 Map <String , String > uriVars =
347- (Map <String , String >) request .getAttribute (HandlerMapping .URI_TEMPLATE_VARIABLES_ATTRIBUTE );
349+ (Map <String , String >) request .getAttribute (HandlerMapping .URI_TEMPLATE_VARIABLES_ATTRIBUTE );
348350 return (uriVars != null ) ? uriVars : Collections .<String , String > emptyMap ();
349351 }
350352
@@ -441,7 +443,6 @@ protected boolean isEligibleProperty(String key, Object value) {
441443 if (isEligibleValue (value )) {
442444 return true ;
443445 }
444-
445446 if (value .getClass ().isArray ()) {
446447 int length = Array .getLength (value );
447448 if (length == 0 ) {
@@ -455,7 +456,6 @@ protected boolean isEligibleProperty(String key, Object value) {
455456 }
456457 return true ;
457458 }
458-
459459 if (value instanceof Collection ) {
460460 Collection coll = (Collection ) value ;
461461 if (coll .isEmpty ()) {
@@ -468,7 +468,6 @@ protected boolean isEligibleProperty(String key, Object value) {
468468 }
469469 return true ;
470470 }
471-
472471 return false ;
473472 }
474473
@@ -504,7 +503,7 @@ protected String urlEncode(String input, String encodingScheme) throws Unsupport
504503 * @return the updated URL or the same as URL as the one passed in
505504 */
506505 protected String updateTargetUrl (String targetUrl , Map <String , Object > model ,
507- HttpServletRequest request , HttpServletResponse response ) {
506+ HttpServletRequest request , HttpServletResponse response ) {
508507
509508 RequestContext requestContext = null ;
510509 if (getWebApplicationContext () != null ) {
@@ -516,14 +515,12 @@ protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
516515 requestContext = new RequestContext (request , response , wac .getServletContext (), model );
517516 }
518517 }
519-
520518 if (requestContext != null ) {
521519 RequestDataValueProcessor processor = requestContext .getRequestDataValueProcessor ();
522520 if (processor != null ) {
523521 targetUrl = processor .processUrl (request , targetUrl );
524522 }
525523 }
526-
527524 return targetUrl ;
528525 }
529526
@@ -535,12 +532,10 @@ protected String updateTargetUrl(String targetUrl, Map<String, Object> model,
535532 * @param http10Compatible whether to stay compatible with HTTP 1.0 clients
536533 * @throws IOException if thrown by response methods
537534 */
538- protected void sendRedirect (
539- HttpServletRequest request , HttpServletResponse response , String targetUrl , boolean http10Compatible )
540- throws IOException {
535+ protected void sendRedirect (HttpServletRequest request , HttpServletResponse response ,
536+ String targetUrl , boolean http10Compatible ) throws IOException {
541537
542538 String encodedRedirectURL = response .encodeRedirectURL (targetUrl );
543-
544539 if (http10Compatible ) {
545540 if (this .statusCode != null ) {
546541 response .setStatus (this .statusCode .value ());
0 commit comments