1 #include "otsdaq/SOAPUtilities/SOAPMessenger.h"
2 #include "otsdaq/Macros/CoutMacros.h"
3 #include "otsdaq/MessageFacility/MessageFacility.h"
4 #include "otsdaq/SOAPUtilities/SOAPCommand.h"
5 #include "otsdaq/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) : theApplication_(application) {}
26 SOAPMessenger::SOAPMessenger(
const SOAPMessenger& aSOAPMessenger) : theApplication_(aSOAPMessenger.theApplication_) {}
33 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, xoap::MessageReference message)
36 return SOAPUtilities::receive(sendWithSOAPReply(ind, message));
40 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d,
SOAPCommand soapCommand)
43 if(soapCommand.hasParameters())
44 return send(d, soapCommand.getCommand(), soapCommand.getParameters());
46 return send(d, soapCommand.getCommand());
50 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d, std::string command)
53 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(command);
54 return send(d, message);
58 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd,
SOAPParameters parameters)
61 return SOAPUtilities::receive(sendWithSOAPReply(ind, cmd, parameters));
65 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd)
68 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd));
72 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, xoap::MessageReference message)
78 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
const_cast<xdaq::ApplicationDescriptor*
>(ind);
81 message->getMimeHeaders()->setHeader(
"Content-Location", d->getURN());
86 message->writeTo(mystring);
89 xoap::MessageReference reply = theApplication_->getApplicationContext()->postSOAP(message, *(theApplication_->getApplicationDescriptor()), *d);
92 catch(xdaq::exception::Exception& e)
97 message->writeTo(mystring);
99 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.", e);
104 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd,
SOAPParameters parameters)
107 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd, parameters));
111 std::string SOAPMessenger::sendStatus(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string message)
117 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
const_cast<xdaq::ApplicationDescriptor*
>(ind);
119 std::string cmd =
"StatusNotification";
123 gettimeofday(&tv, NULL);
125 std::stringstream ss;
127 parameters.addParameter(
"Description", message);
130 parameters.addParameter(
"Time", ss.str());
133 parameters.addParameter(
"usec", ss.str());
134 return send(d, cmd, parameters);
136 catch(xdaq::exception::Exception& e)
138 __COUT__ <<
"This application failed to send a SOAP error message to " << d->getClassName() <<
" instance " << d->getInstance()
139 <<
" with command = " << cmd <<
" re-throwing exception = " << xcept::stdformat_exception_history(e) << std::endl;
140 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.", e);