1
5 package org.jyperion.j2ee.sample.sfsb.client;
6
7 import java.util.Iterator;
8 import java.util.List;
9
10import javax.naming.InitialContext;
11import javax.security.auth.login.LoginContext;
12import javax.security.auth.login.LoginException;
13
14import org.jyperion.j2ee.sample.sfsb.Cart;
15import org.jyperion.j2ee.sample.sfsb.CartHome;
16
17
21public class JbossCartClient {
22
27 public static void main(String[] args) throws Exception {
28 String username = args[0];
29 String password = args[1];
30
31 doLogin(username, password);
33
34
38 InitialContext lContext = new InitialContext();
39 System.out.println("Got initial context: " + lContext);
40
41 CartHome lHome =
42 (CartHome) lContext.lookup(
43 "org.jyperion.sample.sessionbean.CartBean");
44 System.out.println("Got CartHome: " + lHome);
45
46 Cart cart = null;
47
48 try {
49 cart = lHome.create();
50 } catch (Exception e) {
51 Throwable t = e.getCause();
52 System.err.println("Exception lors du create sur CartHome: " + t.getLocalizedMessage());
53 }
54
55 cart.addBook("Apres l'Empire");
57 cart.addBook("L'Illusion economique");
58 cart.addBook("Le langage silencieux");
59 cart.addBook("Hyperion");
60 List livres = cart.getContent();
62
63 Iterator it = livres.iterator();
64 int i = 1;
65 while (it.hasNext()) {
66 String book = (String) it.next();
67 System.out.println("Livre numero " + (i++) + ": " + book);
68 }
69
70 cart.remove();
71 }
72
73 private static void doLogin(String username, String password) {
74 System.out.println("--> doLogin");
75
76 UPCallbackHandler upCallbackHandler = new UPCallbackHandler(username, password);
77 try {
78 LoginContext loginContext = new LoginContext("HyperionSec", upCallbackHandler);
79 loginContext.login();
80 System.out.println("Successful login");
81 } catch (LoginException e) {
82 e.printStackTrace();
83 System.err.println("Login failed!");
84 }
85 }
86}
87