Browse Source
Conflicts: spring-webmvc/src/main/java/org/springframework/web/servlet/support/DefaultFlashMapManager.java spring-webmvc/src/test/java/org/springframework/web/servlet/support/DefaultFlashMapManagerTests.javapull/37/head
16 changed files with 684 additions and 663 deletions
@ -0,0 +1,221 @@
@@ -0,0 +1,221 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.support; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.concurrent.CopyOnWriteArrayList; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.util.MultiValueMap; |
||||
import org.springframework.util.ObjectUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.servlet.FlashMap; |
||||
import org.springframework.web.servlet.FlashMapManager; |
||||
import org.springframework.web.util.UrlPathHelper; |
||||
|
||||
/** |
||||
* A base class for {@link FlashMapManager} implementations. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 3.1.1 |
||||
*/ |
||||
public abstract class AbstractFlashMapManager implements FlashMapManager { |
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass()); |
||||
|
||||
private int flashMapTimeout = 180; |
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper(); |
||||
|
||||
/** |
||||
* Set the amount of time in seconds after a {@link FlashMap} is saved |
||||
* (at request completion) and before it expires. |
||||
* <p>The default value is 180 seconds. |
||||
*/ |
||||
public void setFlashMapTimeout(int flashMapTimeout) { |
||||
this.flashMapTimeout = flashMapTimeout; |
||||
} |
||||
|
||||
/** |
||||
* Return the amount of time in seconds before a FlashMap expires. |
||||
*/ |
||||
public int getFlashMapTimeout() { |
||||
return this.flashMapTimeout; |
||||
} |
||||
|
||||
/** |
||||
* Set the UrlPathHelper to use to match FlashMap instances to requests. |
||||
*/ |
||||
public void setUrlPathHelper(UrlPathHelper urlPathHelper) { |
||||
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); |
||||
this.urlPathHelper = urlPathHelper; |
||||
} |
||||
|
||||
/** |
||||
* Return the UrlPathHelper implementation to use. |
||||
*/ |
||||
public UrlPathHelper getUrlPathHelper() { |
||||
return this.urlPathHelper; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
* <p>Does not cause an HTTP session to be created. |
||||
*/ |
||||
public final Map<String, ?> getFlashMapForRequest(HttpServletRequest request) { |
||||
List<FlashMap> flashMaps = retrieveFlashMaps(request); |
||||
if (CollectionUtils.isEmpty(flashMaps)) { |
||||
return null; |
||||
} |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Retrieved FlashMap(s): " + flashMaps); |
||||
} |
||||
List<FlashMap> result = new ArrayList<FlashMap>(); |
||||
for (FlashMap flashMap : flashMaps) { |
||||
if (isFlashMapForRequest(flashMap, request)) { |
||||
result.add(flashMap); |
||||
} |
||||
} |
||||
if (!result.isEmpty()) { |
||||
Collections.sort(result); |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Found matching FlashMap(s): " + result); |
||||
} |
||||
FlashMap match = result.remove(0); |
||||
flashMaps.remove(match); |
||||
return Collections.unmodifiableMap(match); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Retrieve saved FlashMap instances from underlying storage. |
||||
* @param request the current request |
||||
* @return a List with FlashMap instances or {@code null} |
||||
*/ |
||||
protected abstract List<FlashMap> retrieveFlashMaps(HttpServletRequest request); |
||||
|
||||
/** |
||||
* Whether the given FlashMap matches the current request. |
||||
* The default implementation uses the target request path and query params |
||||
* saved in the FlashMap. |
||||
*/ |
||||
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) { |
||||
if (flashMap.getTargetRequestPath() != null) { |
||||
String requestUri = this.urlPathHelper.getOriginatingRequestUri(request); |
||||
if (!requestUri.equals(flashMap.getTargetRequestPath()) |
||||
&& !requestUri.equals(flashMap.getTargetRequestPath() + "/")) { |
||||
return false; |
||||
} |
||||
} |
||||
MultiValueMap<String, String> targetParams = flashMap.getTargetRequestParams(); |
||||
for (String paramName : targetParams.keySet()) { |
||||
for (String targetValue : targetParams.get(paramName)) { |
||||
if (!ObjectUtils.containsElement(request.getParameterValues(paramName), targetValue)) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
* <p>The FlashMap, if not empty, is saved to the HTTP session. |
||||
*/ |
||||
public final void save(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) { |
||||
Assert.notNull(flashMap, "FlashMap must not be null"); |
||||
|
||||
List<FlashMap> flashMaps = retrieveFlashMaps(request); |
||||
if (flashMap.isEmpty() && (flashMaps == null)) { |
||||
return; |
||||
} |
||||
synchronized (this) { |
||||
boolean update = false; |
||||
flashMaps = retrieveFlashMaps(request); |
||||
if (!CollectionUtils.isEmpty(flashMaps)) { |
||||
update = removeExpired(flashMaps); |
||||
} |
||||
if (!flashMap.isEmpty()) { |
||||
String path = decodeAndNormalizePath(flashMap.getTargetRequestPath(), request); |
||||
flashMap.setTargetRequestPath(path); |
||||
flashMap.startExpirationPeriod(this.flashMapTimeout); |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Saving FlashMap=" + flashMap); |
||||
} |
||||
flashMaps = (flashMaps == null) ? new CopyOnWriteArrayList<FlashMap>() : flashMaps; |
||||
flashMaps.add(flashMap); |
||||
update = true; |
||||
} |
||||
if (update) { |
||||
updateFlashMaps(flashMaps, request, response); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private String decodeAndNormalizePath(String path, HttpServletRequest request) { |
||||
if (path != null) { |
||||
path = this.urlPathHelper.decodeRequestString(request, path); |
||||
if (path.charAt(0) != '/') { |
||||
String requestUri = this.urlPathHelper.getRequestUri(request); |
||||
path = requestUri.substring(0, requestUri.lastIndexOf('/') + 1) + path; |
||||
path = StringUtils.cleanPath(path); |
||||
} |
||||
} |
||||
return path; |
||||
} |
||||
|
||||
/** |
||||
* Update the FlashMap instances in some underlying storage. |
||||
* @param flashMaps a non-empty list of FlashMap instances to save |
||||
* @param request the current request |
||||
* @param response the current response |
||||
*/ |
||||
protected abstract void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, |
||||
HttpServletResponse response); |
||||
|
||||
/** |
||||
* Remove expired FlashMap instances from the given List. |
||||
*/ |
||||
protected boolean removeExpired(List<FlashMap> flashMaps) { |
||||
List<FlashMap> expired = new ArrayList<FlashMap>(); |
||||
for (FlashMap flashMap : flashMaps) { |
||||
if (flashMap.isExpired()) { |
||||
if (logger.isTraceEnabled()) { |
||||
logger.trace("Removing expired FlashMap: " + flashMap); |
||||
} |
||||
expired.add(flashMap); |
||||
} |
||||
} |
||||
if (expired.isEmpty()) { |
||||
return false; |
||||
} |
||||
else { |
||||
return flashMaps.removeAll(expired); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,266 +0,0 @@
@@ -1,266 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.support; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.concurrent.CopyOnWriteArrayList; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
import org.springframework.util.Assert; |
||||
import org.springframework.util.CollectionUtils; |
||||
import org.springframework.util.MultiValueMap; |
||||
import org.springframework.util.ObjectUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.servlet.FlashMap; |
||||
import org.springframework.web.servlet.FlashMapManager; |
||||
import org.springframework.web.util.UrlPathHelper; |
||||
|
||||
/** |
||||
* A default {@link FlashMapManager} implementation that stores {@link FlashMap} |
||||
* instances in the HTTP session. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 3.1 |
||||
*/ |
||||
public class DefaultFlashMapManager implements FlashMapManager { |
||||
|
||||
private static final String FLASH_MAPS_SESSION_ATTRIBUTE = DefaultFlashMapManager.class.getName() + ".FLASH_MAPS"; |
||||
|
||||
private static final Log logger = LogFactory.getLog(DefaultFlashMapManager.class); |
||||
|
||||
private int flashMapTimeout = 180; |
||||
|
||||
private UrlPathHelper urlPathHelper = new UrlPathHelper(); |
||||
|
||||
/** |
||||
* Set the amount of time in seconds after a {@link FlashMap} is saved |
||||
* (at request completion) and before it expires. |
||||
* <p>The default value is 180 seconds. |
||||
*/ |
||||
public void setFlashMapTimeout(int flashMapTimeout) { |
||||
this.flashMapTimeout = flashMapTimeout; |
||||
} |
||||
|
||||
/** |
||||
* Return the amount of time in seconds before a FlashMap expires. |
||||
*/ |
||||
public int getFlashMapTimeout() { |
||||
return flashMapTimeout; |
||||
} |
||||
|
||||
/** |
||||
* Set the UrlPathHelper to use to obtain the request URI. |
||||
*/ |
||||
public void setUrlPathHelper(UrlPathHelper urlPathHelper) { |
||||
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); |
||||
this.urlPathHelper = urlPathHelper; |
||||
} |
||||
|
||||
/** |
||||
* Return the UrlPathHelper implementation for the request URI. |
||||
*/ |
||||
public UrlPathHelper getUrlPathHelper() { |
||||
return urlPathHelper; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
* <p>An HTTP session is never created by this method. |
||||
*/ |
||||
public final void requestStarted(HttpServletRequest request, HttpServletResponse response) { |
||||
if (request.getAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE) != null) { |
||||
return; |
||||
} |
||||
|
||||
FlashMap inputFlashMap = lookupFlashMap(request); |
||||
if (inputFlashMap != null) { |
||||
request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap)); |
||||
} |
||||
|
||||
FlashMap outputFlashMap = new FlashMap(this.hashCode()); |
||||
request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, outputFlashMap); |
||||
|
||||
removeExpiredFlashMaps(request); |
||||
} |
||||
|
||||
/** |
||||
* Find the "input" FlashMap for the current request target by matching it |
||||
* to the target request information of all stored FlashMap instances. |
||||
* @return a FlashMap instance or {@code null} |
||||
*/ |
||||
private FlashMap lookupFlashMap(HttpServletRequest request) { |
||||
List<FlashMap> allFlashMaps = retrieveFlashMaps(request, false); |
||||
if (CollectionUtils.isEmpty(allFlashMaps)) { |
||||
return null; |
||||
} |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Retrieved FlashMap(s): " + allFlashMaps); |
||||
} |
||||
List<FlashMap> result = new ArrayList<FlashMap>(); |
||||
for (FlashMap flashMap : allFlashMaps) { |
||||
if (isFlashMapForRequest(flashMap, request)) { |
||||
result.add(flashMap); |
||||
} |
||||
} |
||||
if (!result.isEmpty()) { |
||||
Collections.sort(result); |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Found matching FlashMap(s): " + result); |
||||
} |
||||
FlashMap match = result.remove(0); |
||||
allFlashMaps.remove(match); |
||||
return match; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Whether the given FlashMap matches the current request. |
||||
* The default implementation uses the target request path and query params |
||||
* saved in the FlashMap. |
||||
*/ |
||||
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) { |
||||
if (flashMap.getTargetRequestPath() != null) { |
||||
String requestUri = this.urlPathHelper.getOriginatingRequestUri(request); |
||||
if (!requestUri.equals(flashMap.getTargetRequestPath()) |
||||
&& !requestUri.equals(flashMap.getTargetRequestPath() + "/")) { |
||||
return false; |
||||
} |
||||
} |
||||
MultiValueMap<String, String> targetParams = flashMap.getTargetRequestParams(); |
||||
for (String paramName : targetParams.keySet()) { |
||||
for (String targetValue : targetParams.get(paramName)) { |
||||
if (!ObjectUtils.containsElement(request.getParameterValues(paramName), targetValue)) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Retrieve all FlashMap instances from the current HTTP session. |
||||
* If {@code allowCreate} is "true" and no flash maps exist yet, a new list |
||||
* is created and stored as a session attribute. |
||||
* @param request the current request |
||||
* @param allowCreate whether to create the session if necessary |
||||
* @return a List to add FlashMap instances to or {@code null} |
||||
* assuming {@code allowCreate} is "false". |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request, boolean allowCreate) { |
||||
HttpSession session = request.getSession(allowCreate); |
||||
if (session == null) { |
||||
return null; |
||||
} |
||||
List<FlashMap> allFlashMaps = (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE); |
||||
if (allFlashMaps == null && allowCreate) { |
||||
synchronized (this) { |
||||
allFlashMaps = (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE); |
||||
if (allFlashMaps == null) { |
||||
allFlashMaps = new CopyOnWriteArrayList<FlashMap>(); |
||||
session.setAttribute(FLASH_MAPS_SESSION_ATTRIBUTE, allFlashMaps); |
||||
} |
||||
} |
||||
} |
||||
return allFlashMaps; |
||||
} |
||||
|
||||
/** |
||||
* Check and remove expired FlashMaps instances. |
||||
*/ |
||||
protected void removeExpiredFlashMaps(HttpServletRequest request) { |
||||
List<FlashMap> allMaps = retrieveFlashMaps(request, false); |
||||
if (CollectionUtils.isEmpty(allMaps)) { |
||||
return; |
||||
} |
||||
List<FlashMap> expiredMaps = new ArrayList<FlashMap>(); |
||||
for (FlashMap flashMap : allMaps) { |
||||
if (flashMap.isExpired()) { |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Removing expired FlashMap: " + flashMap); |
||||
} |
||||
expiredMaps.add(flashMap); |
||||
} |
||||
} |
||||
if (!expiredMaps.isEmpty()) { |
||||
allMaps.removeAll(expiredMaps); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
* <p>An HTTP session is never created if the "output" FlashMap is empty. |
||||
*/ |
||||
public void requestCompleted(HttpServletRequest request, HttpServletResponse response) { |
||||
FlashMap flashMap = (FlashMap) request.getAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE); |
||||
if (flashMap == null) { |
||||
throw new IllegalStateException("requestCompleted called but \"output\" FlashMap was never created"); |
||||
} |
||||
if (!flashMap.isEmpty() && flashMap.isCreatedBy(this.hashCode())) { |
||||
if (logger.isDebugEnabled()) { |
||||
logger.debug("Saving FlashMap=" + flashMap); |
||||
} |
||||
onSaveFlashMap(flashMap, request, response); |
||||
saveFlashMap(flashMap, request, response); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Update a FlashMap before it is stored in the underlying storage. |
||||
* <p>The default implementation starts the expiration period and ensures the |
||||
* target request path is decoded and normalized if it is relative. |
||||
* @param flashMap the flash map to be saved |
||||
* @param request the current request |
||||
* @param response the current response |
||||
*/ |
||||
protected void onSaveFlashMap(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) { |
||||
String targetPath = flashMap.getTargetRequestPath(); |
||||
flashMap.setTargetRequestPath(decodeAndNormalizePath(targetPath, request)); |
||||
flashMap.startExpirationPeriod(this.flashMapTimeout); |
||||
} |
||||
|
||||
/** |
||||
* Save the FlashMap in the underlying storage. |
||||
* @param flashMap the FlashMap to save |
||||
* @param request the current request |
||||
* @param response the current response |
||||
*/ |
||||
protected void saveFlashMap(FlashMap flashMap, HttpServletRequest request, HttpServletResponse response) { |
||||
retrieveFlashMaps(request, true).add(flashMap); |
||||
} |
||||
|
||||
private String decodeAndNormalizePath(String path, HttpServletRequest request) { |
||||
if (path != null) { |
||||
path = this.urlPathHelper.decodeRequestString(request, path); |
||||
if (path.charAt(0) != '/') { |
||||
String requestUri = this.urlPathHelper.getRequestUri(request); |
||||
path = requestUri.substring(0, requestUri.lastIndexOf('/') + 1) + path; |
||||
path = StringUtils.cleanPath(path); |
||||
} |
||||
} |
||||
return path; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.support; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
import org.springframework.web.servlet.FlashMap; |
||||
|
||||
/** |
||||
* Stores {@link FlashMap} instances in the HTTP session. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 3.1.1 |
||||
*/ |
||||
public class SessionFlashMapManager extends AbstractFlashMapManager{ |
||||
|
||||
private static final String FLASH_MAPS_SESSION_ATTRIBUTE = SessionFlashMapManager.class.getName() + ".FLASH_MAPS"; |
||||
|
||||
/** |
||||
* Retrieve saved FlashMap instances from the HTTP session. |
||||
* @param request the current request |
||||
* @return a List with FlashMap instances or {@code null} |
||||
*/ |
||||
@SuppressWarnings("unchecked") |
||||
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) { |
||||
HttpSession session = request.getSession(false); |
||||
return (session != null) ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null; |
||||
} |
||||
|
||||
/** |
||||
* Save the given FlashMap instances in the HTTP session. |
||||
*/ |
||||
protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, HttpServletResponse response) { |
||||
request.getSession().setAttribute(FLASH_MAPS_SESSION_ATTRIBUTE, flashMaps); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,297 @@
@@ -0,0 +1,297 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.support; |
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.concurrent.CopyOnWriteArrayList; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpServletResponse; |
||||
import org.springframework.web.servlet.FlashMap; |
||||
import org.springframework.web.util.WebUtils; |
||||
|
||||
/** |
||||
* Test fixture for testing {@link AbstractFlashMapManager} methods. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
*/ |
||||
public class AbstractFlashMapManagerTests { |
||||
|
||||
private TestFlashMapManager flashMapManager; |
||||
|
||||
private MockHttpServletRequest request; |
||||
|
||||
private MockHttpServletResponse response; |
||||
|
||||
@Before |
||||
public void setup() { |
||||
this.flashMapManager = new TestFlashMapManager(); |
||||
this.request = new MockHttpServletRequest(); |
||||
this.response = new MockHttpServletResponse(); |
||||
} |
||||
|
||||
@Test |
||||
public void getFlashMapForRequestByPath() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/path"); |
||||
|
||||
this.flashMapManager.setFlashMaps(flashMap); |
||||
|
||||
this.request.setRequestURI("/path"); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMap, inputFlashMap); |
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
// SPR-8779
|
||||
|
||||
@Test |
||||
public void getFlashMapForRequestByOriginatingPath() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/accounts"); |
||||
|
||||
this.flashMapManager.setFlashMaps(flashMap); |
||||
|
||||
this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts"); |
||||
this.request.setRequestURI("/mvc/accounts"); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMap, inputFlashMap); |
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getFlashMapForRequestByPathWithTrailingSlash() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/path"); |
||||
|
||||
this.flashMapManager.setFlashMaps(flashMap); |
||||
|
||||
this.request.setRequestURI("/path/"); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMap, inputFlashMap); |
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getFlashMapForRequestWithParams() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.addTargetRequestParam("number", "one"); |
||||
|
||||
this.flashMapManager.setFlashMaps(flashMap); |
||||
|
||||
this.request.setParameter("number", (String) null); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertNull(inputFlashMap); |
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size()); |
||||
|
||||
this.request.setParameter("number", "two"); |
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertNull(inputFlashMap); |
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size()); |
||||
|
||||
this.request.setParameter("number", "one"); |
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMap, inputFlashMap); |
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
// SPR-8798
|
||||
|
||||
@Test |
||||
public void getFlashMapForRequestWithMultiValueParam() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("name", "value"); |
||||
flashMap.addTargetRequestParam("id", "1"); |
||||
flashMap.addTargetRequestParam("id", "2"); |
||||
|
||||
this.flashMapManager.setFlashMaps(flashMap); |
||||
|
||||
this.request.setParameter("id", "1"); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertNull(inputFlashMap); |
||||
assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size()); |
||||
|
||||
this.request.addParameter("id", "2"); |
||||
inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMap, inputFlashMap); |
||||
assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void getFlashMapForRequestSortOrder() { |
||||
FlashMap emptyFlashMap = new FlashMap(); |
||||
|
||||
FlashMap flashMapOne = new FlashMap(); |
||||
flashMapOne.put("key1", "value1"); |
||||
flashMapOne.setTargetRequestPath("/one"); |
||||
|
||||
FlashMap flashMapTwo = new FlashMap(); |
||||
flashMapTwo.put("key1", "value1"); |
||||
flashMapTwo.put("key2", "value2"); |
||||
flashMapTwo.setTargetRequestPath("/one/two"); |
||||
|
||||
this.flashMapManager.setFlashMaps(emptyFlashMap, flashMapOne, flashMapTwo); |
||||
|
||||
this.request.setRequestURI("/one/two"); |
||||
Map<String, ?> inputFlashMap = this.flashMapManager.getFlashMapForRequest(this.request); |
||||
|
||||
assertEquals(flashMapTwo, inputFlashMap); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapEmpty() throws InterruptedException { |
||||
FlashMap flashMap = new FlashMap(); |
||||
|
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
List<FlashMap> allMaps = this.flashMapManager.getFlashMaps(); |
||||
|
||||
assertNull(allMaps); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMap() throws InterruptedException { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("name", "value"); |
||||
|
||||
this.flashMapManager.setFlashMapTimeout(-1); // expire immediately so we can check expiration started
|
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
List<FlashMap> allMaps = this.flashMapManager.getFlashMaps(); |
||||
|
||||
assertNotNull(allMaps); |
||||
assertSame(flashMap, allMaps.get(0)); |
||||
assertTrue(flashMap.isExpired()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapDecodeTargetPath() throws InterruptedException { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
|
||||
flashMap.setTargetRequestPath("/once%20upon%20a%20time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once upon a time", flashMap.getTargetRequestPath()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapNormalizeTargetPath() throws InterruptedException { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
|
||||
flashMap.setTargetRequestPath("."); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/a", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("./"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/a/", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath(".."); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once/upon", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("../"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("../../only"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.save(flashMap, this.request, this.response); |
||||
|
||||
assertEquals("/once/only", flashMap.getTargetRequestPath()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapAndRemoveExpired() throws InterruptedException { |
||||
List<FlashMap> flashMaps = new ArrayList<FlashMap>(); |
||||
for (int i=0; i < 5; i++) { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.startExpirationPeriod(-1); |
||||
flashMaps.add(flashMap); |
||||
} |
||||
this.flashMapManager.setFlashMaps(flashMaps); |
||||
this.flashMapManager.save(new FlashMap(), request, response); |
||||
|
||||
assertEquals("Expired instances should be removed even if the saved FlashMap is empty", |
||||
0, this.flashMapManager.getFlashMaps().size()); |
||||
} |
||||
|
||||
|
||||
private static class TestFlashMapManager extends AbstractFlashMapManager { |
||||
|
||||
private List<FlashMap> flashMaps; |
||||
|
||||
public List<FlashMap> getFlashMaps() { |
||||
return this.flashMaps; |
||||
} |
||||
|
||||
public void setFlashMaps(FlashMap... flashMaps) { |
||||
setFlashMaps(Arrays.asList(flashMaps)); |
||||
} |
||||
|
||||
public void setFlashMaps(List<FlashMap> flashMaps) { |
||||
this.flashMaps = new CopyOnWriteArrayList<FlashMap>(flashMaps); |
||||
} |
||||
|
||||
@Override |
||||
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) { |
||||
return this.flashMaps; |
||||
} |
||||
|
||||
@Override |
||||
protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest request, |
||||
HttpServletResponse response) { |
||||
this.flashMaps = flashMaps; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,322 +0,0 @@
@@ -1,322 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2011 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.servlet.support; |
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
import static org.junit.Assert.assertSame; |
||||
import static org.junit.Assert.assertTrue; |
||||
import static org.springframework.web.servlet.FlashMapManager.INPUT_FLASH_MAP_ATTRIBUTE; |
||||
import static org.springframework.web.servlet.FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.concurrent.CopyOnWriteArrayList; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpServletResponse; |
||||
import org.springframework.web.servlet.FlashMap; |
||||
import org.springframework.web.util.WebUtils; |
||||
|
||||
/** |
||||
* Test fixture for {@link DefaultFlashMapManager} tests. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
*/ |
||||
public class DefaultFlashMapManagerTests { |
||||
|
||||
private DefaultFlashMapManager flashMapManager; |
||||
|
||||
private MockHttpServletRequest request; |
||||
|
||||
private MockHttpServletResponse response; |
||||
|
||||
@Before |
||||
public void setup() { |
||||
this.flashMapManager = new DefaultFlashMapManager(); |
||||
this.request = new MockHttpServletRequest(); |
||||
this.response = new MockHttpServletResponse(); |
||||
} |
||||
|
||||
@Test |
||||
public void requestStarted() { |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); |
||||
|
||||
assertNotNull("Current FlashMap not found", flashMap); |
||||
} |
||||
|
||||
@Test |
||||
public void requestStartedAlready() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
this.request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertSame(flashMap, RequestContextUtils.getOutputFlashMap(request)); |
||||
} |
||||
|
||||
@Test |
||||
public void lookupFlashMapByPath() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/path"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(flashMap); |
||||
|
||||
this.request.setRequestURI("/path"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); |
||||
} |
||||
|
||||
// SPR-8779
|
||||
|
||||
@Test |
||||
public void lookupFlashMapByOriginatingPath() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/accounts"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(flashMap); |
||||
|
||||
this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts"); |
||||
this.request.setRequestURI("/mvc/accounts"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void lookupFlashMapByPathWithTrailingSlash() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.setTargetRequestPath("/path"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(flashMap); |
||||
|
||||
this.request.setRequestURI("/path/"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void lookupFlashMapWithParams() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("key", "value"); |
||||
flashMap.addTargetRequestParam("number", "one"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(flashMap); |
||||
|
||||
this.request.setParameter("number", (String) null); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertNull(RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); |
||||
|
||||
clearFlashMapRequestAttributes(); |
||||
this.request.setParameter("number", "two"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertNull(RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); |
||||
|
||||
clearFlashMapRequestAttributes(); |
||||
this.request.setParameter("number", "one"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); |
||||
} |
||||
|
||||
// SPR-8798
|
||||
|
||||
@Test |
||||
public void lookupFlashMapWithMultiValueParam() { |
||||
FlashMap flashMap = new FlashMap(); |
||||
flashMap.put("name", "value"); |
||||
flashMap.addTargetRequestParam("id", "1"); |
||||
flashMap.addTargetRequestParam("id", "2"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(flashMap); |
||||
|
||||
this.request.setParameter("id", "1"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertNull(RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("FlashMap should not have been removed", 1, getFlashMaps().size()); |
||||
|
||||
clearFlashMapRequestAttributes(); |
||||
this.request.addParameter("id", "2"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMap, RequestContextUtils.getInputFlashMap(this.request)); |
||||
assertEquals("Input FlashMap should have been removed", 0, getFlashMaps().size()); |
||||
} |
||||
|
||||
@Test |
||||
public void lookupFlashMapSortOrder() { |
||||
FlashMap emptyFlashMap = new FlashMap(); |
||||
|
||||
FlashMap flashMapOne = new FlashMap(); |
||||
flashMapOne.put("key1", "value1"); |
||||
flashMapOne.setTargetRequestPath("/one"); |
||||
|
||||
FlashMap flashMapTwo = new FlashMap(); |
||||
flashMapTwo.put("key1", "value1"); |
||||
flashMapTwo.put("key2", "value2"); |
||||
flashMapTwo.setTargetRequestPath("/one/two"); |
||||
|
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
allMaps.add(emptyFlashMap); |
||||
allMaps.add(flashMapOne); |
||||
allMaps.add(flashMapTwo); |
||||
Collections.shuffle(allMaps); |
||||
|
||||
this.request.setRequestURI("/one/two"); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(flashMapTwo, request.getAttribute(INPUT_FLASH_MAP_ATTRIBUTE)); |
||||
} |
||||
|
||||
@Test |
||||
public void removeExpiredFlashMaps() throws InterruptedException { |
||||
List<FlashMap> allMaps = createFlashMaps(); |
||||
for (int i=0; i < 5; i++) { |
||||
FlashMap flashMap = new FlashMap(); |
||||
allMaps.add(flashMap); |
||||
flashMap.startExpirationPeriod(0); |
||||
} |
||||
Thread.sleep(100); |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
|
||||
assertEquals(0, allMaps.size()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapWithoutAttributes() throws InterruptedException { |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertNull(getFlashMaps()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapNotCreatedByThisManager() throws InterruptedException { |
||||
FlashMap flashMap = new FlashMap(); |
||||
this.request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertNull(getFlashMaps()); |
||||
} |
||||
|
||||
@Test |
||||
public void saveFlashMapWithAttributes() throws InterruptedException { |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(this.request); |
||||
flashMap.put("name", "value"); |
||||
|
||||
this.flashMapManager.setFlashMapTimeout(0); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
Thread.sleep(100); |
||||
|
||||
List<FlashMap> allMaps = getFlashMaps(); |
||||
|
||||
assertNotNull(allMaps); |
||||
assertSame(flashMap, allMaps.get(0)); |
||||
assertTrue(flashMap.isExpired()); |
||||
} |
||||
|
||||
@Test |
||||
public void decodeTargetPath() throws InterruptedException { |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(this.request); |
||||
flashMap.put("key", "value"); |
||||
|
||||
flashMap.setTargetRequestPath("/once%20upon%20a%20time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once upon a time", flashMap.getTargetRequestPath()); |
||||
} |
||||
|
||||
@Test |
||||
public void normalizeTargetPath() throws InterruptedException { |
||||
this.flashMapManager.requestStarted(this.request, this.response); |
||||
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(this.request); |
||||
flashMap.put("key", "value"); |
||||
|
||||
flashMap.setTargetRequestPath("."); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/a", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("./"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/a/", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath(".."); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once/upon", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("../"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once/upon/", flashMap.getTargetRequestPath()); |
||||
|
||||
flashMap.setTargetRequestPath("../../only"); |
||||
this.request.setRequestURI("/once/upon/a/time"); |
||||
this.flashMapManager.requestCompleted(this.request, this.response); |
||||
|
||||
assertEquals("/once/only", flashMap.getTargetRequestPath()); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
private List<FlashMap> getFlashMaps() { |
||||
return (List<FlashMap>) this.request.getSession().getAttribute(DefaultFlashMapManager.class.getName() + ".FLASH_MAPS"); |
||||
} |
||||
|
||||
private List<FlashMap> createFlashMaps() { |
||||
List<FlashMap> allMaps = new CopyOnWriteArrayList<FlashMap>(); |
||||
this.request.getSession().setAttribute(DefaultFlashMapManager.class.getName() + ".FLASH_MAPS", allMaps); |
||||
return allMaps; |
||||
} |
||||
|
||||
private void clearFlashMapRequestAttributes() { |
||||
request.removeAttribute(INPUT_FLASH_MAP_ATTRIBUTE); |
||||
request.removeAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue