Class AbstractMethodValidationInterceptor

java.lang.Object
io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
JaxrsEndPointValidationInterceptor, MethodValidationInterceptor, ResteasyReactiveEndPointValidationInterceptor

public abstract class AbstractMethodValidationInterceptor extends Object implements Serializable
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

    Fields
    Modifier and Type
    Field
    Description
    (package private) jakarta.enterprise.inject.Instance<jakarta.validation.Validator>
    The validator to be used for method validation.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    validateConstructorInvocation(jakarta.interceptor.InvocationContext ctx)
    Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted constructor.
    protected Object
    validateMethodInvocation(jakarta.interceptor.InvocationContext ctx)
    Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted method.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • validatorInstance

      @Inject jakarta.enterprise.inject.Instance<jakarta.validation.Validator> validatorInstance
      The 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.

      Instance is used to make the resolution dynamic and working at runtime, this delays Validator injection 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. A ConstraintViolationException in 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. A ConstraintViolationException in case at least one constraint violation occurred either during parameter or return value validation.