Skip to content

Commit

Permalink
Added Business Method Interceptor Methods
Browse files Browse the repository at this point in the history
Signed-off-by: thadumi <th.theodor.th@gmail.com>
  • Loading branch information
thadumi committed Mar 22, 2020
1 parent 9eac5b0 commit 94ad89b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
////
*******************************************************************
* Copyright (c) 2019 Eclipse Foundation
*
* This specification document is made available under the terms
* of the Eclipse Foundation Specification License v1.0, which is
* available at https://www.eclipse.org/legal/efsl.php.
*******************************************************************
////

[[business_method_interceptor_methods]]
== Business Method Interceptor Methods

image:intercept-4.png[image]

Interceptor methods that interpose on
business method invocations are denoted by the _AroundInvoke_
annotation.

Around-invoke methods may be declared in
interceptor classes, in the superclasses of interceptor classes, in the
target class, and/or in superclasses of the target class. However, only
one around-invoke method may be declared in a given class.

Around-invoke methods can have _public_ ,
_private_ , _protected_ , or _package_ level access. An around-invoke
method must not be declared as _abstract, final or static_ .

Around-invoke methods have the following
signature:

_Object_ __ _<METHOD>(InvocationContext)_

Note: An around-invoke interceptor method may
be declared to throw any checked exceptions that the associated target
method allows within its throws clause. It may be declared to throw the
java.lang.Exception, _for example, if it_ interposes on several methods
that can throw unrelated checked exceptions.

An around-invoke method can invoke any
component or resource that the method it is intercepting can invoke.

In general, an around-invoke method
invocation occurs within the same transaction and security context as
the method on which it is interposing. However, note that the
transaction context may be changed by transactional interceptor methods
in the invocation chain, such as those defined by the _Java Transaction
API_ specification link:intercept.html#a547[See Jakarta Transaction (JTA)
version 2.0.
https://jakarta.ee/specifications/transactions/2.0/.] .

The following example defines
MonitoringInterceptor, which is used to interpose on ShoppingCart
business methods:

@Inherited

@InterceptorBinding

@Target(\{TYPE, METHOD}) @Retention(RUNTIME)

public @interface Monitored \{}



@Monitored @Interceptor

public class MonitoringInterceptor \{



@AroundInvoke

public Object
monitorInvocation(InvocationContext ctx) \{



//... log invocation data ...



return ctx.proceed();

}



}



@Monitored

public class ShoppingCart \{



public void placeOrder(Order o) \{

...

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ include::invocation_context.adoc[]

include::exceptions.adoc[]

include::business_method_interceptor_methods.adoc[+]

0 comments on commit 94ad89b

Please sign in to comment.