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"
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)
24 IIOP_Server_Request_Interceptor::name (void)
26 return CORBA::string_dup ("II SRI");
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 ());
36 ACE_TCHAR
**tmpargv
= 0;
37 CORBA::ORB_var orb
= CORBA::ORB_init (tmpargc
,
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
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)
66 ACE_TEXT ("%C (%P|%t) ")
67 ACE_TEXT ("push_request_info: %d ...\n"),
73 ACE_TEXT ("%C (%P|%t) ")
74 ACE_TEXT ("push_request_info: Can't track that many requests %d\n"),
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)
88 ACE_TEXT ("%C (%P|%t) ")
89 ACE_TEXT ("pop_request_info: %d ...\n"),
93 if (requestID
>= sizeof (this->endPoints_
) / sizeof (*this->endPoints_
))
96 ACE_TEXT ("%C (%P|%t) ")
97 ACE_TEXT ("pop_request_info: Can't track that many requests %d\n"),
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"),
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
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
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_
));
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"),
155 return Server_Request_Interceptor::self_test ()
156 && iiop_test_successful_
157 && !has_remaining_endpoints
;
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"),
174 IOP::ServiceId id
= Test::Transport::CurrentTest::ContextTag
;
175 IOP::ServiceContext_var sc
=
176 ri
->get_request_service_context (id
);
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"),
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
);
207 reinterpret_cast <const char *> (sc
->context_data
.get_buffer ());
209 this->pop_request_info (ACE_OS::atoi (buf
));
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"),
228 Server_Request_Interceptor::receive_request_service_contexts (ri
);
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"),
249 Server_Request_Interceptor::send_reply (ri
);
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"),
272 Server_Request_Interceptor::send_exception (ri
);
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"),
291 Server_Request_Interceptor::send_other (ri
);