Java Code Examples for org.springframework.web.servlet.HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE

The following examples show how to use org.springframework.web.servlet.HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE . 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: ExtendedServletRequestDataBinder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Merge URI variables into the property values to use for data binding.
 */
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
	if (uriVars != null) {
		uriVars.forEach((name, value) -> {
			if (mpvs.contains(name)) {
				if (logger.isWarnEnabled()) {
					logger.warn("Skipping URI variable '" + name +
							"' because request contains bind value with same name.");
				}
			}
			else {
				mpvs.addPropertyValue(name, value);
			}
		});
	}
}
 
Example 2
Source File: RequestMappingInfoHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test  // SPR-9098
public void handleMatchUriTemplateVariablesDecode() {
	RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");

	UrlPathHelper pathHelper = new UrlPathHelper();
	pathHelper.setUrlDecode(false);
	String lookupPath = pathHelper.getLookupPathForRequest(request);

	this.handlerMapping.setUrlPathHelper(pathHelper);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);

	assertNotNull(uriVariables);
	assertEquals("group", uriVariables.get("group"));
	assertEquals("a/b", uriVariables.get("identifier"));
}
 
Example 3
Source File: ExtendedServletRequestDataBinder.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Merge URI variables into the property values to use for data binding.
 */
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
	if (uriVars != null) {
		uriVars.forEach((name, value) -> {
			if (mpvs.contains(name)) {
				if (logger.isWarnEnabled()) {
					logger.warn("Skipping URI variable '" + name +
							"' because request contains bind value with same name.");
				}
			}
			else {
				mpvs.addPropertyValue(name, value);
			}
		});
	}
}
 
Example 4
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test  // SPR-9098
public void handleMatchUriTemplateVariablesDecode() {
	RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");

	UrlPathHelper pathHelper = new UrlPathHelper();
	pathHelper.setUrlDecode(false);
	String lookupPath = pathHelper.getLookupPathForRequest(request);

	this.handlerMapping.setUrlPathHelper(pathHelper);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);

	assertNotNull(uriVariables);
	assertEquals("group", uriVariables.get("group"));
	assertEquals("a/b", uriVariables.get("identifier"));
}
 
Example 5
Source File: ExtendedServletRequestDataBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Merge URI variables into the property values to use for data binding.
 */
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
	if (uriVars != null) {
		for (Entry<String, String> entry : uriVars.entrySet()) {
			if (mpvs.contains(entry.getKey())) {
				if (logger.isWarnEnabled()) {
					logger.warn("Skipping URI variable '" + entry.getKey() +
							"' since the request contains a bind value with the same name.");
				}
			}
			else {
				mpvs.addPropertyValue(entry.getKey(), entry.getValue());
			}
		}
	}
}
 
Example 6
Source File: ExtendedServletRequestDataBinder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Merge URI variables into the property values to use for data binding.
 */
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
	String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
	if (uriVars != null) {
		for (Entry<String, String> entry : uriVars.entrySet()) {
			if (mpvs.contains(entry.getKey())) {
				logger.warn("Skipping URI variable '" + entry.getKey()
						+ "' since the request contains a bind value with the same name.");
			}
			else {
				mpvs.addPropertyValue(entry.getKey(), entry.getValue());
			}
		}
	}
}
 
Example 7
Source File: RequestMappingInfoHandlerMappingTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void handleMatchUriTemplateVariables() {
	RequestMappingInfo key = RequestMappingInfo.paths("/{path1}/{path2}").build();
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
	String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);

	assertNotNull(uriVariables);
	assertEquals("1", uriVariables.get("path1"));
	assertEquals("2", uriVariables.get("path2"));
}
 
Example 8
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void handleMatchUriTemplateVariables() {
	RequestMappingInfo key = RequestMappingInfo.paths("/{path1}/{path2}").build();
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2");
	String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
	this.handlerMapping.handleMatch(key, lookupPath, request);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name);

	assertNotNull(uriVariables);
	assertEquals("1", uriVariables.get("path1"));
	assertEquals("2", uriVariables.get("path2"));
}
 
Example 9
Source File: RedirectView.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getCurrentRequestUriVariables(HttpServletRequest request) {
	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(name);
	return (uriVars != null) ? uriVars : Collections.<String, String> emptyMap();
}
 
Example 10
Source File: RequestMappingInfoHandlerMappingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getUriTemplateVariables(HttpServletRequest request) {
	String attrName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	return (Map<String, String>) request.getAttribute(attrName);
}
 
Example 11
Source File: RedirectView.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getCurrentRequestUriVariables(HttpServletRequest request) {
	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(name);
	return (uriVars != null) ? uriVars : Collections.<String, String> emptyMap();
}
 
Example 12
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getUriTemplateVariables(HttpServletRequest request) {
	String attrName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	return (Map<String, String>) request.getAttribute(attrName);
}
 
Example 13
Source File: RedirectView.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getCurrentRequestUriVariables(HttpServletRequest request) {
	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(name);
	return (uriVars != null) ? uriVars : Collections.<String, String> emptyMap();
}
 
Example 14
Source File: RedirectView.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getCurrentRequestUriVariables(HttpServletRequest request) {
	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVars = (Map<String, String>) request.getAttribute(name);
	return (uriVars != null) ? uriVars : Collections.<String, String> emptyMap();
}
 
Example 15
Source File: RequestMappingInfoHandlerMappingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getUriTemplateVariables(HttpServletRequest request) {
	String attrName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	return (Map<String, String>) request.getAttribute(attrName);
}