Java Code Examples for org.springframework.http.HttpMethod#values()

The following examples show how to use org.springframework.http.HttpMethod#values() . These examples are extracted from open source projects. 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
private void initAllowHeader() {
	Collection<String> allowedMethods;
	if (this.supportedMethods == null) {
		allowedMethods = new ArrayList<>(HttpMethod.values().length - 1);
		for (HttpMethod method : HttpMethod.values()) {
			if (method != HttpMethod.TRACE) {
				allowedMethods.add(method.name());
			}
		}
	}
	else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
		allowedMethods = this.supportedMethods;
	}
	else {
		allowedMethods = new ArrayList<>(this.supportedMethods);
		allowedMethods.add(HttpMethod.OPTIONS.name());

	}
	this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
}
 
Example 2
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 3
Source Project: cloudbreak   File: Method.java    License: Apache License 2.0 6 votes vote down vote up
public static Method build(String methodName) {
    HttpMethod httpMethod = null;
    try {
        httpMethod = HttpMethod.valueOf(methodName.toUpperCase());
    } catch (IllegalArgumentException e) {
        for (HttpMethod checkMethod : HttpMethod.values()) {
            if (methodName.startsWith(checkMethod.name().toLowerCase())) {
                httpMethod = checkMethod;
                break;
            }
        }
    }
    if (httpMethod == null) {
        throw new IllegalArgumentException(methodName + " method name should start with http method (get, post, ...)");
    }
    return new Method(httpMethod, methodName);
}
 
Example 4
private void initAllowHeader() {
	Collection<String> allowedMethods;
	if (this.supportedMethods == null) {
		allowedMethods = new ArrayList<>(HttpMethod.values().length - 1);
		for (HttpMethod method : HttpMethod.values()) {
			if (method != HttpMethod.TRACE) {
				allowedMethods.add(method.name());
			}
		}
	}
	else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
		allowedMethods = this.supportedMethods;
	}
	else {
		allowedMethods = new ArrayList<>(this.supportedMethods);
		allowedMethods.add(HttpMethod.OPTIONS.name());

	}
	this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
}
 
Example 5
@Test
public void wrapPutPatchAndDeleteOnly() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/");
		request.setContent("foo=bar".getBytes("ISO-8859-1"));
		request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.filterChain = new MockFilterChain();
		this.filter.doFilter(request, this.response, this.filterChain);
		if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) {
			assertNotSame(request, this.filterChain.getRequest());
		}
		else {
			assertSame(request, this.filterChain.getRequest());
		}
	}
}
 
Example 6
private void initAllowHeader() {
	Collection<String> allowedMethods;
	if (this.supportedMethods == null) {
		allowedMethods = new ArrayList<String>(HttpMethod.values().length - 1);
		for (HttpMethod method : HttpMethod.values()) {
			if (!HttpMethod.TRACE.equals(method)) {
				allowedMethods.add(method.name());
			}
		}
	}
	else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
		allowedMethods = this.supportedMethods;
	}
	else {
		allowedMethods = new ArrayList<String>(this.supportedMethods);
		allowedMethods.add(HttpMethod.OPTIONS.name());

	}
	this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
}
 
Example 7
Source Project: spring-analysis-note   File: FormTag.java    License: MIT License 5 votes vote down vote up
private void assertHttpMethod(String method) {
	for (HttpMethod httpMethod : HttpMethod.values()) {
		if (httpMethod.name().equalsIgnoreCase(method)) {
			return;
		}
	}
	throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
 
Example 8
@Test
public void resolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		testResolvePathWithTraversal(method);
	}
}
 
Example 9
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		resourceNotFound(method);
	}
}
 
Example 10
Source Project: java-technology-stack   File: FormTag.java    License: MIT License 5 votes vote down vote up
private void assertHttpMethod(String method) {
	for (HttpMethod httpMethod : HttpMethod.values()) {
		if (httpMethod.name().equalsIgnoreCase(method)) {
			return;
		}
	}
	throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
 
Example 11
@Test
public void resolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		testResolvePathWithTraversal(method);
	}
}
 
Example 12
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		resourceNotFound(method);
	}
}
 
Example 13
Source Project: lams   File: FormTag.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void assertHttpMethod(String method) {
	for (HttpMethod httpMethod : HttpMethod.values()) {
		if (httpMethod.name().equalsIgnoreCase(method)) {
			return;
		}
	}
	throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
 
Example 14
Source Project: spring4-understanding   File: FormTag.java    License: Apache License 2.0 5 votes vote down vote up
private void assertHttpMethod(String method) {
	for (HttpMethod httpMethod : HttpMethod.values()) {
		if (httpMethod.name().equalsIgnoreCase(method)) {
			return;
		}
	}
	throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
 
Example 15
@Test
public void wrapPutAndPatchOnly() throws Exception {
	request.setContent("".getBytes("ISO-8859-1"));
	for (HttpMethod method : HttpMethod.values()) {
		request.setMethod(method.name());
		filterChain = new MockFilterChain();
		filter.doFilter(request, response, filterChain);
		if (method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH)) {
			assertNotSame("Should wrap HTTP method " + method, request, filterChain.getRequest());
		}
		else {
			assertSame("Should not wrap for HTTP method " + method, request, filterChain.getRequest());
		}
	}
}
 
Example 16
/**
 * Gets the available Http request method names as list.
 * @return
 */
private String[] getHttpMethodOptions() {
    List<String> methodNames = new ArrayList<String>();
    for (HttpMethod method : HttpMethod.values()) {
        methodNames.add(method.name());
    }
    return methodNames.toArray(new String[methodNames.size()]);
}
 
Example 17
@Test
public void testResolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		testResolvePathWithTraversal(method);
	}
}
 
Example 18
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		resourceNotFound(method);
	}
}
 
Example 19
@Test
public void testResolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		testResolvePathWithTraversal(method);
	}
}
 
Example 20
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		resourceNotFound(method);
	}
}