$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h" 00002 #include "otsdaq-core/Macros/CoutMacros.h" 00003 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00004 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h" 00005 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h" 00006 00007 #include <xdaq/NamespaceURI.h> 00008 #include <xoap/MessageReference.h> 00009 #include <xoap/Method.h> 00010 #pragma GCC diagnostic push 00011 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 00012 #include <xoap/MessageFactory.h> 00013 #pragma GCC diagnostic pop 00014 #include <xoap/AttachmentPart.h> 00015 #include <xoap/SOAPBody.h> 00016 #include <xoap/SOAPEnvelope.h> 00017 #include <xoap/SOAPPart.h> 00018 #include <xoap/domutils.h> 00019 00020 using namespace ots; 00021 00022 //======================================================================================================================== 00023 SOAPMessenger::SOAPMessenger(xdaq::Application* application) 00024 : theApplication_(application) 00025 { 00026 } 00027 00028 //======================================================================================================================== 00029 SOAPMessenger::SOAPMessenger(const SOAPMessenger& aSOAPMessenger) 00030 : theApplication_(aSOAPMessenger.theApplication_) 00031 { 00032 } 00033 00034 //======================================================================================================================== 00035 // in xdaq 00036 // xdaq::ApplicationDescriptor* sourceptr; 00037 // void getURN() 00038 // 00039 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, 00040 xoap::MessageReference message) 00041 00042 { 00043 return SOAPUtilities::receive(sendWithSOAPReply(ind, message)); 00044 } 00045 00046 //======================================================================================================================== 00047 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d, 00048 SOAPCommand soapCommand) 00049 00050 { 00051 if(soapCommand.hasParameters()) 00052 return send(d, soapCommand.getCommand(), soapCommand.getParameters()); 00053 else 00054 return send(d, soapCommand.getCommand()); 00055 } 00056 00057 //======================================================================================================================== 00058 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d, 00059 std::string command) 00060 00061 { 00062 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(command); 00063 return send(d, message); 00064 } 00065 00066 //======================================================================================================================== 00067 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, 00068 std::string cmd, 00069 SOAPParameters parameters) 00070 00071 { 00072 return SOAPUtilities::receive(sendWithSOAPReply(ind, cmd, parameters)); 00073 } 00074 00075 //======================================================================================================================== 00076 xoap::MessageReference SOAPMessenger::sendWithSOAPReply( 00077 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd) 00078 00079 { 00080 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd)); 00081 } 00082 00083 //======================================================================================================================== 00084 xoap::MessageReference SOAPMessenger::sendWithSOAPReply( 00085 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, xoap::MessageReference message) 00086 00087 { 00088 // const_cast away the const 00089 // so that this line is compatible with slf6 and slf7 versions of xdaq 00090 // where they changed to XDAQ_CONST_CALL xdaq::ApplicationDescriptor* in slf7 00091 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d = 00092 const_cast<xdaq::ApplicationDescriptor*>(ind); 00093 try 00094 { 00095 message->getMimeHeaders()->setHeader("Content-Location", d->getURN()); 00096 00097 //__COUT__ << d->getURN() << __E__; 00098 //__COUT__ << SOAPUtilities::translate(message) << __E__; 00099 std::string mystring; 00100 message->writeTo(mystring); 00101 //__COUT__<< mystring << std::endl; 00102 00103 xoap::MessageReference reply = theApplication_->getApplicationContext()->postSOAP( 00104 message, *(theApplication_->getApplicationDescriptor()), *d); 00105 return reply; 00106 } 00107 catch(xdaq::exception::Exception& e) 00108 { 00109 __COUT__ << "This application failed to send a SOAP message to " 00110 << d->getClassName() << " instance " << d->getInstance() 00111 << " re-throwing exception = " << xcept::stdformat_exception_history(e); 00112 std::string mystring; 00113 message->writeTo(mystring); 00114 __COUT_ERR__ << mystring << std::endl; 00115 XCEPT_RETHROW(xdaq::exception::Exception, "Failed to send SOAP command.", e); 00116 } 00117 } 00118 00119 //======================================================================================================================== 00120 xoap::MessageReference SOAPMessenger::sendWithSOAPReply( 00121 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, 00122 std::string cmd, 00123 SOAPParameters parameters) 00124 00125 { 00126 return sendWithSOAPReply(ind, 00127 SOAPUtilities::makeSOAPMessageReference(cmd, parameters)); 00128 } 00129 00130 //======================================================================================================================== 00131 std::string SOAPMessenger::sendStatus(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, 00132 std::string message) 00133 00134 { 00135 // const_cast away the const 00136 // so that this line is compatible with slf6 and slf7 versions of xdaq 00137 // where they changed to XDAQ_CONST_CALL xdaq::ApplicationDescriptor* in slf7 00138 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d = 00139 const_cast<xdaq::ApplicationDescriptor*>(ind); 00140 00141 std::string cmd = "StatusNotification"; 00142 try 00143 { 00144 timeval tv; // keep track of when the message comes 00145 gettimeofday(&tv, NULL); 00146 00147 std::stringstream ss; 00148 SOAPParameters parameters; 00149 parameters.addParameter("Description", message); 00150 ss.str(""); 00151 ss << tv.tv_sec; 00152 parameters.addParameter("Time", ss.str()); 00153 ss.str(""); 00154 ss << tv.tv_usec; 00155 parameters.addParameter("usec", ss.str()); 00156 return send(d, cmd, parameters); 00157 } 00158 catch(xdaq::exception::Exception& e) 00159 { 00160 __COUT__ << "This application failed to send a SOAP error message to " 00161 << d->getClassName() << " instance " << d->getInstance() 00162 << " with command = " << cmd 00163 << " re-throwing exception = " << xcept::stdformat_exception_history(e) 00164 << std::endl; 00165 XCEPT_RETHROW(xdaq::exception::Exception, "Failed to send SOAP command.", e); 00166 } 00167 }