Class AbstractMethodValidationInterceptor
java.lang.Object
io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
JaxrsEndPointValidationInterceptor,MethodValidationInterceptor,ResteasyReactiveEndPointValidationInterceptor
NOTE: this is a copy of the interceptor present in hibernate-validator-cdi.
For now, I prefer not depending on this artifact but this might change in the
future.
An interceptor which performs a validation of the Bean Validation constraints specified at the parameters and/or return values of intercepted methods using the method validation functionality provided by Hibernate Validator.
- Author:
- Gunnar Morling, Hardy Ferentschik
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) jakarta.enterprise.inject.Instance<jakarta.validation.Validator>The validator to be used for method validation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvalidateConstructorInvocation(jakarta.interceptor.InvocationContext ctx) Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted constructor.protected ObjectvalidateMethodInvocation(jakarta.interceptor.InvocationContext ctx) Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted method.
-
Field Details
-
validatorInstance
@Inject jakarta.enterprise.inject.Instance<jakarta.validation.Validator> validatorInstanceThe validator to be used for method validation.Although the concrete validator is not necessarily serializable (and HV's implementation indeed isn't) it is still alright to have it as non-transient field here. Upon passivation not the validator itself will be serialized, but the proxy injected here, which in turn is serializable.
Instanceis used to make the resolution dynamic and working at runtime, this delaysValidatorinjection enough to enable it to work for beans that observe@Initialized(ApplicationScoped.class)event.
-
-
Constructor Details
-
AbstractMethodValidationInterceptor
public AbstractMethodValidationInterceptor()
-
-
Method Details
-
validateMethodInvocation
protected Object validateMethodInvocation(jakarta.interceptor.InvocationContext ctx) throws Exception Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted method.- Parameters:
ctx- The context of the intercepted method invocation.- Returns:
- The result of the method invocation.
- Throws:
Exception- Any exception caused by the intercepted method invocation. AConstraintViolationExceptionin case at least one constraint violation occurred either during parameter or return value validation.
-
validateConstructorInvocation
protected void validateConstructorInvocation(jakarta.interceptor.InvocationContext ctx) throws Exception Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted constructor.- Parameters:
ctx- The context of the intercepted constructor invocation.- Throws:
Exception- Any exception caused by the intercepted constructor invocation. AConstraintViolationExceptionin case at least one constraint violation occurred either during parameter or return value validation.
-