Professional Documents
Culture Documents
Objectives
Ver. 1.0
Slide 1 of 30
Ver. 1.0
Slide 2 of 30
Ver. 1.0
Slide 3 of 30
Ver. 1.0
Slide 4 of 30
Ver. 1.0
Slide 5 of 30
Ver. 1.0
@Stateless
public class AccountManagementBean implements
AccountManagement {
public void createAccount(int accountNumber,
AccountDetails details) { ... }
public void deleteAccount(int accountNumber) { ... }
public void activateAccount(int accountNumber) { ...
public void deactivateAccount(int accountNumber) {
... }
Slide 6 of 30
12
13
14
15
16
17
18
19
Ver. 1.0
try {
return inv.proceed(); }
finally {
long diffTime = time - System.currentTimeMillis();
System.out.println(inv.getMethod() + " took " +
diffTime + " milliseconds.");
}
}
Slide 7 of 30
Ver. 1.0
Slide 8 of 30
@Stateless
@Interceptors({
com.acme.AccountAudit.class,
})
public class AccountManagementBean implements
AccountManagement {
6
public void createAccount(int accountNumber,
7
AccountDetails details) { ... }
8
public void deleteAccount(int accountNumber) { ...
}
9
public void activateAccount(int accountNumber) {
... }
10 public void deactivateAccount(int accountNumber) {
...}
Ver. 1.0
Slide 9 of 30
Slide 10 of 30
Ver. 1.0
Slide 11 of 30
@Stateless
@Interceptors({
com.acme.AccountAudit.class,
com.acme.CustomSecurity.class
})
public class AccountManagementBean implements
AccountManagement {
7
public void createAccount(int accountNumber,
8
AccountDetails details) { ... }
9
public void deleteAccount(int accountNumber) { ...
}
10 public void activateAccount(int accountNumber) {
... }
Ver. 1.0
Slide 12 of 30
11
12
13 @AroundInvoke public Object
profile(InvocationContext
inv)
14 throws Exception {
15 long time = System.currentTimeMillis();
16 try {
17
return inv.proceed(); }
18 finally {
19
long diffTime = time System.currentTimeMillis();
20
System.out.println(inv.getMethod() + " took " +
diffTime + "21 milliseconds.");
22
}
Ver. 1.0
Slide 13 of 30
23 }
24 }
25
26 public class AccountAudit {
27 @AroundInvoke public Object auditAccountOperation
28
(InvocationContext inv) throws Exception {
29
try {
30
Object result = inv.proceed();
31
Auditor.audit(inv.getMethod().getName(),
32
inv.getParameters()[0]);
33
return result;
34
} catch (Exception ex) {
35
Auditor.auditFailure(ex);
36
throw ex;
37
}
38 }
Ver. 1.0
Slide 14 of 30
39 }
40
41 public class CustomSecurity {
42 @AroundInvoke public Object
customSecurity(InvocationContext inv)
43
throws Exception {
44
doCustomSecurityCheck(inv.getEJBContext().
getCallerPrincipal());
45
return inv.proceed();
46 }
47 private void doCustomSecurityCheck(Principal
caller)
48 throws SecurityException {
49 //...
50 }
51 }
Ver. 1.0
Slide 15 of 30
Ver. 1.0
Slide 16 of 30
Ver. 1.0
PostConstruct
PreDestroy
PostActivate
PreActivate
Slide 17 of 30
Ver. 1.0
Slide 18 of 30
Ver. 1.0
Slide 19 of 30
Ver. 1.0
Slide 20 of 30
Ver. 1.0
Slide 21 of 30
Ver. 1.0
Slide 22 of 30
Ver. 1.0
Slide 23 of 30
Ver. 1.0
Slide 24 of 30
Ver. 1.0
Slide 25 of 30
4.
Ver. 1.0
Slide 26 of 30
Ver. 1.0
Slide 27 of 30
Ver. 1.0
Slide 28 of 30
Ver. 1.0
Slide 29 of 30
Ver. 1.0
Slide 30 of 30