00001
00002
00003 #include "tao/TAO_Server_Request.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/Timeprobe.h"
00006 #include "tao/debug.h"
00007 #include "tao/GIOP_Message_Base.h"
00008 #include "tao/GIOP_Utils.h"
00009 #include "tao/Stub.h"
00010 #include "tao/operation_details.h"
00011 #include "tao/Transport.h"
00012 #include "tao/CDR.h"
00013 #include "tao/SystemException.h"
00014
00015 #if TAO_HAS_INTERCEPTORS == 1
00016 #include "tao/PortableInterceptorC.h"
00017 #include "tao/ServerRequestInterceptor_Adapter.h"
00018 #endif
00019
00020 #if !defined (__ACE_INLINE__)
00021 # include "tao/TAO_Server_Request.inl"
00022 #endif
00023
00024 ACE_RCSID (tao,
00025 TAO_Server_Request,
00026 "$Id: TAO_Server_Request.cpp 81140 2008-03-28 09:19:19Z vzykov $")
00027
00028 #if defined (ACE_ENABLE_TIMEPROBES)
00029
00030 static const char * TAO_Server_Request_Timeprobe_Description[] =
00031 {
00032 "TAO_ServerRequest::TAO_ServerRequest - start",
00033 "TAO_ServerRequest::TAO_ServerRequest - end",
00034 };
00035
00036 enum
00037 {
00038
00039 TAO_SERVER_REQUEST_START = 400,
00040 TAO_SERVER_REQUEST_END
00041 };
00042
00043
00044 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Server_Request_Timeprobe_Description,
00045 TAO_SERVER_REQUEST_START);
00046
00047 #endif
00048
00049 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00050
00051 TAO_ServerRequest::TAO_ServerRequest (TAO_GIOP_Message_Base *mesg_base,
00052 TAO_InputCDR &input,
00053 TAO_OutputCDR &output,
00054 TAO_Transport *transport,
00055 TAO_ORB_Core *orb_core)
00056 : mesg_base_ (mesg_base),
00057 operation_ (0),
00058 operation_len_ (0),
00059 release_operation_ (false),
00060 is_forwarded_ (false),
00061 incoming_ (&input),
00062 outgoing_ (&output),
00063 response_expected_ (false),
00064 deferred_reply_ (false),
00065 sync_with_server_ (false),
00066 is_dsi_ (false),
00067
00068 reply_status_ (GIOP::NO_EXCEPTION),
00069 orb_core_ (orb_core),
00070 request_id_ (0),
00071 profile_ (orb_core),
00072 requesting_principal_ (0),
00073 dsi_nvlist_align_ (0),
00074 operation_details_ (0),
00075 argument_flag_ (true)
00076 #if TAO_HAS_INTERCEPTORS == 1
00077 , interceptor_count_ (0)
00078 , rs_pi_current_ (0)
00079 , caught_exception_ (0)
00080 , pi_reply_status_ (-1)
00081 #endif
00082 , transport_(transport)
00083 {
00084 ACE_FUNCTION_TIMEPROBE (TAO_SERVER_REQUEST_START);
00085
00086 }
00087
00088
00089 TAO_ServerRequest::TAO_ServerRequest (TAO_GIOP_Message_Base *mesg_base,
00090 CORBA::ULong request_id,
00091 CORBA::Boolean response_expected,
00092 CORBA::Boolean deferred_reply,
00093 TAO::ObjectKey &object_key,
00094 const char *operation,
00095 TAO_OutputCDR &output,
00096 TAO_Transport *transport,
00097 TAO_ORB_Core *orb_core,
00098 int &parse_error)
00099 : mesg_base_ (mesg_base),
00100 operation_ (CORBA::string_dup (operation)),
00101 operation_len_ (operation == 0 ? 0 : ACE_OS::strlen (operation)),
00102 release_operation_ (true),
00103 is_forwarded_ (false),
00104 incoming_ (0),
00105 outgoing_ (&output),
00106 response_expected_ (response_expected),
00107 deferred_reply_ (deferred_reply),
00108 sync_with_server_ (false),
00109 is_dsi_ (false),
00110 reply_status_ (GIOP::NO_EXCEPTION),
00111 orb_core_ (orb_core),
00112 request_id_ (request_id),
00113 profile_ (orb_core),
00114 requesting_principal_ (0),
00115 dsi_nvlist_align_ (0),
00116 operation_details_ (0),
00117 argument_flag_ (true)
00118 #if TAO_HAS_INTERCEPTORS == 1
00119 , interceptor_count_ (0)
00120 , rs_pi_current_ (0)
00121 , caught_exception_ (0)
00122 , pi_reply_status_ (-1)
00123 #endif
00124 , transport_(transport)
00125 {
00126 this->profile_.object_key (object_key);
00127 parse_error = 0;
00128 }
00129
00130
00131 TAO_ServerRequest::TAO_ServerRequest (TAO_ORB_Core * orb_core,
00132 TAO_Operation_Details const & details,
00133 CORBA::Object_ptr target)
00134 : mesg_base_ (0),
00135 operation_ (details.opname ()),
00136 operation_len_ (details.opname_len ()),
00137 release_operation_ (false),
00138 is_forwarded_ (false),
00139 incoming_ (0),
00140 outgoing_ (0),
00141 response_expected_ (details.response_flags () == TAO_TWOWAY_RESPONSE_FLAG
00142 || details.response_flags () == static_cast<CORBA::Octet> (Messaging::SYNC_WITH_SERVER)
00143 || details.response_flags () == static_cast<CORBA::Octet> (Messaging::SYNC_WITH_TARGET)),
00144 deferred_reply_ (false),
00145 sync_with_server_ (details.response_flags () == static_cast<CORBA::Octet> (Messaging::SYNC_WITH_SERVER)),
00146 is_dsi_ (false),
00147 reply_status_ (GIOP::NO_EXCEPTION),
00148 orb_core_ (orb_core),
00149 request_id_ (0),
00150 profile_ (orb_core),
00151 requesting_principal_ (0),
00152 dsi_nvlist_align_ (0),
00153 operation_details_ (&details),
00154 argument_flag_ (false)
00155 #if TAO_HAS_INTERCEPTORS == 1
00156 , interceptor_count_ (0)
00157 , rs_pi_current_ (0)
00158 , caught_exception_ (0)
00159 , pi_reply_status_ (-1)
00160 #endif
00161 , transport_ (0)
00162 {
00163
00164 this->profile_.object_key (
00165 const_cast<TAO::ObjectKey &> (target->_stubobj ()->object_key ()));
00166
00167
00168
00169 IOP::ServiceContextList & dest_request_contexts =
00170 this->request_service_context_.service_info ();
00171
00172 IOP::ServiceContextList & src_request_contexts =
00173 (const_cast <TAO_Operation_Details&> (details)).request_service_info ();
00174
00175 dest_request_contexts.replace (src_request_contexts.maximum (),
00176 src_request_contexts.length (),
00177 src_request_contexts.get_buffer (),
00178 false );
00179
00180
00181
00182
00183 }
00184
00185 TAO_ServerRequest::~TAO_ServerRequest (void)
00186 {
00187 #if TAO_HAS_INTERCEPTORS == 1
00188 if (this->rs_pi_current_)
00189 {
00190 TAO::ServerRequestInterceptor_Adapter *interceptor_adapter =
00191 this->orb_core_->serverrequestinterceptor_adapter ();
00192
00193 if (interceptor_adapter)
00194 {
00195 interceptor_adapter->deallocate_pi_current (
00196 this->rs_pi_current_);
00197 }
00198 }
00199 #endif
00200 if (this->release_operation_)
00201 CORBA::string_free (const_cast<char*> (this->operation_));
00202 }
00203
00204 CORBA::ORB_ptr
00205 TAO_ServerRequest::orb (void)
00206 {
00207 return this->orb_core_->orb ();
00208 }
00209
00210 TAO_Service_Context &
00211 TAO_ServerRequest::reply_service_context (void)
00212 {
00213 if (!operation_details_)
00214 {
00215 return this->reply_service_context_;
00216 }
00217 else
00218 {
00219 return const_cast <TAO_Operation_Details*> (
00220 this->operation_details_)->reply_service_context ();
00221 }
00222 }
00223
00224
00225 void
00226 TAO_ServerRequest::init_reply (void)
00227 {
00228 if (!this->outgoing_)
00229 return;
00230
00231
00232 TAO_Pluggable_Reply_Params_Base reply_params;
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 reply_params.request_id_ = this->request_id_;
00243 reply_params.is_dsi_ = this->is_dsi_;
00244 reply_params.dsi_nvlist_align_ = this->dsi_nvlist_align_;
00245
00246
00247 reply_params.service_context_notowned (&this->reply_service_info ());
00248
00249
00250 reply_params.argument_flag_ = this->argument_flag_;
00251
00252
00253 if (this->is_forwarded_)
00254 {
00255 CORBA::Boolean const permanent_forward_condition =
00256 this->orb_core_->is_permanent_forward_condition (this->forward_location_.in (),
00257 this->request_service_context ());
00258
00259 reply_params.reply_status (
00260 permanent_forward_condition
00261 ? GIOP::LOCATION_FORWARD_PERM
00262 : GIOP::LOCATION_FORWARD);
00263 }
00264
00265 else
00266 {
00267 reply_params.reply_status (this->reply_status_);
00268 }
00269
00270 this->outgoing_->message_attributes (this->request_id_,
00271 0,
00272 TAO_Transport::TAO_REPLY,
00273 0);
00274
00275
00276 this->mesg_base_->generate_reply_header (*this->outgoing_, reply_params);
00277
00278
00279 if (reply_params.reply_status () == GIOP::LOCATION_FORWARD ||
00280 reply_params.reply_status () == GIOP::LOCATION_FORWARD_PERM)
00281 {
00282
00283 CORBA::Object_ptr object_ptr = this->forward_location_.in ();
00284
00285 if ((*this->outgoing_ << object_ptr) == 0)
00286 {
00287 ACE_DEBUG ((LM_DEBUG,
00288 ACE_TEXT ("TAO (%P|%t) - ServerRequest::init_reply, ")
00289 ACE_TEXT ("TAO_GIOP_ServerRequest::marshal - ")
00290 ACE_TEXT ("marshal encoding forwarded objref failed\n")));
00291 }
00292 }
00293 this->transport_->assign_translators (0, this->outgoing_);
00294 }
00295
00296 void
00297 TAO_ServerRequest::send_no_exception_reply (void)
00298 {
00299
00300 TAO_Pluggable_Reply_Params_Base reply_params;
00301 reply_params.request_id_ = this->request_id_;
00302 reply_params.is_dsi_ = this->is_dsi_;
00303 reply_params.dsi_nvlist_align_ = this->dsi_nvlist_align_;
00304
00305
00306
00307 reply_params.svc_ctx_.length (0);
00308
00309
00310 reply_params.service_context_notowned (&this->reply_service_info ());
00311
00312 reply_params.reply_status (GIOP::NO_EXCEPTION);
00313
00314
00315 reply_params.argument_flag_ = false;
00316
00317 this->outgoing_->message_attributes (this->request_id_,
00318 0,
00319 TAO_Transport::TAO_REPLY,
00320 0);
00321
00322
00323 this->mesg_base_->generate_reply_header (*this->outgoing_, reply_params);
00324
00325 this->outgoing_->more_fragments (false);
00326
00327
00328 int result = this->transport_->send_message (*this->outgoing_,
00329 0,
00330 TAO_Transport::TAO_REPLY);
00331
00332 if (result == -1)
00333 {
00334 if (TAO_debug_level > 0)
00335 {
00336
00337
00338 ACE_ERROR ((
00339 LM_ERROR,
00340 ACE_TEXT ("TAO (%P|%t) - ServerRequest::send_no_exception_reply, ")
00341 ACE_TEXT ("cannot send NO_EXCEPTION reply\n")
00342 ));
00343 }
00344 }
00345 }
00346
00347 void
00348 TAO_ServerRequest::tao_send_reply (void)
00349 {
00350 if (this->collocated ())
00351 return;
00352
00353 this->outgoing_->more_fragments (false);
00354
00355 int result = this->transport_->send_message (*this->outgoing_,
00356 0,
00357 TAO_Transport::TAO_REPLY);
00358 if (result == -1)
00359 {
00360 if (TAO_debug_level > 0)
00361 {
00362
00363
00364 ACE_ERROR ((LM_ERROR,
00365 ACE_TEXT ("TAO (%P|%t) - ServerRequest::tao_send_reply, ")
00366 ACE_TEXT ("cannot send reply\n")));
00367 }
00368 }
00369 }
00370
00371 void
00372 TAO_ServerRequest::tao_send_reply_exception (const CORBA::Exception &ex)
00373 {
00374 if (this->response_expected_ && !this->collocated ())
00375 {
00376
00377 TAO_Pluggable_Reply_Params_Base reply_params;
00378
00379 reply_params.request_id_ = this->request_id_;
00380 reply_params.svc_ctx_.length (0);
00381
00382
00383 reply_params.service_context_notowned (&this->reply_service_info ());
00384
00385
00386 reply_params.argument_flag_ = true;
00387
00388
00389
00390
00391 if (CORBA::SystemException::_downcast (&ex) != 0)
00392 {
00393 reply_params.reply_status (GIOP::SYSTEM_EXCEPTION);
00394 }
00395 else
00396 {
00397 reply_params.reply_status (GIOP::USER_EXCEPTION);
00398 }
00399
00400
00401 #if defined(ACE_INITIALIZE_MEMORY_BEFORE_USE)
00402
00403
00404
00405
00406 char repbuf[ACE_CDR::DEFAULT_BUFSIZE] = { 0 };
00407 #else
00408 char repbuf[ACE_CDR::DEFAULT_BUFSIZE];
00409 #endif
00410 TAO_GIOP_Message_Version gv;
00411 if (this->outgoing_)
00412 this->outgoing_->get_version (gv);
00413
00414 TAO_OutputCDR output (repbuf,
00415 sizeof repbuf,
00416 TAO_ENCAP_BYTE_ORDER,
00417 this->orb_core_->output_cdr_buffer_allocator (),
00418 this->orb_core_->output_cdr_dblock_allocator (),
00419 this->orb_core_->output_cdr_msgblock_allocator (),
00420 this->orb_core_->orb_params ()->cdr_memcpy_tradeoff (),
00421 this->mesg_base_->fragmentation_strategy (),
00422 gv.major,
00423 gv.minor);
00424
00425 this->transport_->assign_translators (0, &output);
00426
00427 if (this->mesg_base_->generate_exception_reply (*this->outgoing_,
00428 reply_params,
00429 ex) == -1)
00430 {
00431 ACE_ERROR ((LM_ERROR,
00432 ACE_TEXT ("TAO (%P|%t) - ServerRequest::tao_send_reply_exception, ")
00433 ACE_TEXT ("could not make exception reply\n")));
00434
00435 }
00436
00437 this->outgoing_->more_fragments (false);
00438
00439
00440 if (this->transport_->send_message (*this->outgoing_,
00441 0,
00442 TAO_Transport::TAO_REPLY) == -1)
00443 {
00444 ACE_ERROR ((LM_ERROR,
00445 ACE_TEXT ("TAO (%P|%t) - ServerRequest::tao_send_reply_exception, ")
00446 ACE_TEXT ("could not send exception reply\n")));
00447 }
00448 }
00449 else if (TAO_debug_level > 0)
00450 {
00451
00452
00453
00454
00455
00456
00457 ACE_ERROR ((LM_ERROR,
00458 ACE_TEXT ("TAO (%P|%t) - ServerRequest::tao_send_reply_exception, ")
00459 ACE_TEXT ("exception thrown ")
00460 ACE_TEXT ("but client is not waiting a response\n")));
00461 }
00462 }
00463
00464 #if TAO_HAS_INTERCEPTORS == 1
00465 void
00466 TAO_ServerRequest::send_cached_reply (CORBA::OctetSeq &s)
00467 {
00468 #if defined(ACE_HAS_PURIFY)
00469
00470
00471
00472
00473 char repbuf[ACE_CDR::DEFAULT_BUFSIZE] = { 0 };
00474 #else
00475 char repbuf[ACE_CDR::DEFAULT_BUFSIZE];
00476 #endif
00477 TAO_GIOP_Message_Version gv;
00478 if (this->outgoing_)
00479 this->outgoing_->get_version (gv);
00480 TAO_OutputCDR output (repbuf,
00481 sizeof repbuf,
00482 TAO_ENCAP_BYTE_ORDER,
00483 this->orb_core_->output_cdr_buffer_allocator (),
00484 this->orb_core_->output_cdr_dblock_allocator (),
00485 this->orb_core_->output_cdr_msgblock_allocator (),
00486 this->orb_core_->orb_params ()->cdr_memcpy_tradeoff (),
00487 this->mesg_base_->fragmentation_strategy (),
00488 gv.major,
00489 gv.minor);
00490
00491 this->transport_->assign_translators (0, &output);
00492
00493
00494 TAO_Pluggable_Reply_Params_Base reply_params;
00495
00496 reply_params.request_id_ = this->request_id_;
00497
00498 reply_params.svc_ctx_.length (0);
00499
00500
00501 reply_params.service_context_notowned (&this->reply_service_info ());
00502
00503
00504 reply_params.argument_flag_ = true;
00505
00506
00507 reply_params.reply_status (GIOP::NO_EXCEPTION);
00508
00509 this->outgoing_->message_attributes (this->request_id_,
00510 0,
00511 TAO_Transport::TAO_REPLY,
00512 0);
00513
00514
00515 if (this->mesg_base_->generate_reply_header (*this->outgoing_,
00516 reply_params) == -1)
00517 {
00518 ACE_ERROR ((LM_ERROR,
00519 ACE_TEXT ("TAO (%P|%t) - ServerRequest::send_cached_reply, ")
00520 ACE_TEXT ("could not make cached reply\n")));
00521
00522 }
00523
00524
00525 this->outgoing_->write_octet_array (
00526 s.get_buffer (),
00527 s.length ());
00528
00529 if (!this->outgoing_->good_bit ())
00530 ACE_ERROR ((LM_ERROR,
00531 ACE_TEXT ("TAO (%P|%t) - ServerRequest::send_cached_reply, ")
00532 ACE_TEXT ("could not marshal reply\n")));
00533
00534 this->outgoing_->more_fragments (false);
00535
00536
00537 if (this->transport_->send_message (*this->outgoing_,
00538 0,
00539 TAO_Transport::TAO_REPLY) == -1)
00540 {
00541 ACE_ERROR ((LM_ERROR,
00542 ACE_TEXT ("TAO (%P|%t) - ServerRequest::send_cached_reply, ")
00543 ACE_TEXT ("could not send cached reply\n")));
00544 }
00545 }
00546
00547 void
00548 TAO_ServerRequest::caught_exception (CORBA::Exception *exception)
00549 {
00550 if (CORBA::SystemException::_downcast (exception) != 0)
00551 this->pi_reply_status_ = PortableInterceptor::SYSTEM_EXCEPTION;
00552 else if (CORBA::UserException::_downcast (exception) != 0)
00553 this->pi_reply_status_ = PortableInterceptor::USER_EXCEPTION;
00554
00555 this->caught_exception_ = exception;
00556 }
00557
00558 TAO::PICurrent_Impl *
00559 TAO_ServerRequest::rs_pi_current (void)
00560 {
00561 if (!this->rs_pi_current_)
00562 {
00563 TAO::ServerRequestInterceptor_Adapter *interceptor_adapter =
00564 this->orb_core_->serverrequestinterceptor_adapter ();
00565
00566 if (interceptor_adapter)
00567 {
00568 this->rs_pi_current_ = interceptor_adapter->allocate_pi_current ();
00569 }
00570 }
00571
00572 return this->rs_pi_current_;
00573 }
00574
00575 TAO_END_VERSIONED_NAMESPACE_DECL
00576
00577 #endif