1 #include "otsdaq/SOAPUtilities/SOAPUtilities.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/MessageFacility/MessageFacility.h"
6 #include <xdaq/NamespaceURI.h>
7 #include <xoap/MessageReference.h>
8 #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
15 #include <xoap/AttachmentPart.h>
16 #include <xoap/SOAPBody.h>
17 #include <xoap/SOAPEnvelope.h>
18 #include <xoap/SOAPPart.h>
19 #include <xoap/domutils.h>
24 SOAPUtilities::SOAPUtilities(
void) {}
27 SOAPUtilities::~SOAPUtilities(
void) {}
30 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(
SOAPCommand soapCommand)
32 if(soapCommand.hasParameters())
33 return makeSOAPMessageReference(soapCommand.getCommand(), soapCommand.getParameters());
35 return makeSOAPMessageReference(soapCommand.getCommand());
39 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command)
41 xoap::MessageReference message = xoap::createMessage();
42 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
43 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
44 xoap::SOAPBody body = envelope.getBody();
45 body.addBodyElement(name);
50 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command,
SOAPParameters parameters)
54 if(parameters.size() == 0)
55 return makeSOAPMessageReference(command);
56 xoap::MessageReference message = xoap::createMessage();
57 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
58 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
59 xoap::SOAPBody body = envelope.getBody();
60 xoap::SOAPElement bodyCommand = body.addBodyElement(name);
61 xoap::SOAPName parameterName = envelope.createName(
"Null");
62 for(SOAPParameters::iterator it = parameters.begin(); it != parameters.end(); it++)
64 parameterName = envelope.createName(it->first);
65 bodyCommand.addAttribute(parameterName, it->second);
72 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command, std::string fileName)
74 __COUT__ <<
"SOAP XML file path : " << fileName << std::endl;
75 xoap::MessageReference message = xoap::createMessage();
76 xoap::SOAPPart soap = message->getSOAPPart();
77 xoap::SOAPEnvelope envelope = soap.getEnvelope();
78 xoap::AttachmentPart* attachment;
79 attachment = message->createAttachmentPart();
80 attachment->setContent(fileName);
81 attachment->setContentId(
"SOAPTEST1");
82 attachment->addMimeHeader(
"Content-Description",
"This is a SOAP message with attachments");
83 message->addAttachmentPart(attachment);
84 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
85 xoap::SOAPBody body = envelope.getBody();
86 body.addBodyElement(name);
91 void SOAPUtilities::addParameters(xoap::MessageReference& message,
SOAPParameters parameters)
94 if(parameters.size() == 0)
96 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
97 xoap::SOAPBody body = envelope.getBody();
98 xoap::SOAPName name(translate(message).getCommand(),
"xdaq", XDAQ_NS_URI);
100 std::vector<xoap::SOAPElement> bodyList = body.getChildElements();
101 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin(); it != bodyList.end(); it++)
103 if((*it).getElementName() == name)
105 for(SOAPParameters::iterator itPar = parameters.begin(); itPar != parameters.end(); itPar++)
107 xoap::SOAPName parameterName = envelope.createName(itPar->first);
108 (*it).addAttribute(parameterName, itPar->second);
115 SOAPCommand SOAPUtilities::translate(
const xoap::MessageReference& message)
118 const std::vector<xoap::SOAPElement>& bodyList = message->getSOAPPart().getEnvelope().getBody().getChildElements();
119 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin(); it != bodyList.end(); it++)
121 xoap::SOAPElement element = *it;
122 soapCommand.setCommand(element.getElementName().getLocalName());
123 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes();
124 for(
unsigned int i = 0; i < parameters->getLength(); i++)
125 soapCommand.setParameter(xoap::XMLCh2String(parameters->item(i)->getNodeName()), xoap::XMLCh2String(parameters->item(i)->getNodeValue()));
131 std::string SOAPUtilities::receive(
const xoap::MessageReference& message,
SOAPCommand& soapCommand) {
return receive(message, soapCommand.getParametersRef()); }
134 std::string SOAPUtilities::receive(
const xoap::MessageReference& message)
138 return (message->getSOAPPart().getEnvelope().getBody().getChildElements()).begin()->getElementName().getLocalName();
142 std::string SOAPUtilities::receive(
const xoap::MessageReference& message,
SOAPParameters& parameters)
144 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
145 std::vector<xoap::SOAPElement> bodyList = envelope.getBody().getChildElements();
146 xoap::SOAPElement command = bodyList[0];
147 std::string commandName = command.getElementName().getLocalName();
148 xoap::SOAPName name = envelope.createName(
"Key");
150 for(SOAPParameters::iterator it = parameters.begin(); it != parameters.end(); it++)
152 name = envelope.createName(it->first);
156 it->second = command.getAttributeValue(name);
169 catch(xoap::exception::Exception& e)
171 __COUT__ <<
"Parameter " << it->first <<
" does not exist in the list of incoming parameters!" << std::endl;
172 XCEPT_RETHROW(xoap::exception::Exception,
"Looking for parameter that does not exist!", e);