use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.
the class RequestContextUtils method saveOutputFlashMap.
/**
* Convenience method that retrieves the {@link #getOutputFlashMap "output"
* FlashMap}, updates it with the path and query params of the target URL,
* and then saves it using the {@link #getFlashMapManager FlashMapManager}.
* @param location the target URL for the redirect
* @param request the current request
* @param response the current response
* @since 5.0
*/
public static void saveOutputFlashMap(String location, HttpServletRequest request, HttpServletResponse response) {
FlashMap flashMap = getOutputFlashMap(request);
if (CollectionUtils.isEmpty(flashMap)) {
return;
}
UriComponents uriComponents = UriComponentsBuilder.fromUriString(location).build();
flashMap.setTargetRequestPath(uriComponents.getPath());
flashMap.addTargetRequestParams(uriComponents.getQueryParams());
FlashMapManager manager = getFlashMapManager(request);
Assert.state(manager != null, "No FlashMapManager. Is this a DispatcherServlet handled request?");
manager.saveOutputFlashMap(flashMap, request, response);
}
use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.
the class FlashMapManagerTests method retrieveAndUpdateMatchByParams.
@Test
public void retrieveAndUpdateMatchByParams() {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.addTargetRequestParam("number", "one");
this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));
this.request.setQueryString("number=");
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
assertThatFlashMap(inputFlashMap).isNull();
assertThat(this.flashMapManager.getFlashMaps().size()).as("FlashMap should not have been removed").isEqualTo(1);
this.request.setQueryString("number=two");
inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
assertThatFlashMap(inputFlashMap).isNull();
assertThat(this.flashMapManager.getFlashMaps().size()).as("FlashMap should not have been removed").isEqualTo(1);
this.request.setQueryString("number=one");
inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
assertThatFlashMap(inputFlashMap).isEqualTo(flashMap);
assertThat(this.flashMapManager.getFlashMaps().size()).as("Input FlashMap should have been removed").isEqualTo(0);
}
use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.
the class FlashMapManagerTests method saveOutputFlashMapNormalizeTargetPath.
@Test
public void saveOutputFlashMapNormalizeTargetPath() {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.setTargetRequestPath(".");
this.request.setRequestURI("/once/upon/a/time");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/upon/a");
flashMap.setTargetRequestPath("./");
this.request.setRequestURI("/once/upon/a/time");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/upon/a/");
flashMap.setTargetRequestPath("..");
this.request.setRequestURI("/once/upon/a/time");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/upon");
flashMap.setTargetRequestPath("../");
this.request.setRequestURI("/once/upon/a/time");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/upon/");
flashMap.setTargetRequestPath("../../only");
this.request.setRequestURI("/once/upon/a/time");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/only");
}
use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.
the class FlashMapManagerTests method retrieveAndUpdateMatchByOriginatingPath.
// SPR-8779
@Test
public void retrieveAndUpdateMatchByOriginatingPath() {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.setTargetRequestPath("/accounts");
this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));
this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts");
this.request.setRequestURI("/mvc/accounts");
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
assertThatFlashMap(inputFlashMap).isEqualTo(flashMap);
assertThat(this.flashMapManager.getFlashMaps().size()).as("Input FlashMap should have been removed").isEqualTo(0);
}
use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.
the class FlashMapManagerTests method retrieveAndUpdateSortMultipleMatches.
@Test
public void retrieveAndUpdateSortMultipleMatches() {
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(Arrays.asList(emptyFlashMap, flashMapOne, flashMapTwo));
this.request.setRequestURI("/one/two");
FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
assertThatFlashMap(inputFlashMap).isEqualTo(flashMapTwo);
assertThat(this.flashMapManager.getFlashMaps().size()).as("Input FlashMap should have been removed").isEqualTo(2);
}
Aggregations