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"
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)
18 IIOP_Server_Request_Interceptor::name ()
20 return CORBA::string_dup ("II SRI");
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 ());
30 ACE_TCHAR
**tmpargv
= 0;
31 CORBA::ORB_var orb
= CORBA::ORB_init (tmpargc
,
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
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)
60 ACE_TEXT ("%C (%P|%t) ")
61 ACE_TEXT ("push_request_info: %d ...\n"),
67 ACE_TEXT ("%C (%P|%t) ")
68 ACE_TEXT ("push_request_info: Can't track that many requests %d\n"),
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)
81 ACE_TEXT ("%C (%P|%t) ")
82 ACE_TEXT ("pop_request_info: %d ...\n"),
86 if (requestID
>= sizeof (this->endPoints_
) / sizeof (*this->endPoints_
))
89 ACE_TEXT ("%C (%P|%t) ")
90 ACE_TEXT ("pop_request_info: Can't track that many requests %d\n"),
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"),
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
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
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_
));
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"),
148 return Server_Request_Interceptor::self_test ()
149 && iiop_test_successful_
150 && !has_remaining_endpoints
;
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"),
167 IOP::ServiceId id
= Test::Transport::CurrentTest::ContextTag
;
168 IOP::ServiceContext_var sc
=
169 ri
->get_request_service_context (id
);
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"),
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
);
200 reinterpret_cast <const char *> (sc
->context_data
.get_buffer ());
202 this->pop_request_info (ACE_OS::atoi (buf
));
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"),
221 Server_Request_Interceptor::receive_request_service_contexts (ri
);
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"),
240 Server_Request_Interceptor::send_reply (ri
);
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"),
259 Server_Request_Interceptor::send_exception (ri
);
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"),
278 Server_Request_Interceptor::send_other (ri
);