blob: abc2da28ffb0dee9188bfa891a41afefe046265c (
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
|
package examples.stateful.client;
import javax.ejb.NoSuchEJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import examples.stateful.interfaces.Cart;
public class CartClient {
public static void main(String[] args) {
try {
InitialContext ic = new InitialContext();
System.out.println("Adding items to cart, then removing...");
for (int i=0;i<2;i++) {
Cart cart = (Cart)ic.lookup(Cart.class.getName());
cart.addItem();
cart.addItem();
System.out.println("Number of items in the cart: "+cart.getItems());
try {
try {
if (i==0) {
cart.remove1();
}
else {
cart.remove2();
}
}
catch (Exception e) {
;
}
cart.addItem();
cart.addItem();
cart.addItem();
System.out.println("Number of items in the cart: "+cart.getItems());
}
catch (NoSuchEJBException nsee) {
System.out.println("Cart was already removed during iteration "+i);
}
}
}
catch (NamingException e) {
e.printStackTrace();
}
}
}
|