Java Code Examples for org.springframework.web.servlet.FlashMap#setTargetRequestPath()
The following examples show how to use
org.springframework.web.servlet.FlashMap#setTargetRequestPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void saveOutputFlashMapDecodeParameters() throws Exception { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); flashMap.addTargetRequestParam("param", "%D0%90%D0%90"); flashMap.addTargetRequestParam("param", "%D0%91%D0%91"); flashMap.addTargetRequestParam("param", "%D0%92%D0%92"); flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value"); this.request.setCharacterEncoding("UTF-8"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path"); requestAfterRedirect.setQueryString("param=%D0%90%D0%90¶m=%D0%91%D0%91¶m=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value"); requestAfterRedirect.addParameter("param", "\u0410\u0410"); requestAfterRedirect.addParameter("param", "\u0411\u0411"); requestAfterRedirect.addParameter("param", "\u0412\u0412"); requestAfterRedirect.addParameter(":/?#[]@", "value"); flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse()); assertNotNull(flashMap); assertEquals(1, flashMap.size()); assertEquals("value", flashMap.get("key")); }
Example 2
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-15505 public void retrieveAndUpdateMatchByOriginatingPathAndQueryString() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/accounts"); flashMap.addTargetRequestParam("a", "b"); this.flashMapManager.setFlashMaps(Collections.singletonList(flashMap)); this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts"); this.request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "a=b"); this.request.setRequestURI("/mvc/accounts"); this.request.setQueryString("x=y"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 3
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void flashAttributesWithQueryParamsWithSpace() throws Exception { String encodedValue = URLEncoder.encode("1 2", "UTF-8"); FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); flashMap.addTargetRequestParam("param", encodedValue); this.request.setCharacterEncoding("UTF-8"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path"); requestAfterRedirect.setQueryString("param=" + encodedValue); requestAfterRedirect.addParameter("param", "1 2"); flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse()); assertNotNull(flashMap); assertEquals(1, flashMap.size()); assertEquals("value", flashMap.get("key")); }
Example 4
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); assertEquals(flashMapTwo, inputFlashMap); assertEquals("Input FlashMap should have been removed", 2, this.flashMapManager.getFlashMaps().size()); }
Example 5
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 6 votes |
@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); assertEquals(flashMapTwo, inputFlashMap); assertEquals("Input FlashMap should have been removed", 2, this.flashMapManager.getFlashMaps().size()); }
Example 6
Source File: FlashMapManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-15505 public void retrieveAndUpdateMatchByOriginatingPathAndQueryString() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/accounts"); flashMap.addTargetRequestParam("a", "b"); this.flashMapManager.setFlashMaps(Collections.singletonList(flashMap)); this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts"); this.request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "a=b"); this.request.setRequestURI("/mvc/accounts"); this.request.setQueryString("x=y"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 7
Source File: FlashMapManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException { 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); assertEquals("/once/upon/a", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("./"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon/a/", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath(".."); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("../"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon/", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("../../only"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/only", flashMap.getTargetRequestPath()); }
Example 8
Source File: FlashMapManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void saveOutputFlashMapDecodeParameters() throws Exception { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); flashMap.addTargetRequestParam("param", "%D0%90%D0%90"); flashMap.addTargetRequestParam("param", "%D0%91%D0%91"); flashMap.addTargetRequestParam("param", "%D0%92%D0%92"); flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value"); this.request.setCharacterEncoding("UTF-8"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path"); requestAfterRedirect.setQueryString( "param=%D0%90%D0%90¶m=%D0%91%D0%91¶m=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value"); requestAfterRedirect.addParameter("param", "\u0410\u0410"); requestAfterRedirect.addParameter("param", "\u0411\u0411"); requestAfterRedirect.addParameter("param", "\u0412\u0412"); requestAfterRedirect.addParameter(":/?#[]@", "value"); flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse()); assertNotNull(flashMap); assertEquals(1, flashMap.size()); assertEquals("value", flashMap.get("key")); }
Example 9
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 10
Source File: FlashMapManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/once%20upon%20a%20time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once upon a time", flashMap.getTargetRequestPath()); }
Example 11
Source File: RequestContextUtils.java From spring-analysis-note with MIT License | 5 votes |
/** * 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); }
Example 12
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void retrieveAndUpdateMatchByPath() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); this.request.setRequestURI("/path"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); assertEquals(flashMap, inputFlashMap); }
Example 13
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 5 votes |
@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); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 14
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void retrieveAndUpdateMatchWithTrailingSlash() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); this.request.setRequestURI("/path/"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 15
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void retrieveAndUpdateMatchByPath() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); this.request.setRequestURI("/path"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); assertEquals(flashMap, inputFlashMap); }
Example 16
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/once%20upon%20a%20time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once upon a time", flashMap.getTargetRequestPath()); }
Example 17
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/once%20upon%20a%20time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once upon a time", flashMap.getTargetRequestPath()); }
Example 18
Source File: FlashMapManagerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void saveOutputFlashMapDecodeParameters() throws Exception { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); flashMap.addTargetRequestParam("param", "%D0%90%D0%90"); flashMap.addTargetRequestParam("param", "%D0%91%D0%91"); flashMap.addTargetRequestParam("param", "%D0%92%D0%92"); flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value"); this.request.setCharacterEncoding("UTF-8"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path"); requestAfterRedirect.setQueryString( "param=%D0%90%D0%90¶m=%D0%91%D0%91¶m=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value"); requestAfterRedirect.addParameter("param", "\u0410\u0410"); requestAfterRedirect.addParameter("param", "\u0411\u0411"); requestAfterRedirect.addParameter("param", "\u0412\u0412"); requestAfterRedirect.addParameter(":/?#[]@", "value"); flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse()); assertNotNull(flashMap); assertEquals(1, flashMap.size()); assertEquals("value", flashMap.get("key")); }
Example 19
Source File: FlashMapManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@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); assertEquals(flashMap, inputFlashMap); assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size()); }
Example 20
Source File: FlashMapManagerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException { 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); assertEquals("/once/upon/a", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("./"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon/a/", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath(".."); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("../"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/upon/", flashMap.getTargetRequestPath()); flashMap.setTargetRequestPath("../../only"); this.request.setRequestURI("/once/upon/a/time"); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); assertEquals("/once/only", flashMap.getTargetRequestPath()); }