Interface Interceptor<T>

  • Type Parameters:
    T -
    All Superinterfaces:
    Bean<T>, BeanAttributes<T>, Contextual<T>

    public interface Interceptor<T>
    extends Bean<T>
    A Bean for creating and using an interceptor. A CDI interceptor is always a separate dependent instance for each intercepted class. It will get created when the intercepted bean gets created and destroyed when the intercepted bean gets destroyed.
    • Method Detail

      • getInterceptorBindings

        java.util.Set<java.lang.annotation.Annotation> getInterceptorBindings()
        Usually a single Interceptor
        Returns:
        all InterceptorBindings handled by this interceptor.
      • intercepts

        boolean intercepts​(InterceptionType type)
        Parameters:
        type - InterceptionType in question
        Returns:
        true if this interceptor handles the given InterceptionType, false otherwise
      • intercept

        java.lang.Object intercept​(InterceptionType type,
                                   T instance,
                                   javax.interceptor.InvocationContext ctx)
                            throws java.lang.Exception
        Perform the interception. This will e.g. invoke the @AroundInvoke annotated method on the given instance of T.
        Parameters:
        type - the InterceptionType. This is important if an interceptor has multiple interceptor methods e.g. one @AroundInvoke and one @PostConstruct;
        instance - the interceptor instance
        ctx - the InvocationContext contains all the interceptor chain state for a single invocation.
        Returns:
        the object or wrapper type returned by the intercepted instance or the previous interceptor (if this is not the last interceptor in the chain)
        Throws:
        java.lang.Exception - wrapped from the intercepted instance. See CDI-115