Java Code Examples for org.springframework.web.HttpRequestMethodNotSupportedException#getSupportedHttpMethods()

The following examples show how to use org.springframework.web.HttpRequestMethodNotSupportedException#getSupportedHttpMethods() . 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: ResponseEntityExceptionHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * <p>This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(
		HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {

	pageNotFoundLogger.warn(ex.getMessage());

	Set<HttpMethod> supportedMethods = ex.getSupportedHttpMethods();
	if (!CollectionUtils.isEmpty(supportedMethods)) {
		headers.setAllow(supportedMethods);
	}
	return handleExceptionInternal(ex, null, headers, status, request);
}
 
Example 2
Source File: ResponseEntityExceptionHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * <p>This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(
		HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {

	pageNotFoundLogger.warn(ex.getMessage());

	Set<HttpMethod> supportedMethods = ex.getSupportedHttpMethods();
	if (!CollectionUtils.isEmpty(supportedMethods)) {
		headers.setAllow(supportedMethods);
	}
	return handleExceptionInternal(ex, null, headers, status, request);
}
 
Example 3
Source File: RestControllerExceptionHandler.java    From Spring-Boot-Blog-REST-API with GNU Affero General Public License v3.0 5 votes vote down vote up
@ExceptionHandler({ HttpRequestMethodNotSupportedException.class })
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ResponseBody
public ResponseEntity<ExceptionResponse> resolveException(HttpRequestMethodNotSupportedException ex) {
	String message = "Request method '" + ex.getMethod() + "' not supported. List of all supported methods - "
			+ ex.getSupportedHttpMethods();
	List<String> messages = new ArrayList<>(1);
	messages.add(message);
	
	return new ResponseEntity<>(new ExceptionResponse(messages, HttpStatus.METHOD_NOT_ALLOWED.getReasonPhrase(),
			HttpStatus.METHOD_NOT_ALLOWED.value()), HttpStatus.METHOD_NOT_ALLOWED);
}
 
Example 4
Source File: ResponseEntityExceptionHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * <p>This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
		HttpHeaders headers, HttpStatus status, WebRequest request) {

	pageNotFoundLogger.warn(ex.getMessage());

	Set<HttpMethod> supportedMethods = ex.getSupportedHttpMethods();
	if (!CollectionUtils.isEmpty(supportedMethods)) {
		headers.setAllow(supportedMethods);
	}
	return handleExceptionInternal(ex, null, headers, status, request);
}
 
Example 5
Source File: ResponseEntityExceptionHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * <p>This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal}.
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
		HttpHeaders headers, HttpStatus status, WebRequest request) {

	pageNotFoundLogger.warn(ex.getMessage());

	Set<HttpMethod> supportedMethods = ex.getSupportedHttpMethods();
	if (!supportedMethods.isEmpty()) {
		headers.setAllow(supportedMethods);
	}

	return handleExceptionInternal(ex, null, headers, status, request);
}