Java Code Examples for org.springframework.web.servlet.FlashMap#addTargetRequestParam()

The following examples show how to use org.springframework.web.servlet.FlashMap#addTargetRequestParam() . 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 spring-analysis-note with MIT License 6 votes vote down vote up
@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);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=two");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=one");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertEquals(flashMap, inputFlashMap);
	assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
}
 
Example 2
Source File: FlashMapManagerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void retrieveAndUpdateMatchWithMultiValueParam() {
	FlashMap flashMap = new FlashMap();
	flashMap.put("name", "value");
	flashMap.addTargetRequestParam("id", "1");
	flashMap.addTargetRequestParam("id", "2");

	this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));

	this.request.setQueryString("id=1");
	FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("id=1&id=2");
	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 spring-analysis-note with MIT License 6 votes vote down vote up
@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 spring-analysis-note with MIT License 6 votes vote down vote up
@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 5
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=two");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=one");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertEquals(flashMap, inputFlashMap);
	assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
}
 
Example 6
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void retrieveAndUpdateMatchWithMultiValueParam() {
	FlashMap flashMap = new FlashMap();
	flashMap.put("name", "value");
	flashMap.addTargetRequestParam("id", "1");
	flashMap.addTargetRequestParam("id", "2");

	this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));

	this.request.setQueryString("id=1");
	FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("id=1&id=2");
	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 java-technology-stack with MIT License 6 votes vote down vote up
@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 8
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 9
Source File: FlashMapManagerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=two");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("number=one");
	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 spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void retrieveAndUpdateMatchWithMultiValueParam() {
	FlashMap flashMap = new FlashMap();
	flashMap.put("name", "value");
	flashMap.addTargetRequestParam("id", "1");
	flashMap.addTargetRequestParam("id", "2");

	this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));

	this.request.setQueryString("id=1");
	FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertNull(inputFlashMap);
	assertEquals("FlashMap should not have been removed", 1, this.flashMapManager.getFlashMaps().size());

	this.request.setQueryString("id=1&id=2");
	inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);

	assertEquals(flashMap, inputFlashMap);
	assertEquals("Input FlashMap should have been removed", 0, this.flashMapManager.getFlashMaps().size());
}
 
Example 11
Source File: FlashMapManagerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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&param=%D0%91%D0%91&param=%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 12
Source File: FlashMapManagerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 13
Source File: FlashMapManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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&param=%D0%91%D0%91&param=%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 14
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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&param=%D0%91%D0%91&param=%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"));
}