KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > sas > UP_Client


1 package org.jacorb.test.sas;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.FileWriter JavaDoc;
5 import java.io.InputStreamReader JavaDoc;
6 import java.io.PrintWriter JavaDoc;
7 import java.net.URL JavaDoc;
8
9 import org.jacorb.sasPolicy.SASPolicyValues;
10 import org.jacorb.sasPolicy.SASPolicyValuesHelper;
11 import org.jacorb.sasPolicy.SAS_POLICY_TYPE;
12 import org.jacorb.security.sas.GssUpContext;
13 import org.omg.CORBA.Any JavaDoc;
14 import org.omg.CORBA.ORB JavaDoc;
15 import org.omg.CSIIOP.EstablishTrustInClient;
16 import org.omg.PortableServer.IdAssignmentPolicyValue JavaDoc;
17 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
18 import org.omg.PortableServer.POA JavaDoc;
19
20 import InterOpTest.Johnson;
21 import InterOpTest.JohnsonHelper;
22 import InterOpTest.Peter;
23 import InterOpTest.PeterHelper;
24 import InterOpTest.PeterPOA;
25
26 /**
27  * This is the client side of the sas demo. It just calls the single
28  * operation "printCert()" of the server. As you can see, sas is fully
29  * transparent.
30  *
31  * @author Nicolas Noffke
32  * @version $Id: UP_Client.java,v 1.2 2004/03/16 17:55:40 david.robison Exp $
33  */

34
35 public class UP_Client extends PeterPOA {
36
37     private static ORB JavaDoc orb;
38     
39     public static void main(String JavaDoc args[]) {
40         if (args.length != 3) {
41             System.out.println("Usage: <ior_file> <username> <password>");
42             System.exit(1);
43         }
44
45         try {
46             // set security credentials
47
GssUpContext.setUsernamePassword(args[1], args[2]);
48
49             // initialize the ORB.
50
orb = ORB.init(args, null);
51             
52             // initialize the POA
53
POA JavaDoc rootPOA = (POA JavaDoc) orb.resolve_initial_references("RootPOA");
54             org.omg.CORBA.Policy JavaDoc [] policies = new org.omg.CORBA.Policy JavaDoc[3];
55             policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
56             policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
57             Any JavaDoc sasAny = orb.create_any();
58             SASPolicyValuesHelper.insert( sasAny, new SASPolicyValues(EstablishTrustInClient.value, EstablishTrustInClient.value, true) );
59             policies[2] = orb.create_policy(SAS_POLICY_TYPE.value, sasAny);
60             POA JavaDoc securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies);
61             rootPOA.the_POAManager().activate();
62             
63             // run the ORB
64
Thread JavaDoc orbThread = new Thread JavaDoc(new Runnable JavaDoc() {
65                 public void run() {
66                     runORB();
67                     System.out.println("ORB closed");
68                 }
69             });
70             orbThread.start();
71
72             // create peter and write his IOR
73
UP_Client server = new UP_Client();
74             securePOA.activate_object_with_id("SecurePeter".getBytes(), server);
75             Peter peter = PeterHelper.narrow(rootPOA.servant_to_reference(server));
76             org.omg.CORBA.Object JavaDoc demo = securePOA.servant_to_reference(server);
77             PrintWriter JavaDoc pw = new PrintWriter JavaDoc(new FileWriter JavaDoc("peter.ior"));
78             pw.println(orb.object_to_string(demo));
79             pw.flush();
80             pw.close();
81
82             // get the server
83
URL JavaDoc iorURL = new URL JavaDoc(args[0]);
84             System.out.println("Reading object from ior: "+args[0]);
85             BufferedReader JavaDoc br = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(iorURL.openStream()));//new FileReader(f));
86
org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(br.readLine());
87             br.close();
88             Johnson johnson = JohnsonHelper.narrow(obj);
89             
90             // call
91
System.out.println("CSS1:"+johnson.say_hello("hello from JacORB"));
92             System.out.println("CSS2:"+johnson.say_hello("hello from JacORB"));
93             System.out.println("TSS1:"+johnson.say_hello_from_you(peter, 1));
94             System.out.println("TSS2:"+johnson.say_hello_from_you(peter, 1));
95
96             System.out.println("Call to server succeeded");
97         } catch (Exception JavaDoc ex) {
98             ex.printStackTrace();
99         }
100         if (orb != null) orb.shutdown(false);
101     }
102     
103     private static void runORB() {
104         orb.run();
105     }
106
107     /* (non-Javadoc)
108      * @see InterOpTest.PeterOperations#say_hello(java.lang.String)
109      */

110     public String JavaDoc say_hello(String JavaDoc msg) {
111         return "Hello from Peter!\n" + msg;
112     }
113 }
114
Popular Tags