Top Description Inners Fields Constructors Methods
org.springframework.web.method.annotation

public Class HandlerMethodValidationException

extends ResponseStatusException
implements MethodValidationResult
Class Inheritance
All Implemented Interfaces
org.springframework.validation.method.MethodValidationResult
Annotations
@SuppressWarnings:serial
Imports
java.lang.reflect.Method, java.util.List, .Locale, java.util.function.Predicate, org.springframework.context.MessageSource, org.springframework.core.MethodParameter, org.springframework.http.HttpStatus, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.validation.method.MethodValidationResult, .ParameterErrors, .ParameterValidationResult, org.springframework.web.bind.annotation.CookieValue, .MatrixVariable, .ModelAttribute, .PathVariable, .RequestBody, .RequestHeader, .RequestParam, .RequestPart, org.springframework.web.server.ResponseStatusException, org.springframework.web.util.BindErrorUtils

ResponseStatusException that is also MethodValidationResult. Raised by HandlerMethodValidator in case of method validation errors on a web controller method.

The getStatusCode() is 400 for input validation errors, and 500 for validation errors on a return value.

Author
Rossen Stoyanchev
Since
6.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
HandlerMethodValidationException.Visitor

Contract to handle validation results with callbacks by controller method parameter type, with other serving as the fallthrough.

Field Summary

Modifier and TypeField and Description
private final Predicate<MethodParameter>
private final Predicate<MethodParameter>
private final MethodValidationResult

Constructor Summary

