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

The following examples show how to use org.springframework.web.servlet.FlashMap#put() . 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 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 2
Source File: PageRestController.java    From wallride with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value="/{language}/pages", method=RequestMethod.POST)
public @ResponseBody DomainObjectSavedModel save(
		@Valid PageCreateForm form,
		BindingResult result,
		AuthorizedUser authorizedUser,
		HttpServletRequest request,
		HttpServletResponse response) throws BindException {
	if (result.hasErrors()) {
		throw new BindException(result);
	}
	Page page = pageService.createPage(form.buildPageCreateRequest(), Post.Status.DRAFT, authorizedUser);
	FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
	flashMap.put("savedPage", page);
	RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response);
	return new DomainObjectSavedModel<>(page);
}
 
Example 3
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 4
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 5
Source File: CategoryRestController.java    From wallride with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value="/{language}/categories", method=RequestMethod.POST)
public @ResponseBody DomainObjectSavedModel save(
		@Valid CategoryCreateForm form,
		BindingResult result,
		AuthorizedUser authorizedUser,
		HttpServletRequest request,
		HttpServletResponse response) throws BindException {
	if (result.hasErrors()) {
		throw new BindException(result);
	}
	Category category = categoryService.createCategory(form.buildCategoryCreateRequest(), authorizedUser);
	FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
	flashMap.put("savedCategory", category);
	RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response);
	return new DomainObjectSavedModel<>(category);
}
 
Example 6
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 7
Source File: TagRestController.java    From wallride with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{language}/tags/merge", method = RequestMethod.POST)
public @ResponseBody DomainObjectSavedModel merge(
		@Valid TagMergeForm form,
		BindingResult errors,
		AuthorizedUser authorizedUser,
		HttpServletRequest request,
		HttpServletResponse response) throws BindException {
	if (errors.hasErrors()) {
		throw new BindException(errors);
	}

	Tag mergedTag;
	try {
		mergedTag = tagService.mergeTags(form.toTagMergeRequest(), authorizedUser);
	} catch (DuplicateNameException e) {
		errors.rejectValue("name", "NotDuplicate");
		throw new BindException(errors);
	}

	FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
	flashMap.put("mergedTag", mergedTag);
	RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response);
	return new DomainObjectSavedModel<>(mergedTag);
}
 
Example 8
Source File: PostBackManager.java    From sinavi-jfw with Apache License 2.0 6 votes vote down vote up
/**
 * {@link PostBack} インスタンスを保存します。
 * @param postBack {@link PostBack} インスタンス
 */
public static void save(PostBack postBack) {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    DispatchType dispatchType = getDispatchType(postBack.getException());
    switch (dispatchType) {
    case JSP:
        requestAttributes.setAttribute(PostBack.POST_BACK_ATTRIBUTE_KEY, postBack, RequestAttributes.SCOPE_REQUEST);
        break;
    case FORWARD:
        requestAttributes.setAttribute(PostBack.POST_BACK_ATTRIBUTE_KEY, postBack, RequestAttributes.SCOPE_REQUEST);
        break;
    case REDIRECT:
        PostBackManager instance = (PostBackManager) requestAttributes.getAttribute(STORE_KEY_TO_REQUEST, RequestAttributes.SCOPE_REQUEST);
        FlashMap flashMap = RequestContextUtils.getOutputFlashMap(instance.request);
        flashMap.put(PostBack.POST_BACK_ATTRIBUTE_KEY, postBack);
        break;
    default:
        throw new InternalException(PostBackManager.class, "E-POSTBACK#0001");
    }
}
 
Example 9
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 10
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 11
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 12
Source File: FlashMapManagerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: CategoryRestController.java    From wallride with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value="/{language}/categories/{id}", method= RequestMethod.DELETE)
public @ResponseBody DomainObjectDeletedModel<Long> delete(
		@PathVariable String language,
		@PathVariable long id,
		AuthorizedUser authorizedUser,
		HttpServletRequest request,
		HttpServletResponse response) throws BindException {
	Category category = categoryService.deleteCategory(id, language);
	FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
	flashMap.put("deletedCategory", category);
	RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response);
	return new DomainObjectDeletedModel<>(category);
}
 
Example 14
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 15
Source File: FlashMapManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 16
Source File: MessageContext.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
private void clearForFlash(String key, String code, MessageType type) {
    FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
    Messages messages = (Messages) flashMap.get(key);
    if (messages == null) return;
    
    if (Strings.isEmpty(code)) {
        flashMap.remove(key);
    } else {
        messages.remove(code);
        flashMap.put(key, messages);
    }
}
 
Example 17
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"));
}
 
Example 18
Source File: FlashMapManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 19
Source File: FlashMapManagerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 20
Source File: FlashMapManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}