Merge pull request #2317 from jwillemsen/jwi-deleteop
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / Callback / client.cpp
blobfcbdaf63893fb74962b85dc07f823c04eee2f8cd
1 #include "ace/Log_Msg.h"
2 #include "serverC.h"
3 #include "client_i.h"
4 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior = ACE_TEXT ("file://server.ior");
8 const ACE_TCHAR *cert_file = ACE_TEXT ("cacert.pem");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-k <ior> "
28 "\n",
29 argv [0]),
30 -1);
32 // Indicates successful parsing of the command line
33 return 0;
36 int
37 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
39 try
41 ACE_TString env (ACE_TEXT ("SSL_CERT_FILE="));
42 env += cert_file;
43 ACE_OS::putenv ( ACE_TEXT_ALWAYS_CHAR(env.c_str ()));
46 // Initialize the ORB
48 CORBA::ORB_var orb =
49 CORBA::ORB_init (argc, argv);
51 if (parse_args (argc, argv) != 0)
52 return 1;
55 // Get the Root POA.
57 CORBA::Object_var obj =
58 orb->resolve_initial_references ("RootPOA");
60 PortableServer::POA_var poa =
61 PortableServer::POA::_narrow (obj.in ());
64 // Get a reference to the server.
66 obj = orb->string_to_object (ior);
68 if (CORBA::is_nil (obj.in ()))
70 ACE_ERROR_RETURN ((LM_ERROR,
71 ACE_TEXT ("(%P) orb->string_to_object ")
72 ACE_TEXT ("(\"file://server.ior\") failed.\n")),
73 -1);
77 // Downcast the IOR to the appropriate object type.
79 server_var server_obj =
80 server::_narrow (obj.in ());
82 if (CORBA::is_nil (server_obj.in ()))
84 ACE_ERROR_RETURN ((LM_ERROR,
85 ACE_TEXT ("(%P) server::_narrow(obj) failed.\n")),
86 -1);
90 // Create and activate the client.
92 client_i *servant = 0;
93 ACE_NEW_RETURN (servant,
94 client_i (server_obj.in ()),
95 -1);
96 PortableServer::ServantBase_var theClient = servant;
98 client_var client_ref = servant->_this ();
101 // Activate the POA manager.
103 PortableServer::POAManager_var mgr =
104 poa->the_POAManager ();
106 mgr->activate ();
109 // Set the server's callback and invoke the test request.
111 server_obj->set_client (client_ref.in ());
113 server_obj->test_request ("first secure callback to client");
116 // Repeat the callback test.
118 server_obj->set_client (client_ref.in ());
119 server_obj->test_request ("second secure callback to client");
121 server_obj->shutdown ();
123 poa->destroy (true, true);
125 orb->destroy ();
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception (ACE_TEXT ("Caught exception\n"));
131 return -1;
134 return 0;