Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AroundInvoke: Curious name?

Request more information on this interceptor annotation. Why is the interceptor annotation called @AroundInvoke and not @BeforeInvoke?

Can I for example invoke an access verification before an action API? What is the guarantee that the Access Verification is completed before the method is actually invoked? Is there something that the VM or the CDI implementation do that does not prevent the actual invocation but execute this interceptor in parallel?

If I were using the Google Guice AOP Method Interceptors, I am assured that the Access Verification failure will determine whether or not the method invocation BEGINS. How can I assure myself of a similar behavior from the jakarta CDI?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Have not been able to find this information in the spec

A related question can be found here. But the exact questions above remain unanswered.

>Solution :

@AroundInvoke is called that because it can act both before and after the actually invoked method. Look at the documentation and its sample:

@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception { ... }

In that method you can call ctx.proceed() to call the target method (or any other interceptors). When you do stuff before that call then you act before the method and anything you do after that call happens after the method is called. Therefore it’s "around" the method.

Sample:

@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
   log.info("We're about to do the thing!");
   Object result = ctx.proceed();
   log.info("We did the thing!");
   return result;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading