From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../stateless/interceptors/AuditorInterceptor.java | 18 ++++++++++++++++++ .../stateless/interceptors/LoggerInterceptor.java | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java new file mode 100644 index 0000000..853a891 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java @@ -0,0 +1,18 @@ +package examples.stateless.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +public class AuditorInterceptor { + @AroundInvoke + public Object checkCost(InvocationContext inv) throws Exception { + if (inv.getMethod().getName().startsWith("getTax")) { + Object[] o = inv.getParameters(); + double cost = ((Double)o[0]).doubleValue(); + if (cost > 50) { + System.out.println("Cost is > 50!"); + } + } + return inv.proceed(); + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java new file mode 100644 index 0000000..ee37d23 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java @@ -0,0 +1,16 @@ +package examples.stateless.interceptors; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; + +public class LoggerInterceptor { + @AroundInvoke + public Object logger(InvocationContext inv) throws Exception { + System.out.println("Intercepted call via external class to: "+inv.getMethod().getName()); + Object[] params = inv.getParameters(); + for (int i=0;i