Interface InvocationContext
@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 TypeMethodDescriptionConstructor<?>
Returns the constructor of the target class for which theAroundConstruct
interceptor method was invoked.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.default <T extends Annotation>
TgetInterceptorBinding
(Class<T> annotationType) Returns the single annotation of given type present in the full set of interceptor binding annotations.default Set<Annotation>
Returns the set of interceptor binding annotations for the method or constructor whose invocation is being intercepted.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 the method of the target class for which the interceptor was invoked.Object[]
Returns the parameter values that will be passed to the method or constructor of the target class.Returns the target instance.getTimer()
Returns the timer object associated with a timeout method invocation on the target class, or a null value for interceptor method types other thanAroundTimeout
.proceed()
Proceed to the next interceptor in the interceptor chain.void
setParameters
(Object[] params) Sets the parameter values that will be passed to the method or constructor of the target class.
-
Method Details
-
getTarget
Object getTarget()Returns the target instance. ForAroundConstruct
lifecycle callback interceptor methods, thegetTarget
method returnsnull
if called before theproceed()
method.- Returns:
- the target instance
-
getTimer
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 thanAroundTimeout
. For example, when associated with a Jakarta Enterprise Beans component timeout, this method returnsjakarta.ejb.Timer
.- Returns:
- the timer object or a null value
- Since:
- Jakarta Interceptors 1.1
-
getMethod
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 anAroundConstruct
lifecycle callback interceptor method.- Returns:
- the method, or a null value
-
getConstructor
Constructor<?> getConstructor()Returns the constructor of the target class for which theAroundConstruct
interceptor method was invoked. Returns null for interceptor method types other thanAroundConstruct
interceptor methods.- Returns:
- the constructor, or a null value
-
getParameters
Object[] getParameters()Returns the parameter values that will be passed to the method or constructor of the target class. IfsetParameters(java.lang.Object[])
has been called,getParameters
returns the values to which the parameters have been set.- Returns:
- the parameter values, as an array
- Throws:
IllegalStateException
- if invoked within a lifecycle callback method that is not anAroundConstruct
callback.
-
setParameters
Sets the parameter values that will be passed to the method or constructor of the target class.- Parameters:
params
- the parameter values, as an array- Throws:
IllegalStateException
- if invoked within a lifecycle callback method that is not anAroundConstruct
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 typeT
, it is considered to be equivalent to a parameter of typeT[]
).
-
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:
- 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.
-
proceed
Proceed to the next interceptor in the interceptor chain. For around-invoke or around-timeout interceptor methods, the invocation ofproceed
in the last interceptor method in the chain causes the invocation of the target class method. ForAroundConstruct
lifecycle callback interceptor methods, the invocation ofproceed
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:
- the return value of the next method in the chain
- Throws:
Exception
- if thrown by target method or interceptor method in call stack
-
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:
- immutable set of interceptor binding annotations, never
null
- Since:
- Jakarta Interceptors 2.2
-
getInterceptorBinding
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
- type of the interceptor binding annotation, must not benull
- Returns:
- the interceptor binding annotation of given type, may be
null
- Since:
- Jakarta Interceptors 2.2
-
getInterceptorBindings
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
- type of the interceptor binding annotations, must not benull
- Returns:
- immutable set of interceptor binding annotations of given type, never
null
- Since:
- Jakarta Interceptors 2.2
-