Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / TransportCurrent / IIOP / IIOP_Server_Request_Interceptor.cpp
blob4e1a630dd0657a6a9b15052dbe71bae71d28b2ab
1 // -*- C++ -*-
2 #include "ace/Log_Msg.h"
3 #include "tao/ORB_Constants.h"
4 #include "tao/TransportCurrent/TC_IIOPC.h"
6 #include "IIOP_Server_Request_Interceptor.h"
8 namespace Test {
10 using namespace TAO;
12 IIOP_Server_Request_Interceptor::IIOP_Server_Request_Interceptor (const char* orbid, TEST test)
13 : Server_Request_Interceptor (orbid, test)
14 , iiop_test_successful_ (true)
15 , mult_thr_test_successful_ (true)
19 IIOP_Server_Request_Interceptor::~IIOP_Server_Request_Interceptor (void)
23 char *
24 IIOP_Server_Request_Interceptor::name (void)
26 return CORBA::string_dup ("II SRI");
29 ///
30 TAO::Transport::IIOP::Current_ptr
31 IIOP_Server_Request_Interceptor::resolve_iiop_transport_current (const char* orbid)
33 CORBA::String_var name (this->name ());
35 int tmpargc = 0;
36 ACE_TCHAR **tmpargv = 0;
37 CORBA::ORB_var orb = CORBA::ORB_init (tmpargc,
38 tmpargv,
39 orbid);
41 CORBA::Object_var tcobject =
42 orb->resolve_initial_references ("TAO::Transport::IIOP::Current");
44 return TAO::Transport::IIOP::Current::_narrow (tcobject.in ());
47 /// On every request, a client-supplied (via the context) id is used
48 /// as index in an array, where we store the endpoint
49 void
50 IIOP_Server_Request_Interceptor::push_request_info (size_t requestID)
52 CORBA::String_var name (this->name ());
54 TAO::Transport::IIOP::Current_var tc =
55 resolve_iiop_transport_current (this->orb_id_.in ());
57 CORBA::String_var host (tc->remote_host());
58 EndPoint ep (tc->remote_port(), host.in ());
60 if (requestID < sizeof (this->endPoints_) / sizeof (*this->endPoints_))
62 endPoints_[requestID] = ep;
64 if (TAO_debug_level > 1)
65 ACE_DEBUG ((LM_DEBUG,
66 ACE_TEXT ("%C (%P|%t) ")
67 ACE_TEXT ("push_request_info: %d ...\n"),
68 name.in (),
69 requestID));
71 else
72 ACE_ERROR ((LM_ERROR,
73 ACE_TEXT ("%C (%P|%t) ")
74 ACE_TEXT ("push_request_info: Can't track that many requests %d\n"),
75 name.in (),
76 requestID));
80 void
81 IIOP_Server_Request_Interceptor::pop_request_info (size_t requestID)
83 static EndPoint dummy;
84 CORBA::String_var name (this->name ());
86 if (TAO_debug_level > 1)
87 ACE_DEBUG ((LM_DEBUG,
88 ACE_TEXT ("%C (%P|%t) ")
89 ACE_TEXT ("pop_request_info: %d ...\n"),
90 name.in (),
91 requestID));
93 if (requestID >= sizeof (this->endPoints_) / sizeof (*this->endPoints_))
95 ACE_ERROR ((LM_ERROR,
96 ACE_TEXT ("%C (%P|%t) ")
97 ACE_TEXT ("pop_request_info: Can't track that many requests %d\n"),
98 name.in (),
99 requestID));
100 return;
105 TAO::Transport::IIOP::Current_var tc =
106 resolve_iiop_transport_current (this->orb_id_.in ());
108 CORBA::String_var host (tc->remote_host());
109 EndPoint ep (tc->remote_port(), host.in ());
111 if (ep != endPoints_[requestID])
113 ACE_ERROR ((LM_ERROR,
114 ACE_TEXT ("%C (%P|%t) ")
115 ACE_TEXT ("pop_request_info: The expected host and port don't match for request %d\n"),
116 name.in (),
117 requestID));
118 return;
121 catch (const CORBA::BAD_INV_ORDER& )
123 // Last reply after the orb has been shut down. Calling
124 // resolve_iiop_transport_current in this case will cause
125 // BAD_INV_ORDER, so instead we swallow the exception and bid
126 // goodbye.
129 endPoints_[requestID] = dummy;
133 /// Checks if all the endpoints, encountered on the way in have been
134 /// cleaned on the way out of the interception point
135 bool
136 IIOP_Server_Request_Interceptor::self_test (void)
138 CORBA::String_var name (this->name ());
139 bool has_remaining_endpoints = false;
140 for (size_t count = 0;
141 count < (sizeof (this->endPoints_) / sizeof (*this->endPoints_));
142 count ++)
144 if (endPoints_[count].port_ != 0)
146 has_remaining_endpoints = true;
147 ACE_ERROR ((LM_ERROR,
148 ACE_TEXT ("%C (%P|%t) Endpoint at ")
149 ACE_TEXT ("index=%d has not been removed yet\n"),
150 name.in (),
151 count));
155 return Server_Request_Interceptor::self_test ()
156 && iiop_test_successful_
157 && !has_remaining_endpoints;
160 void
161 IIOP_Server_Request_Interceptor::inbound_process_context (PortableInterceptor::ServerRequestInfo_ptr ri)
163 CORBA::String_var name (this->name ());
164 CORBA::String_var op (ri->operation());
166 if (TAO_debug_level >=1)
167 ACE_DEBUG ((LM_DEBUG,
168 ACE_TEXT("%C (%P|%t) Intercepted operation %C ()\n"),
169 name.in (),
170 op.in ()));
174 IOP::ServiceId id = Test::Transport::CurrentTest::ContextTag;
175 IOP::ServiceContext_var sc =
176 ri->get_request_service_context (id);
178 const char *buf =
179 reinterpret_cast <const char *> (sc->context_data.get_buffer ());
181 long requestID = ACE_OS::atoi (buf);
183 this->push_request_info (requestID);
185 catch (const CORBA::Exception&)
187 ACE_DEBUG ((LM_DEBUG,
188 ACE_TEXT ("%C (%P|%t) Service context")
189 ACE_TEXT (" is unavailable when invoking %C (). ")
190 ACE_TEXT ("A colocated invocation would have ")
191 ACE_TEXT ("no service context.\n"),
192 name.in (),
193 op.in ()));
198 void
199 IIOP_Server_Request_Interceptor::outbound_process_context (PortableInterceptor::ServerRequestInfo_ptr ri)
201 IOP::ServiceId id = Test::Transport::CurrentTest::ContextTag;
203 IOP::ServiceContext_var sc =
204 ri->get_request_service_context (id);
206 const char *buf =
207 reinterpret_cast <const char *> (sc->context_data.get_buffer ());
209 this->pop_request_info (ACE_OS::atoi (buf));
212 void
213 IIOP_Server_Request_Interceptor::receive_request_service_contexts (PortableInterceptor::ServerRequestInfo_ptr ri)
217 inbound_process_context (ri);
219 catch (const CORBA::Exception&)
221 CORBA::String_var name (this->name ());
222 ACE_ERROR ((LM_ERROR,
223 ACE_TEXT("%C (%P|%t) Inbound_process_context failed in ")
224 ACE_TEXT(" receive_request_service_contexts.\n"),
225 name.in ()));
228 Server_Request_Interceptor::receive_request_service_contexts (ri);
232 void
233 IIOP_Server_Request_Interceptor::send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
237 outbound_process_context (ri);
240 catch (const CORBA::Exception&)
242 CORBA::String_var name (this->name ());
243 ACE_ERROR ((LM_ERROR,
244 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
245 ACE_TEXT("send_reply.\n"),
246 name.in ()));
249 Server_Request_Interceptor::send_reply (ri);
253 void
254 IIOP_Server_Request_Interceptor::send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
258 outbound_process_context (ri);
262 catch (const CORBA::Exception&)
264 CORBA::String_var name (this->name ());
265 ACE_ERROR ((LM_ERROR,
266 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
267 ACE_TEXT("send_exception.\n"),
268 name.in ()));
272 Server_Request_Interceptor::send_exception (ri);
275 void
276 IIOP_Server_Request_Interceptor::send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
280 outbound_process_context (ri);
282 catch (const CORBA::Exception&)
284 CORBA::String_var name (this->name ());
285 ACE_ERROR ((LM_ERROR,
286 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
287 ACE_TEXT("send_other.\n"),
288 name.in ()));
291 Server_Request_Interceptor::send_other (ri);