1 #include "otsdaq-core/SOAPUtilities/SOAPMessenger.h"
2 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
3 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
4 #include "otsdaq-core/MessageFacility/MessageFacility.h"
5 #include "otsdaq-core/Macros/CoutMacros.h"
8 #include <xoap/Method.h>
9 #include <xdaq/NamespaceURI.h>
10 #include <xoap/MessageReference.h>
11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
13 #include <xoap/MessageFactory.h>
14 #pragma GCC diagnostic pop
15 #include <xoap/SOAPPart.h>
16 #include <xoap/SOAPEnvelope.h>
17 #include <xoap/SOAPBody.h>
18 #include <xoap/domutils.h>
19 #include <xoap/AttachmentPart.h>
31 SOAPMessenger::SOAPMessenger(xdaq::Application* application) :
32 theApplication_(application)
37 SOAPMessenger::SOAPMessenger(
const SOAPMessenger& aSOAPMessenger) :
38 theApplication_(aSOAPMessenger.theApplication_)
43 std::string SOAPMessenger::receive(
const xoap::MessageReference& message,
SOAPCommand& soapCommand)
45 return receive(message, soapCommand.getParametersRef());
49 std::string SOAPMessenger::receive(
const xoap::MessageReference& message)
52 return (message->getSOAPPart().getEnvelope().getBody().getChildElements()).begin()->getElementName().getLocalName();
56 std::string SOAPMessenger::receive(
const xoap::MessageReference& message,
SOAPParameters& parameters)
58 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
59 std::vector<xoap::SOAPElement> bodyList = envelope.getBody().getChildElements();
60 xoap::SOAPElement command = bodyList[0];
61 std::string commandName = command.getElementName().getLocalName();
62 xoap::SOAPName name = envelope.createName(
"Key");
64 for (SOAPParameters::iterator it=parameters.begin(); it!=parameters.end(); it++)
66 name = envelope.createName(it->first);
70 it->second = command.getAttributeValue(name);
80 catch (xoap::exception::Exception& e)
82 __COUT__ <<
"Parameter " << it->first <<
" does not exist in the list of incoming parameters!" << std::endl;
83 XCEPT_RETHROW(xoap::exception::Exception,
"Looking for parameter that does not exist!",e);
96 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
97 xoap::MessageReference message)
100 return receive(sendWithSOAPReply(ind,message));
138 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d,
SOAPCommand soapCommand)
141 if(soapCommand.hasParameters())
142 return send(d, soapCommand.getCommand(), soapCommand.getParameters());
144 return send(d, soapCommand.getCommand());
148 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d, std::string command)
151 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(command);
152 return send(d, message);
156 std::string SOAPMessenger::send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind, std::string cmd,
160 return receive(sendWithSOAPReply(ind,cmd,parameters));
203 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
207 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd));
244 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor *ind,
245 xoap::MessageReference message)
251 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
252 const_cast<xdaq::ApplicationDescriptor*
>(ind);
255 message->getMimeHeaders()->setHeader(
"Content-Location", d->getURN());
259 std::string mystring;
260 message->writeTo(mystring);
263 xoap::MessageReference reply = theApplication_->getApplicationContext()->postSOAP(message,
264 *(theApplication_->getApplicationDescriptor()),
268 catch (xdaq::exception::Exception& e)
270 __COUT__ <<
"This application failed to send a SOAP message to "
271 << d->getClassName() <<
" instance " << d->getInstance()
272 <<
" re-throwing exception = " << xcept::stdformat_exception_history(e);
273 std::string mystring;
274 message->writeTo(mystring);
275 __COUT_ERR__<< mystring << std::endl;
276 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.",e);
281 xoap::MessageReference SOAPMessenger::sendWithSOAPReply(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
285 return sendWithSOAPReply(ind, SOAPUtilities::makeSOAPMessageReference(cmd, parameters));
349 std::string SOAPMessenger::sendStatus(XDAQ_CONST_CALL xdaq::ApplicationDescriptor* ind,
356 XDAQ_CONST_CALL xdaq::ApplicationDescriptor* d =
357 const_cast<xdaq::ApplicationDescriptor*
>(ind);
359 std::string cmd =
"StatusNotification";
363 gettimeofday(&tv,NULL);
365 std::stringstream ss;
367 parameters.addParameter(
"Description",message);
368 ss.str(
""); ss << tv.tv_sec;
369 parameters.addParameter(
"Time",ss.str());
370 ss.str(
""); ss << tv.tv_usec;
371 parameters.addParameter(
"usec",ss.str());
372 return send(d, cmd, parameters);
374 catch (xdaq::exception::Exception& e)
376 __COUT__ <<
"This application failed to send a SOAP error message to "
377 << d->getClassName() <<
" instance " << d->getInstance()
378 <<
" with command = " << cmd
379 <<
" re-throwing exception = " << xcept::stdformat_exception_history(e) << std::endl;
380 XCEPT_RETHROW(xdaq::exception::Exception,
"Failed to send SOAP command.",e);