blob: 58697d64ab95dc636c4b8ab564dbba6acaa99c94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package examples.stateless;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateless;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptors;
import javax.interceptor.InvocationContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import examples.stateless.interceptors.AuditorInterceptor;
import examples.stateless.interceptors.LoggerInterceptor;
import examples.stateless.interfaces.PricerInjection;
import examples.stateless.interfaces.PricerLookup;
import examples.stateless.interfaces.TaxRate;
@Stateless
@Interceptors({LoggerInterceptor.class,AuditorInterceptor.class})
@Remote({PricerInjection.class,PricerLookup.class})
public class PricerBean implements PricerInjection, PricerLookup {
private TaxRate taxRate;
@EJB
private TaxRate taxRate2;
public double getTaxLookup(double cost, String state) {
double tax = -1;
tax = cost * taxRate.getTaxRate(state);
return tax;
}
public double getTaxInjection(double cost, String state) {
double tax = -1;
tax = cost * taxRate2.getTaxRate(state);
return tax;
}
@PostConstruct
public void postConstruct() {
try {
InitialContext ic = new InitialContext();
taxRate = (TaxRate)ic.lookup(TaxRate.class.getName());
}
catch (NamingException e) {
// some kind of appropriate handling here
}
}
@PreDestroy
public void preDestroy() {
taxRate = null;
}
@AroundInvoke
public Object logger(InvocationContext inv) throws Exception {
System.out.println("Intercepted call via internal method to: "+inv.getMethod().getName());
Object[] params = inv.getParameters();
for (int i=0;i<params.length;i++) {
System.out.println("\tparam: "+params[i]);
}
return inv.proceed();
}
}
|