Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / TransportCurrent / IIOP / IIOP_Server_Request_Interceptor.cpp
blob0411ed36200217b426ba097993d17766c3f896e3
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 {
9 using namespace TAO;
11 IIOP_Server_Request_Interceptor::IIOP_Server_Request_Interceptor (const char* orbid, TEST test)
12 : Server_Request_Interceptor (orbid, test)
13 , iiop_test_successful_ (true)
17 char *
18 IIOP_Server_Request_Interceptor::name ()
20 return CORBA::string_dup ("II SRI");
23 ///
24 TAO::Transport::IIOP::Current_ptr
25 IIOP_Server_Request_Interceptor::resolve_iiop_transport_current (const char* orbid)
27 CORBA::String_var name (this->name ());
29 int tmpargc = 0;
30 ACE_TCHAR **tmpargv = 0;
31 CORBA::ORB_var orb = CORBA::ORB_init (tmpargc,
32 tmpargv,
33 orbid);
35 CORBA::Object_var tcobject =
36 orb->resolve_initial_references ("TAO::Transport::IIOP::Current");
38 return TAO::Transport::IIOP::Current::_narrow (tcobject.in ());
41 /// On every request, a client-supplied (via the context) id is used
42 /// as index in an array, where we store the endpoint
43 void
44 IIOP_Server_Request_Interceptor::push_request_info (size_t requestID)
46 CORBA::String_var name (this->name ());
48 TAO::Transport::IIOP::Current_var tc =
49 resolve_iiop_transport_current (this->orb_id_.in ());
51 CORBA::String_var host (tc->remote_host());
52 EndPoint ep (tc->remote_port(), host.in ());
54 if (requestID < sizeof (this->endPoints_) / sizeof (*this->endPoints_))
56 endPoints_[requestID] = ep;
58 if (TAO_debug_level > 1)
59 ACE_DEBUG ((LM_DEBUG,
60 ACE_TEXT ("%C (%P|%t) ")
61 ACE_TEXT ("push_request_info: %d ...\n"),
62 name.in (),
63 requestID));
65 else
66 ACE_ERROR ((LM_ERROR,
67 ACE_TEXT ("%C (%P|%t) ")
68 ACE_TEXT ("push_request_info: Can't track that many requests %d\n"),
69 name.in (),
70 requestID));
73 void
74 IIOP_Server_Request_Interceptor::pop_request_info (size_t requestID)
76 static EndPoint dummy;
77 CORBA::String_var name (this->name ());
79 if (TAO_debug_level > 1)
80 ACE_DEBUG ((LM_DEBUG,
81 ACE_TEXT ("%C (%P|%t) ")
82 ACE_TEXT ("pop_request_info: %d ...\n"),
83 name.in (),
84 requestID));
86 if (requestID >= sizeof (this->endPoints_) / sizeof (*this->endPoints_))
88 ACE_ERROR ((LM_ERROR,
89 ACE_TEXT ("%C (%P|%t) ")
90 ACE_TEXT ("pop_request_info: Can't track that many requests %d\n"),
91 name.in (),
92 requestID));
93 return;
96 try
98 TAO::Transport::IIOP::Current_var tc =
99 resolve_iiop_transport_current (this->orb_id_.in ());
101 CORBA::String_var host (tc->remote_host());
102 EndPoint ep (tc->remote_port(), host.in ());
104 if (ep != endPoints_[requestID])
106 ACE_ERROR ((LM_ERROR,
107 ACE_TEXT ("%C (%P|%t) ")
108 ACE_TEXT ("pop_request_info: The expected host and port don't match for request %d\n"),
109 name.in (),
110 requestID));
111 return;
114 catch (const CORBA::BAD_INV_ORDER& )
116 // Last reply after the orb has been shut down. Calling
117 // resolve_iiop_transport_current in this case will cause
118 // BAD_INV_ORDER, so instead we swallow the exception and bid
119 // goodbye.
122 endPoints_[requestID] = dummy;
126 /// Checks if all the endpoints, encountered on the way in have been
127 /// cleaned on the way out of the interception point
128 bool
129 IIOP_Server_Request_Interceptor::self_test ()
131 CORBA::String_var name (this->name ());
132 bool has_remaining_endpoints = false;
133 for (size_t count = 0;
134 count < (sizeof (this->endPoints_) / sizeof (*this->endPoints_));
135 count ++)
137 if (endPoints_[count].port_ != 0)
139 has_remaining_endpoints = true;
140 ACE_ERROR ((LM_ERROR,
141 ACE_TEXT ("%C (%P|%t) Endpoint at ")
142 ACE_TEXT ("index=%d has not been removed yet\n"),
143 name.in (),
144 count));
148 return Server_Request_Interceptor::self_test ()
149 && iiop_test_successful_
150 && !has_remaining_endpoints;
153 void
154 IIOP_Server_Request_Interceptor::inbound_process_context (PortableInterceptor::ServerRequestInfo_ptr ri)
156 CORBA::String_var name (this->name ());
157 CORBA::String_var op (ri->operation());
159 if (TAO_debug_level >=1)
160 ACE_DEBUG ((LM_DEBUG,
161 ACE_TEXT("%C (%P|%t) Intercepted operation %C ()\n"),
162 name.in (),
163 op.in ()));
167 IOP::ServiceId id = Test::Transport::CurrentTest::ContextTag;
168 IOP::ServiceContext_var sc =
169 ri->get_request_service_context (id);
171 const char *buf =
172 reinterpret_cast <const char *> (sc->context_data.get_buffer ());
174 long requestID = ACE_OS::atoi (buf);
176 this->push_request_info (requestID);
178 catch (const CORBA::Exception&)
180 ACE_DEBUG ((LM_DEBUG,
181 ACE_TEXT ("%C (%P|%t) Service context")
182 ACE_TEXT (" is unavailable when invoking %C (). ")
183 ACE_TEXT ("A colocated invocation would have ")
184 ACE_TEXT ("no service context.\n"),
185 name.in (),
186 op.in ()));
191 void
192 IIOP_Server_Request_Interceptor::outbound_process_context (PortableInterceptor::ServerRequestInfo_ptr ri)
194 IOP::ServiceId id = Test::Transport::CurrentTest::ContextTag;
196 IOP::ServiceContext_var sc =
197 ri->get_request_service_context (id);
199 const char *buf =
200 reinterpret_cast <const char *> (sc->context_data.get_buffer ());
202 this->pop_request_info (ACE_OS::atoi (buf));
205 void
206 IIOP_Server_Request_Interceptor::receive_request_service_contexts (PortableInterceptor::ServerRequestInfo_ptr ri)
210 inbound_process_context (ri);
212 catch (const CORBA::Exception&)
214 CORBA::String_var name (this->name ());
215 ACE_ERROR ((LM_ERROR,
216 ACE_TEXT("%C (%P|%t) Inbound_process_context failed in ")
217 ACE_TEXT(" receive_request_service_contexts.\n"),
218 name.in ()));
221 Server_Request_Interceptor::receive_request_service_contexts (ri);
224 void
225 IIOP_Server_Request_Interceptor::send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
229 outbound_process_context (ri);
231 catch (const CORBA::Exception&)
233 CORBA::String_var name (this->name ());
234 ACE_ERROR ((LM_ERROR,
235 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
236 ACE_TEXT("send_reply.\n"),
237 name.in ()));
240 Server_Request_Interceptor::send_reply (ri);
243 void
244 IIOP_Server_Request_Interceptor::send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
248 outbound_process_context (ri);
250 catch (const CORBA::Exception&)
252 CORBA::String_var name (this->name ());
253 ACE_ERROR ((LM_ERROR,
254 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
255 ACE_TEXT("send_exception.\n"),
256 name.in ()));
259 Server_Request_Interceptor::send_exception (ri);
262 void
263 IIOP_Server_Request_Interceptor::send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
267 outbound_process_context (ri);
269 catch (const CORBA::Exception&)
271 CORBA::String_var name (this->name ());
272 ACE_ERROR ((LM_ERROR,
273 ACE_TEXT("%C (%P|%t) Outbound_process_context failed in ")
274 ACE_TEXT("send_other.\n"),
275 name.in ()));
278 Server_Request_Interceptor::send_other (ri);