2 #include "ServerRequestInterceptor.h"
3 #include "tao/CORBA_String.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
7 ServerRequestInterceptor::ServerRequestInterceptor (
8 PortableInterceptor::SlotId id
,
9 PortableInterceptor::Current_ptr pi_current
)
11 pi_current_ (PortableInterceptor::Current::_duplicate (pi_current
))
16 ServerRequestInterceptor::name (void)
18 return CORBA::string_dup ("ServerRequestInterceptor");
22 ServerRequestInterceptor::destroy (void)
27 ServerRequestInterceptor::receive_request_service_contexts (
28 PortableInterceptor::ServerRequestInfo_ptr ri
)
31 CORBA::String_var op
= ri
->operation ();
33 if (ACE_OS::strcmp (op
.in (), "invoke_me") != 0)
34 return; // Don't mess with PICurrent if not invoking test method.
38 // Insert data into the RSC (request scope current).
40 CORBA::Long number
= 62;
45 ri
->set_slot (this->slot_id_
, data
);
48 "(%P|%t) Inserted number <%d> into RSC.\n",
51 catch (const PortableInterceptor::InvalidSlot
& ex
)
53 ex
._tao_print_exception (
54 "Exception thrown in ""receive_request_service_contexts()\n");
60 throw CORBA::INTERNAL ();
65 ServerRequestInterceptor::receive_request (
66 PortableInterceptor::ServerRequestInfo_ptr ri
)
71 CORBA::Long number
= 19;
74 // Set a value in RSC, this should not effect TSC anymore
75 ri
->set_slot (this->slot_id_
,
78 // Now retrieve the data from the TSC again. It should not have
79 // changed to the new value
80 CORBA::Any_var data2
=
81 this->pi_current_
->get_slot (this->slot_id_
);
83 CORBA::Long number2
= 0;
84 if ((data2
.in () >>= number2
)
88 "(%P|%t) ERROR: TSC was modified because "
89 "RSC was modified.\n"));
91 throw CORBA::INTERNAL ();
94 catch (const PortableInterceptor::InvalidSlot
& ex
)
96 ex
._tao_print_exception ("Exception thrown in ""send_reply()\n");
102 throw CORBA::INTERNAL ();
106 "(%P|%t) Server side RSC/TSC semantics appear "
107 "to be correct.\n"));
112 ServerRequestInterceptor::send_reply (
113 PortableInterceptor::ServerRequestInfo_ptr ri
)
116 CORBA::String_var op
= ri
->operation ();
118 if (ACE_OS::strcmp (op
.in (), "invoke_me") != 0)
119 return; // Don't mess with PICurrent if not invoking test method.
125 // Retrieve the data stored in the RSC. This data (a string)
126 // should be different from the original data (a CORBA::Long)
127 // stored into the RSC by the receive_request_service_contexts()
128 // interception point.
129 data
= ri
->get_slot (this->slot_id_
);
131 // The original data in the RSC was of type CORBA::Long. If the
132 // following extraction from the CORBA::Any fails, then the
133 // original data in the RSC was not replaced with the data in
134 // the TSC after the test method completed.
136 if (data
.in () >>= str
)
138 ACE_DEBUG ((LM_DEBUG
,
139 "(%P|%t) Retrieved \"%s\" from the RSC.\n",
144 ACE_DEBUG ((LM_DEBUG
,
145 "(%P|%t) Unable to extract data (a string) "
148 throw CORBA::INTERNAL ();
151 // Now verify that the RSC is truly independent of the TSC. In
152 // particular, modifying the TSC at this point should not cause
153 // the RSC to be modified.
155 CORBA::Long number
= 19;
159 // Now reset the contents of our slot in the thread-scope
161 this->pi_current_
->set_slot (this->slot_id_
,
164 // Now retrieve the data from the RSC again. It should not have
166 CORBA::Any_var data2
=
167 ri
->get_slot (this->slot_id_
);
169 const char *str2
= 0;
170 if (!(data2
.in () >>= str2
)
171 || ACE_OS::strcmp (str
, str2
) != 0)
173 ACE_ERROR ((LM_ERROR
,
174 "(%P|%t) ERROR: RSC was modified after "
175 "TSC was modified.\n"));
177 throw CORBA::INTERNAL ();
180 catch (const PortableInterceptor::InvalidSlot
& ex
)
182 ex
._tao_print_exception ("Exception thrown in ""send_reply()\n");
184 ACE_DEBUG ((LM_DEBUG
,
185 "Invalid slot: %u\n",
188 throw CORBA::INTERNAL ();
192 "(%P|%t) Server side RSC/TSC semantics appear "
193 "to be correct.\n"));
197 ServerRequestInterceptor::send_exception (
198 PortableInterceptor::ServerRequestInfo_ptr
)
203 ServerRequestInterceptor::send_other (
204 PortableInterceptor::ServerRequestInfo_ptr
)