Top Description Methods
jakarta.interceptor

public Interface InvocationContext

Imports
java.lang.annotation.Annotation, java.lang.reflect.Constructor, .Method, java.util.Collections, .HashSet, .Map, .Set

Exposes contextual information about the intercepted invocation and operations that enable interceptor methods to control the behavior of the invocation chain.

   @AroundInvoke
   public Object logInvocation(InvocationContext ctx) throws Exception {
      String class = ctx.getMethod().getDeclaringClass().getName();
      String method = ctx.getMethod().getName();
      Logger.global.entering(class, method, ctx.getParameters());
      try {
         Object result = ctx.proceed();
         Logger.global.exiting(class, method, result);
         return result;
      }
      catch (Exception e) {
         Logger.global.throwing(class, method, e);
         throw e;
      }

   }

Since
Jakarta Interceptors 1.0

Method Summary

Modifier and TypeMethod and Description
public Constructor<?>

Returns:

the constructor, or a null value
getConstructor
()

Returns the constructor of the target class for which the AroundConstruct interceptor method was invoked.

public Map<String, Object>

Returns:

the context data associated with this invocation or lifecycle callback. If there is no context data, an empty Map<String,Object> object will be returned.
getContextData
()

Enables an interceptor to retrieve or update the data associated with the invocation by another interceptor, business method, and/or webservices endpoint in the invocation chain.

public default <T extends Annotation> T

Returns:

the interceptor binding annotation of given type, may be null
getInterceptorBinding
(Class<T>
type of the interceptor binding annotation, must not be null
annotationType
)

Returns the single annotation of given type present in the full set of interceptor binding annotations.

public default Set<Annotation>

Returns:

immutable set of interceptor binding annotations, never null
getInterceptorBindings
()

Returns the set of interceptor binding annotations for the method or constructor whose invocation is being intercepted.

public default <T extends Annotation> Set<T>

Returns:

immutable set of interceptor binding annotations of given type, never null
getInterceptorBindings
(Class<T>
type of the interceptor binding annotations, must not be null
annotationType
)

Returns all annotations of given type present in the full set of interceptor binding annotations.

public Method

Returns:

the method, or a null value
getMethod
()

Returns the method of the target class for which the interceptor was invoked.

public Object[]

Returns:

the parameter values, as an array
getParameters
()

Returns the parameter values that will be passed to the method or constructor of the target class.

public Object

Returns:

the target instance
getTarget
()

Returns the target instance.

public Object

Returns:

the timer object or a null value
getTimer
()

Returns the timer object associated with a timeout method invocation on the target class, or a null value for interceptor method types other than AroundTimeout.

public Object

Returns:

the return value of the next method in the chain
proceed
()

Proceed to the next interceptor in the interceptor chain.

public void
setParameters(Object[]
the parameter values, as an array
params
)

Sets the parameter values that will be passed to the method or constructor of the target class.

Method Detail

getConstructorback to summary
public Constructor<?> getConstructor()

Returns the constructor of the target class for which the AroundConstruct interceptor method was invoked. Returns null for interceptor method types other than AroundConstruct interceptor methods.

Returns:Constructor<?>

the constructor, or a null value

getContextDataback to summary
public Map<String, Object> getContextData()

Enables an interceptor to retrieve or update the data associated with the invocation by another interceptor, business method, and/or webservices endpoint in the invocation chain.

Returns:Map<String, Object>

the context data associated with this invocation or lifecycle callback. If there is no context data, an empty Map<String,Object> object will be returned.

getInterceptorBindingback to summary
public default <T extends Annotation> T getInterceptorBinding(Class<T> annotationType)

Returns the single annotation of given type present in the full set of interceptor binding annotations.

Returns null if the full set of interceptor binding annotations does not contain an annotation of given type.

In case of repeatable interceptor binding annotations, getInterceptorBindings(Class) should be used instead.

Parameters
annotationType:Class<T>

type of the interceptor binding annotation, must not be null

Returns:T

the interceptor binding annotation of given type, may be null

Since
Jakarta Interceptors 2.2
getInterceptorBindingsback to summary
public default Set<Annotation> getInterceptorBindings()

Returns the set of interceptor binding annotations for the method or constructor whose invocation is being intercepted. In case there is no target method or target constructor, interceptor binding annotations applied to the target class are returned.

All interceptor binding annotations are returned, including inherited interceptor binding annotations, transitive interceptor binding annotations, interceptor binding annotations that associate interceptors of a different interceptor method type, as well as interceptor binding annotations that associate no interceptor.

Returns an empty set if no interceptor binding annotation is applied and all interceptors were associated using the @Interceptors annotation.

Returns:Set<Annotation>

immutable set of interceptor binding annotations, never null

Since
Jakarta Interceptors 2.2
getInterceptorBindingsback to summary
public default <T extends Annotation> Set<T> getInterceptorBindings(Class<T> annotationType)

Returns all annotations of given type present in the full set of interceptor binding annotations.

Returns an empty set if the full set of interceptor binding annotations does not contain any annotation of given type.

Parameters
annotationType:Class<T>

type of the interceptor binding annotations, must not be null

Returns:Set<T>

immutable set of interceptor binding annotations of given type, never null

Since
Jakarta Interceptors 2.2
getMethodback to summary
public Method getMethod()

Returns the method of the target class for which the interceptor was invoked. Returns null in a lifecycle callback interceptor for which there is no corresponding lifecycle callback method declared in the target class (or inherited from a superclass) or in an AroundConstruct lifecycle callback interceptor method.

Returns:Method

the method, or a null value

getParametersback to summary
public Object[] getParameters()

Returns the parameter values that will be passed to the method or constructor of the target class. If setParameters has been called, getParameters returns the values to which the parameters have been set.

Returns:Object[]

the parameter values, as an array

Exceptions
IllegalStateException:
if invoked within a lifecycle callback method that is not an AroundConstruct callback.
getTargetback to summary
public Object getTarget()

Returns the target instance. For AroundConstruct lifecycle callback interceptor methods, the getTarget method returns null if called before the proceed method.

Returns:Object

the target instance

getTimerback to summary
public Object getTimer()

Returns the timer object associated with a timeout method invocation on the target class, or a null value for interceptor method types other than AroundTimeout. For example, when associated with a Jakarta Enterprise Beans component timeout, this method returns jakarta.ejb.Timer.

Returns:Object

the timer object or a null value

Since
Jakarta Interceptors 1.1
proceedback to summary
public Object proceed() throws Exception

Proceed to the next interceptor in the interceptor chain. For around-invoke or around-timeout interceptor methods, the invocation of proceed in the last interceptor method in the chain causes the invocation of the target class method. For AroundConstruct lifecycle callback interceptor methods, the invocation of proceed in the last interceptor method in the chain causes the target instance to be created. For all other lifecycle callback interceptor methods, if there is no callback method defined on the target class, the invocation of proceed in the last interceptor method in the chain is a no-op.

Return the result of the next method invoked, or a null value if the method has return type void.

Returns:Object

the return value of the next method in the chain

Exceptions
Exception:
if thrown by target method or interceptor method in call stack
setParametersback to summary
public void setParameters(Object[] params)

Sets the parameter values that will be passed to the method or constructor of the target class.

Parameters
params:Object[]

the parameter values, as an array

Exceptions
IllegalStateException:
if invoked within a lifecycle callback method that is not an AroundConstruct callback.
IllegalArgumentException:
if the types of the given parameter values do not match the types of the method or constructor parameters, or if the number of parameters supplied does not equal the number of method or constructor parameters (if the last parameter is a vararg parameter of type T, it is considered to be equivalent to a parameter of type T[]).