1 package org.jacorb.test.sas; 2 3 import java.io.BufferedReader ; 4 import java.io.FileWriter ; 5 import java.io.InputStreamReader ; 6 import java.io.PrintWriter ; 7 import java.net.URL ; 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 ; 14 import org.omg.CORBA.ORB ; 15 import org.omg.CSIIOP.EstablishTrustInClient; 16 import org.omg.PortableServer.IdAssignmentPolicyValue ; 17 import org.omg.PortableServer.LifespanPolicyValue ; 18 import org.omg.PortableServer.POA ; 19 20 import InterOpTest.Johnson; 21 import InterOpTest.JohnsonHelper; 22 import InterOpTest.Peter; 23 import InterOpTest.PeterHelper; 24 import InterOpTest.PeterPOA; 25 26 34 35 public class UP_Client extends PeterPOA { 36 37 private static ORB orb; 38 39 public static void main(String args[]) { 40 if (args.length != 3) { 41 System.out.println("Usage: <ior_file> <username> <password>"); 42 System.exit(1); 43 } 44 45 try { 46 GssUpContext.setUsernamePassword(args[1], args[2]); 48 49 orb = ORB.init(args, null); 51 52 POA rootPOA = (POA ) orb.resolve_initial_references("RootPOA"); 54 org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy [3]; 55 policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID); 56 policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 57 Any 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 securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies); 61 rootPOA.the_POAManager().activate(); 62 63 Thread orbThread = new Thread (new Runnable () { 65 public void run() { 66 runORB(); 67 System.out.println("ORB closed"); 68 } 69 }); 70 orbThread.start(); 71 72 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 demo = securePOA.servant_to_reference(server); 77 PrintWriter pw = new PrintWriter (new FileWriter ("peter.ior")); 78 pw.println(orb.object_to_string(demo)); 79 pw.flush(); 80 pw.close(); 81 82 URL iorURL = new URL (args[0]); 84 System.out.println("Reading object from ior: "+args[0]); 85 BufferedReader br = new BufferedReader (new InputStreamReader (iorURL.openStream())); org.omg.CORBA.Object obj = orb.string_to_object(br.readLine()); 87 br.close(); 88 Johnson johnson = JohnsonHelper.narrow(obj); 89 90 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 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 110 public String say_hello(String msg) { 111 return "Hello from Peter!\n" + msg; 112 } 113 } 114 | Popular Tags |