1 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
5 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
7 #include <xdaq/NamespaceURI.h>
8 #include <xoap/MessageReference.h>
9 #include <xoap/Method.h>
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
12 #include <xoap/MessageFactory.h>
13 #pragma GCC diagnostic pop
14 #include <xoap/AttachmentPart.h>
15 #include <xoap/SOAPBody.h>
16 #include <xoap/SOAPEnvelope.h>
17 #include <xoap/SOAPPart.h>
18 #include <xoap/domutils.h>
23 SOAPMessenger::SOAPMessenger(xdaq::Application* application)
24 : theApplication_(application)
29 SOAPMessenger::SOAPMessenger(
const SOAPMessenger& aSOAPMessenger)
30 : theApplication_(aSOAPMessenger.theApplication_)
39 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
40 xoap::MessageReference message)
43 return SOAPUtilities::receive(sendWithSOAPReply(ind, message));
47 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d,
51 if(soapCommand.hasParameters())
52 return send(d, soapCommand.getCommand(), soapCommand.getParameters());
54 return send(d, soapCommand.getCommand());
58 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d,
62 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(command);
63 return send(d, message);
67 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
72 return SOAPUtilities::receive(sendWithSOAPReply(ind, cmd, parameters));
76 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(
77 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd)
80 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd));
84 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(
85 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, xoap::MessageReference message)
91 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
92 const_cast<xdaq::ApplicationDescriptor*
>(ind);
95 message->getMimeHeaders()->setHeader(
"Content-Location", d->getURN());
100 message->writeTo(mystring);
103 xoap::MessageReference reply = theApplication_->getApplicationContext()->postSOAP(
104 message, *(theApplication_->getApplicationDescriptor()), *d);
107 catch(xdaq::exception::Exception& e)
109 __COUT__ <<
"This application failed to send a SOAP message to "
110 << d->getClassName() <<
" instance " << d->getInstance()
111 <<
" re-throwing exception = " << xcept::stdformat_exception_history(e);
112 std::string mystring;
113 message->writeTo(mystring);
114 __COUT_ERR__ << mystring << std::endl;
115 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.", e);
120 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(
121 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
126 return sendWithSOAPReply(ind,
127 SOAPUtilities::makeSOAPMessageReference(cmd, parameters));
131 std::string SOAPMessenger::sendStatus(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
138 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
139 const_cast<xdaq::ApplicationDescriptor*
>(ind);
141 std::string cmd =
"StatusNotification";
145 gettimeofday(&tv, NULL);
147 std::stringstream ss;
149 parameters.addParameter(
"Description", message);
152 parameters.addParameter(
"Time", ss.str());
155 parameters.addParameter(
"usec", ss.str());
156 return send(d, cmd, parameters);
158 catch(xdaq::exception::Exception& e)
160 __COUT__ <<
"This application failed to send a SOAP error message to "
161 << d->getClassName() <<
" instance " << d->getInstance()
162 <<
" with command = " << cmd
163 <<
" re-throwing exception = " << xcept::stdformat_exception_history(e)
165 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.", e);