AccessConstructor and Description
public
public
HandlerMethodValidationException(MethodValidationResult validationResult, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Method Summary

Modifier and TypeMethod and Description
private static ParameterErrors
public List<ParameterValidationResult>
public Object[]
getDetailMessageArguments(MessageSource
the MessageSource to use for the lookup
messageSource
,
Locale
the Locale to use for the lookup
locale
)

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Variant of getDetailMessageArguments() that uses the given MessageSource for resolving the message argument values.
public Object[]
getDetailMessageArguments()

Overrides org.springframework.web.ErrorResponseException.getDetailMessageArguments.

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Return arguments to use along with a message code to resolve the problem "detail" for this exception through a MessageSource.
public Method
getMethod()

Implements org.springframework.validation.method.MethodValidationResult.getMethod.

Return the method to which validation was applied.
public Object
getTarget()

Implements org.springframework.validation.method.MethodValidationResult.getTarget.

Return the target of the method invocation to which validation was applied.
private static HttpStatus
public boolean
isForReturnValue()

Implements org.springframework.validation.method.MethodValidationResult.isForReturnValue.

Whether the violations are for a return value.
public void
visitResults(HandlerMethodValidationException.Visitor visitor)

Provide a Visitor to handle ParameterValidationResults through callback methods organized by controller method parameter type.

Inherited from org.springframework.web.server.ResponseStatusException:
getHeadersgetMessagegetReasongetResponseHeadersupdateAndGetBody

Field Detail

modelAttributePredicateback to summary
private final Predicate<MethodParameter> modelAttributePredicate
requestParamPredicateback to summary
private final Predicate<MethodParameter> requestParamPredicate
validationResultback to summary
private final MethodValidationResult validationResult

Constructor Detail

HandlerMethodValidationExceptionback to summary
public HandlerMethodValidationException(MethodValidationResult validationResult)
HandlerMethodValidationExceptionback to summary
public HandlerMethodValidationException(MethodValidationResult validationResult, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)

Method Detail

asErrorsback to summary
private static ParameterErrors asErrors(ParameterValidationResult result)
getAllValidationResultsback to summary
public List<ParameterValidationResult> getAllValidationResults()

Implements org.springframework.validation.method.MethodValidationResult.getAllValidationResults.

Doc from org.springframework.validation.method.MethodValidationResult.getAllValidationResults.

Return all validation results. This includes both method parameters with errors directly on them, and Object method parameters with nested errors on their fields and properties.

Annotations
@Override
getDetailMessageArgumentsback to summary
public Object[] getDetailMessageArguments(MessageSource messageSource, Locale locale)

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Doc from org.springframework.web.ErrorResponse.getDetailMessageArguments.

Variant of getDetailMessageArguments() that uses the given MessageSource for resolving the message argument values.

This is useful for example to expand message codes from validation errors.

The default implementation delegates to getDetailMessageArguments(), ignoring the supplied MessageSource and Locale.

Parameters
messageSource:MessageSource

the MessageSource to use for the lookup

locale:Locale

the Locale to use for the lookup

Annotations
@Override
getDetailMessageArgumentsback to summary
public Object[] getDetailMessageArguments()

Overrides org.springframework.web.ErrorResponseException.getDetailMessageArguments.

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Doc from org.springframework.web.ErrorResponse.getDetailMessageArguments.

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, e.g. "Invalid content type {0}".

Annotations
@Override
getMethodback to summary
public Method getMethod()

Implements org.springframework.validation.method.MethodValidationResult.getMethod.

Doc from org.springframework.validation.method.MethodValidationResult.getMethod.

Return the method to which validation was applied.

Annotations
@Override
getTargetback to summary
public Object getTarget()

Implements org.springframework.validation.method.MethodValidationResult.getTarget.

Doc from org.springframework.validation.method.MethodValidationResult.getTarget.

Return the target of the method invocation to which validation was applied.

Annotations
@Override
initHttpStatusback to summary
private static HttpStatus initHttpStatus(MethodValidationResult validationResult)
isForReturnValueback to summary
public boolean isForReturnValue()

Implements org.springframework.validation.method.MethodValidationResult.isForReturnValue.

Doc from org.springframework.validation.method.MethodValidationResult.isForReturnValue.

Whether the violations are for a return value. If true the violations are from validating a return value. If false the violations are from validating method arguments.

Annotations
@Override
visitResultsback to summary
public void visitResults(HandlerMethodValidationException.Visitor visitor)

Provide a Visitor to handle ParameterValidationResults through callback methods organized by controller method parameter type.

org.springframework.web.method.annotation back to summary

public Interface HandlerMethodValidationException.Visitor


Contract to handle validation results with callbacks by controller method parameter type, with other serving as the fallthrough.

Method Summary

Modifier and TypeMethod and Description
public void
cookieValue(CookieValue
the annotation declared on the parameter
cookieValue
,
ParameterValidationResult
the validation result
result
)

Handle results for @CookieValue method parameters.

public void
matrixVariable(MatrixVariable
the annotation declared on the parameter
matrixVariable
,
ParameterValidationResult
the validation result
result
)

Handle results for @MatrixVariable method parameters.

public void
modelAttribute(ModelAttribute
the optional ModelAttribute annotation, possibly null if the method parameter is declared without it.
modelAttribute
,
ParameterErrors
the validation errors
errors
)

Handle results for @ModelAttribute method parameters.

public void
other(ParameterValidationResult
the validation result
result
)

Handle other results that aren't any of the above.

public void
pathVariable(PathVariable
the annotation declared on the parameter
pathVariable
,
ParameterValidationResult
the validation result
result
)

Handle results for @PathVariable method parameters.

public void
requestBody(RequestBody
the annotation declared on the parameter
requestBody
,
ParameterErrors
the validation error
errors
)

Handle results for @RequestBody method parameters.

public void
requestHeader(RequestHeader
the annotation declared on the parameter
requestHeader
,
ParameterValidationResult
the validation result
result
)

Handle results for @RequestHeader method parameters.

public void
requestParam(RequestParam
the optional RequestParam annotation, possibly null if the method parameter is declared without it.
requestParam
,
ParameterValidationResult
the validation result
result
)

Handle results for @RequestParam method parameters.

public void
requestPart(RequestPart
the annotation declared on the parameter
requestPart
,
ParameterErrors
the validation errors
errors
)

Handle results for @RequestPart method parameters.

Method Detail

cookieValueback to summary
public void cookieValue(CookieValue cookieValue, ParameterValidationResult result)

Handle results for @CookieValue method parameters.

Parameters
cookieValue:CookieValue

the annotation declared on the parameter

result:ParameterValidationResult

the validation result

matrixVariableback to summary
public void matrixVariable(MatrixVariable matrixVariable, ParameterValidationResult result)

Handle results for @MatrixVariable method parameters.

Parameters
matrixVariable:MatrixVariable

the annotation declared on the parameter

result:ParameterValidationResult

the validation result

modelAttributeback to summary
public void modelAttribute(ModelAttribute modelAttribute, ParameterErrors errors)

Handle results for @ModelAttribute method parameters.

Parameters
modelAttribute:ModelAttribute

the optional ModelAttribute annotation, possibly null if the method parameter is declared without it.

errors:ParameterErrors

the validation errors

otherback to summary
public void other(ParameterValidationResult result)

Handle other results that aren't any of the above.

Parameters
result:ParameterValidationResult

the validation result

pathVariableback to summary
public void pathVariable(PathVariable pathVariable, ParameterValidationResult result)

Handle results for @PathVariable method parameters.

Parameters
pathVariable:PathVariable

the annotation declared on the parameter

result:ParameterValidationResult

the validation result

requestBodyback to summary
public void requestBody(RequestBody requestBody, ParameterErrors errors)

Handle results for @RequestBody method parameters.

Parameters
requestBody:RequestBody

the annotation declared on the parameter

errors:ParameterErrors

the validation error

requestHeaderback to summary
public void requestHeader(RequestHeader requestHeader, ParameterValidationResult result)

Handle results for @RequestHeader method parameters.

Parameters
requestHeader:RequestHeader

the annotation declared on the parameter

result:ParameterValidationResult

the validation result

requestParamback to summary
public void requestParam(RequestParam requestParam, ParameterValidationResult result)

Handle results for @RequestParam method parameters.

Parameters
requestParam:RequestParam

the optional RequestParam annotation, possibly null if the method parameter is declared without it.

result:ParameterValidationResult

the validation result

requestPartback to summary
public void requestPart(RequestPart requestPart, ParameterErrors errors)

Handle results for @RequestPart method parameters.

Parameters
requestPart:RequestPart

the annotation declared on the parameter

errors:ParameterErrors

the validation errors