Package org.springframework.web

# Class HttpRequestMethodNotSupportedException

java.lang.Object
java.lang.Throwable
java.lang.Exception
jakarta.servlet.ServletException
org.springframework.web.HttpRequestMethodNotSupportedException

All Implemented Interfaces:
  `Serializable`, `ErrorResponse`

public class HttpRequestMethodNotSupportedException extends ServletException implements ErrorResponse
Exception thrown when a request handler does not support a specific request method.

Since:
  2.0
Author:
  Juergen Hoeller, Sam Brannen
See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## Constructor Summary

Constructors
Constructor
Description
`HttpRequestMethodNotSupportedException(String method)`
Create a new `HttpRequestMethodNotSupportedException`.
`HttpRequestMethodNotSupportedException(String method, Collection<String> supportedMethods)`
Create a new `HttpRequestMethodNotSupportedException`.

## Method Summary

Modifier and Type
Method
Description
`ProblemDetail`
`getBody()`
Return the body for the response, formatted as an RFC 9457 `ProblemDetail` whose `status` should match the response status.
`Object[]`
`getDetailMessageArguments()`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`.
`HttpHeaders`
`getHeaders()`
Return headers to use for the response.
`String`
`getMethod()`
Return the HTTP request method that caused the failure.
`HttpStatusCode`
`getStatusCode()`
Return the HTTP status code to use for the response.
`Set<HttpMethod>`
`getSupportedHttpMethods()`
Return the actually supported HTTP methods as `HttpMethod` instances, or `null` if not known.
`String[]`
`getSupportedMethods()`
Return the actually supported HTTP methods, or `null` if not known.

### Methods inherited from class jakarta.servlet.ServletException

`getRootCause`

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.web.ErrorResponse

`getDetailMessageArguments, getDetailMessageCode, getTitleMessageCode, getTypeMessageCode, updateAndGetBody`

## Constructor Details

### HttpRequestMethodNotSupportedException

public HttpRequestMethodNotSupportedException(String method)
Create a new `HttpRequestMethodNotSupportedException`.

Parameters:
  `method` - the unsupported HTTP request method

### HttpRequestMethodNotSupportedException

public HttpRequestMethodNotSupportedException(String method, @Nullable Collection<String> supportedMethods)
Create a new `HttpRequestMethodNotSupportedException`.

Parameters:
  `method` - the unsupported HTTP request method
  `supportedMethods` - the actually supported HTTP methods (possibly `null`)

## Method Details

### getMethod

public String getMethod()
Return the HTTP request method that caused the failure.

### getSupportedMethods

@Nullable public String[] getSupportedMethods()
Return the actually supported HTTP methods, or `null` if not known.

### getSupportedHttpMethods

@Nullable public Set<HttpMethod> getSupportedHttpMethods()
Return the actually supported HTTP methods as `HttpMethod` instances, or `null` if not known.

Since:
  3.2

### getStatusCode

public HttpStatusCode getStatusCode()
Description copied from interface: `ErrorResponse`
Return the HTTP status code to use for the response.

Specified by:
  `getStatusCode` in interface `ErrorResponse`

### getHeaders

public HttpHeaders getHeaders()
Description copied from interface: `ErrorResponse`
Return headers to use for the response.

Specified by:
  `getHeaders` in interface `ErrorResponse`

### getBody

public ProblemDetail getBody()
Description copied from interface: `ErrorResponse`
Return the body for the response, formatted as an RFC 9457 `ProblemDetail` whose `status` should match the response status.

Note: The returned `ProblemDetail` may be updated before the response is rendered, for example, via `ErrorResponse.updateAndGetBody(MessageSource, Locale)`. Therefore, implementing methods should use an instance field, and should not re-create the `ProblemDetail` on every call, nor use a static variable.

Specified by:
  `getBody` in interface `ErrorResponse`

### getDetailMessageArguments

public Object[] getDetailMessageArguments()
Description copied from interface: `ErrorResponse`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`. The arguments are expanded into placeholders of the message value, for example, "Invalid content type {0}".

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`