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 ()
18 return CORBA::string_dup ("ServerRequestInterceptor");
22 ServerRequestInterceptor::destroy ()
27 ServerRequestInterceptor::receive_request_service_contexts (
28 PortableInterceptor::ServerRequestInfo_ptr ri
)
30 CORBA::String_var op
= ri
->operation ();
32 if (ACE_OS::strcmp (op
.in (), "invoke_me") != 0)
33 return; // Don't mess with PICurrent if not invoking test method.
37 // Insert data into the RSC (request scope current).
39 CORBA::Long number
= 62;
44 ri
->set_slot (this->slot_id_
, data
);
47 "(%P|%t) Inserted number <%d> into RSC.\n",
50 catch (const PortableInterceptor::InvalidSlot
& ex
)
52 ex
._tao_print_exception (
53 "Exception thrown in ""receive_request_service_contexts()\n");
59 throw CORBA::INTERNAL ();
64 ServerRequestInterceptor::receive_request (
65 PortableInterceptor::ServerRequestInfo_ptr ri
)
70 CORBA::Long number
= 19;
73 // Set a value in RSC, this should not effect TSC anymore
74 ri
->set_slot (this->slot_id_
,
77 // Now retrieve the data from the TSC again. It should not have
78 // changed to the new value
79 CORBA::Any_var data2
=
80 this->pi_current_
->get_slot (this->slot_id_
);
82 CORBA::Long number2
= 0;
83 if ((data2
.in () >>= number2
)
87 "(%P|%t) ERROR: TSC was modified because "
88 "RSC was modified.\n"));
90 throw CORBA::INTERNAL ();
93 catch (const PortableInterceptor::InvalidSlot
& ex
)
95 ex
._tao_print_exception ("Exception thrown in ""send_reply()\n");
101 throw CORBA::INTERNAL ();
105 "(%P|%t) Server side RSC/TSC semantics appear "
106 "to be correct.\n"));
110 ServerRequestInterceptor::send_reply (
111 PortableInterceptor::ServerRequestInfo_ptr ri
)
113 CORBA::String_var op
= ri
->operation ();
115 if (ACE_OS::strcmp (op
.in (), "invoke_me") != 0)
116 return; // Don't mess with PICurrent if not invoking test method.
122 // Retrieve the data stored in the RSC. This data (a string)
123 // should be different from the original data (a CORBA::Long)
124 // stored into the RSC by the receive_request_service_contexts()
125 // interception point.
126 data
= ri
->get_slot (this->slot_id_
);
128 // The original data in the RSC was of type CORBA::Long. If the
129 // following extraction from the CORBA::Any fails, then the
130 // original data in the RSC was not replaced with the data in
131 // the TSC after the test method completed.
133 if (data
.in () >>= str
)
135 ACE_DEBUG ((LM_DEBUG
,
136 "(%P|%t) Retrieved \"%s\" from the RSC.\n",
141 ACE_DEBUG ((LM_DEBUG
,
142 "(%P|%t) Unable to extract data (a string) "
145 throw CORBA::INTERNAL ();
148 // Now verify that the RSC is truly independent of the TSC. In
149 // particular, modifying the TSC at this point should not cause
150 // the RSC to be modified.
152 CORBA::Long number
= 19;
156 // Now reset the contents of our slot in the thread-scope
158 this->pi_current_
->set_slot (this->slot_id_
,
161 // Now retrieve the data from the RSC again. It should not have
163 CORBA::Any_var data2
=
164 ri
->get_slot (this->slot_id_
);
166 const char *str2
= 0;
167 if (!(data2
.in () >>= str2
)
168 || ACE_OS::strcmp (str
, str2
) != 0)
170 ACE_ERROR ((LM_ERROR
,
171 "(%P|%t) ERROR: RSC was modified after "
172 "TSC was modified.\n"));
174 throw CORBA::INTERNAL ();
177 catch (const PortableInterceptor::InvalidSlot
& ex
)
179 ex
._tao_print_exception ("Exception thrown in ""send_reply()\n");
181 ACE_DEBUG ((LM_DEBUG
,
182 "Invalid slot: %u\n",
185 throw CORBA::INTERNAL ();
189 "(%P|%t) Server side RSC/TSC semantics appear "
190 "to be correct.\n"));
194 ServerRequestInterceptor::send_exception (
195 PortableInterceptor::ServerRequestInfo_ptr
)
200 ServerRequestInterceptor::send_other (
201 PortableInterceptor::ServerRequestInfo_ptr
)