Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3215_Regression / ServerRequest_Interceptor2.cpp
blobcb01b6ce8e37f0304b27f5973474c5e7605122b9
1 // -*- C++ -*-
2 #include "ServerRequest_Interceptor2.h"
3 #include "orbsvcs/FT_CORBA_ORBC.h"
4 #include "tao/IOPC.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/AnyTypeCode/DynamicC.h"
7 #include "tao/AnyTypeCode/TypeCode.h"
8 #include "tao/CDR.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/OS_NS_stdio.h"
12 #include "ace/OS_NS_unistd.h"
13 #include "Hello.h"
14 #include "ace/OS_NS_sys_time.h"
15 #include "tao/PI/PIForwardRequestC.h"
17 int invocation_count = 0;
19 TAO249_ServerRequest_Interceptor2::TAO249_ServerRequest_Interceptor2 (void)
20 : orb_ (0),
21 expired_ (0)
25 TAO249_ServerRequest_Interceptor2::~TAO249_ServerRequest_Interceptor2 (void)
29 char *
30 TAO249_ServerRequest_Interceptor2::name ()
32 return CORBA::string_dup ("TAO_TAO249_ServerRequest_Interceptor2");
35 void
36 TAO249_ServerRequest_Interceptor2::destroy ()
40 void
41 TAO249_ServerRequest_Interceptor2::receive_request_service_contexts (
42 PortableInterceptor::ServerRequestInfo_ptr
47 void
48 TAO249_ServerRequest_Interceptor2::receive_request (
49 PortableInterceptor::ServerRequestInfo_ptr ri
52 CORBA::String_var op = ri->operation ();
54 if (ACE_OS::strcmp (op.in (), "throw_location_forward"))
56 // bail if not the op we are interested in -
57 // avoid excess spurious error clutter when client calls ::shutdown
58 return;
62 IOP::ServiceContext_var sc =
63 ri->get_request_service_context (IOP::FT_REQUEST
67 TAO_InputCDR cdr (reinterpret_cast <const char*>
68 (sc->context_data.get_buffer ()
70 sc->context_data.length ());
72 CORBA::Boolean byte_order;
74 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
76 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28,
77 CORBA::COMPLETED_NO);
81 cdr.reset_byte_order (static_cast <int>(byte_order));
83 FT::FTRequestServiceContext ftrsc;
85 if ((cdr >> ftrsc) == 0)
86 throw CORBA::BAD_PARAM (CORBA::OMGVMCID | 28,
87 CORBA::COMPLETED_NO);
90 TimeBase::TimeT now = get_now ();
92 if (now > ftrsc.expiration_time)
94 // We have passed the exp time... there should be no more retries received after this point...
95 if (expired_)
97 // The client has retried more than once after the expiration time. This is a regression
98 ACE_DEBUG ((LM_ERROR, "Test Failed - REGRESSION !!! Client ORB is still retrying LOCATION_FORWARDs / TRANSIENTS after the expiration time on invocation # %d !!\n", invocation_count + 1));
99 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Expiration time : %Q\n"), ftrsc.expiration_time));
100 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Time now : %Q\n"), now));
102 // Let the request 'succeed' rather than throwing a forward exception.
103 return;
105 else
107 // A request has been recioved after the expiration time.
108 // This could legitimately happen - it is only definitely a problem if
109 // the client keeps on retrying after now. We set a flag so we can check for this.
110 expired_ = 1;
111 ACE_DEBUG ((LM_DEBUG, "The expiration time has now passed !! The next exception must NOT prompt reinvocation.\n"));
112 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Expiration time : %Q\n"), ftrsc.expiration_time));
113 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Time now : %Q\n"), now));
117 if (invocation_count == 0)
119 ++invocation_count;
120 if (expired_)
122 ACE_DEBUG ((LM_DEBUG, "On invocation #%d throwing a ForwardRequest back to the client\n", invocation_count));
124 // Throw a forward back to ourselves on the first try
125 // This means that we are testing the exception handling after a forward perm...
126 throw PortableInterceptor::ForwardRequest (server_iogr_.in ());
128 else
130 ++invocation_count;
131 if (expired_)
133 ACE_DEBUG ((LM_DEBUG, "On invocation #%d throwing a TRANSIENT back to the client\n", invocation_count));
135 // Thaen throw a transient on all subsequent invocations
136 throw CORBA::TRANSIENT (0, CORBA::COMPLETED_NO);
140 TimeBase::TimeT
141 TAO249_ServerRequest_Interceptor2::get_now (void)
143 // 1582...
144 const TimeBase::TimeT timeOffset = ACE_UINT64_LITERAL (0x1B21DD213814000);
146 // Now in posix
147 ACE_Time_Value time_value = ACE_OS::gettimeofday ();
149 TimeBase::TimeT sec_part = time_value.sec ();
150 sec_part = sec_part * 10000000;
151 TimeBase::TimeT usec_part = time_value.usec ();
152 usec_part = usec_part * 10;
153 return (sec_part + usec_part + timeOffset);
156 void
157 TAO249_ServerRequest_Interceptor2::send_reply (
158 PortableInterceptor::ServerRequestInfo_ptr
163 void
164 TAO249_ServerRequest_Interceptor2::send_exception (
165 PortableInterceptor::ServerRequestInfo_ptr
170 void
171 TAO249_ServerRequest_Interceptor2::send_other (
172 PortableInterceptor::ServerRequestInfo_ptr