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

The following examples show how to use org.springframework.http.HttpMethod#values() . 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: WebContentGenerator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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
Source File: WebContentGenerator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: FormContentFilterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 4
Source File: Method.java    From cloudbreak with 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 5
Source File: FormContentFilterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: WebContentGenerator.java    From java-technology-stack with MIT License 6 votes vote down vote up
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 7
Source File: HttpClientConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 8
Source File: HttpPutFormContentFilterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: FormTag.java    From spring4-understanding with 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 10
Source File: FormTag.java    From lams with 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 11
Source File: ResourceHttpRequestHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		resourceNotFound(method);
	}
}
 
Example 12
Source File: ResourceHttpRequestHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		testResolvePathWithTraversal(method);
	}
}
 
Example 13
Source File: FormTag.java    From java-technology-stack with 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 14
Source File: ResourceHttpRequestHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		resourceNotFound(method);
	}
}
 
Example 15
Source File: ResourceHttpRequestHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		this.request = new MockHttpServletRequest("GET", "");
		this.response = new MockHttpServletResponse();
		testResolvePathWithTraversal(method);
	}
}
 
Example 16
Source File: FormTag.java    From spring-analysis-note with 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 17
Source File: ResourceWebHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		resourceNotFound(method);
	}
}
 
Example 18
Source File: ResourceWebHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testResolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		testResolvePathWithTraversal(method);
	}
}
 
Example 19
Source File: ResourceWebHandlerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void resourceNotFound() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		resourceNotFound(method);
	}
}
 
Example 20
Source File: ResourceWebHandlerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testResolvePathWithTraversal() throws Exception {
	for (HttpMethod method : HttpMethod.values()) {
		testResolvePathWithTraversal(method);
	}
}