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.omg.BiDirPolicy.BIDIRECTIONAL_POLICY_TYPE; 10 import org.omg.BiDirPolicy.BOTH; 11 import org.omg.BiDirPolicy.BidirectionalPolicyValueHelper; 12 import org.omg.CORBA.Any ; 13 import org.omg.CORBA.ORB ; 14 import org.omg.CORBA.Policy ; 15 import org.omg.PortableServer.IdAssignmentPolicyValue ; 16 import org.omg.PortableServer.ImplicitActivationPolicyValue ; 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 Basic_Client extends PeterPOA { 36 37 private static ORB orb = null; 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 orb = ORB.init(args, null); 48 49 POA rootPOA = (POA ) orb.resolve_initial_references("RootPOA"); 51 Policy [] policies = new Policy [4]; 52 policies[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT); 53 policies[1] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID); 54 policies[2] = rootPOA.create_implicit_activation_policy( ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION ); 55 Any bidirAny = orb.create_any(); 56 BidirectionalPolicyValueHelper.insert( bidirAny, BOTH.value ); 57 policies[3] = orb.create_policy( BIDIRECTIONAL_POLICY_TYPE.value, bidirAny ); 58 POA bidirPOA = rootPOA.create_POA( "BiDirPOA", rootPOA.the_POAManager(), policies ); 59 bidirPOA.the_POAManager().activate(); 60 61 Thread orbThread = new Thread (new Runnable () { 63 public void run() { 64 runORB(); 65 System.out.println("ORB closed"); 66 } 67 }); 68 orbThread.start(); 69 70 Basic_Client server = new Basic_Client(); 72 bidirPOA.activate_object(server); 73 Peter peter = PeterHelper.narrow(bidirPOA.servant_to_reference(server)); 74 PrintWriter pw = new PrintWriter (new FileWriter ("peter.ior")); 75 pw.println(orb.object_to_string(peter)); 76 pw.flush(); 77 pw.close(); 78 79 URL iorURL = new URL (args[0]); 81 System.out.println("Reading object from ior: "+args[0]); 82 BufferedReader br = new BufferedReader (new InputStreamReader (iorURL.openStream())); org.omg.CORBA.Object obj = orb.string_to_object(br.readLine()); 84 br.close(); 85 Johnson johnson = JohnsonHelper.narrow(obj); 86 87 System.out.println("CSS1:"+johnson.say_hello("hello from JacORB")); 89 System.out.println("CSS2:"+johnson.say_hello("hello from JacORB")); 90 System.out.println("TSS1:"+johnson.say_hello_from_you(peter, 1)); 91 System.out.println("TSS2:"+johnson.say_hello_from_you(peter, 1)); 92 93 System.out.println("Call to server succeeded"); 94 } catch (Exception ex) { 95 System.out.println("Error: " + ex + ": " + ex.getMessage()); 96 ex.printStackTrace(); 97 } 98 if (orb != null) orb.shutdown(false); 99 } 100 101 private static void runORB() { 102 orb.run(); 103 } 104 105 108 public String say_hello(String msg) { 109 System.out.println("TSS: "+msg); 110 return "Hello from Peter!\n" + msg; 111 } 112 } 113 | Popular Tags |