1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.client;
18
19 import java.util.HashMap;
20 import java.util.Hashtable;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import javax.ejb.NoSuchEJBException;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28
29 import org.jboss.as.quickstarts.sfsb.ShoppingCart;
30 import org.jboss.as.quickstarts.sfsb.ShoppingCartBean;
31
32 public class Client {
33
34 private static final String SOAP = "JBoss SOA Platform 6";
35 private static final String EAP = "Red Hat JBoss Enterprise Application Platform 6";
36
37 public static void main(String[] args) throws NamingException {
38
39 Logger.getLogger("org.xnio").setLevel(Level.WARNING);
40 Logger.getLogger("org.jboss.remoting").setLevel(Level.WARNING);
41 Logger.getLogger("org.jboss.ejb.client").setLevel(Level.WARNING);
42
43
44 Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
45 jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
46 final Context context = new InitialContext(jndiProperties);
47
48
49
50
51
52
53 final String appName = "";
54
55
56
57
58
59
60 final String moduleName = "jboss-shopping-cart-server";
61
62
63
64
65
66 final String distinctName = "";
67
68
69
70
71 final String beanName = ShoppingCartBean.class.getSimpleName();
72
73
74 final String viewClassName = ShoppingCart.class.getName();
75
76
77 String lookupName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName
78 + "?stateful";
79 final ShoppingCart cart = (ShoppingCart) context.lookup(lookupName);
80
81 System.out.println("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
82 System.out.println("Obtained the remote interface to the shopping cart");
83
84
85 System.out.println("Buying a \"" + EAP + "\"");
86 cart.buy(EAP, 1);
87 System.out.println("Buying another \"" + EAP + "\"");
88 cart.buy(EAP, 1);
89
90 System.out.println("Buying a \"" + SOAP + "\"");
91 cart.buy(SOAP, 1);
92
93 System.out.println("\nPrint cart:");
94 HashMap<String, Integer> cartContents = cart.getCartContents();
95 for (String product : cartContents.keySet()) {
96 System.out.println(cartContents.get(product) + " " + product);
97 }
98
99 System.out.println("\nCheckout");
100 cart.checkout();
101
102
103 try {
104 cart.getCartContents();
105 System.err.println("ERROR: The cart should not be available after Checkout!");
106 } catch (NoSuchEJBException e) {
107 System.out.println("Cart was correctly removed, as expected, after Checkout and is no longer available!");
108 }
109 System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
110 }
111 }