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(),
34 soapCommand.getParameters());
36 return makeSOAPMessageReference(soapCommand.
getCommand());
40 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command)
42 xoap::MessageReference message = xoap::createMessage();
43 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
44 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
45 xoap::SOAPBody body = envelope.getBody();
46 body.addBodyElement(name);
51 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command,
56 if(parameters.
size() == 0)
57 return makeSOAPMessageReference(command);
58 xoap::MessageReference message = xoap::createMessage();
59 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
60 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
61 xoap::SOAPBody body = envelope.getBody();
62 xoap::SOAPElement bodyCommand = body.addBodyElement(name);
63 xoap::SOAPName parameterName = envelope.createName(
"Null");
64 for(SOAPParameters::iterator it = parameters.
begin(); it != parameters.end(); it++)
66 parameterName = envelope.createName(it->first);
67 bodyCommand.addAttribute(parameterName, it->second);
74 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command,
77 __COUT__ <<
"SOAP XML file path : " << fileName << std::endl;
78 xoap::MessageReference message = xoap::createMessage();
79 xoap::SOAPPart soap = message->getSOAPPart();
80 xoap::SOAPEnvelope envelope = soap.getEnvelope();
81 xoap::AttachmentPart* attachment;
82 attachment = message->createAttachmentPart();
83 attachment->setContent(fileName);
84 attachment->setContentId(
"SOAPTEST1");
85 attachment->addMimeHeader(
"Content-Description",
86 "This is a SOAP message with attachments");
87 message->addAttachmentPart(attachment);
88 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
89 xoap::SOAPBody body = envelope.getBody();
90 body.addBodyElement(name);
95 void SOAPUtilities::addParameters(xoap::MessageReference& message,
99 if(parameters.
size() == 0)
101 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
102 xoap::SOAPBody body = envelope.getBody();
103 xoap::SOAPName name(translate(message).getCommand(),
"xdaq", XDAQ_NS_URI);
105 std::vector<xoap::SOAPElement> bodyList = body.getChildElements();
106 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin();
107 it != bodyList.end();
110 if((*it).getElementName() == name)
112 for(SOAPParameters::iterator itPar = parameters.
begin();
113 itPar != parameters.end();
116 xoap::SOAPName parameterName = envelope.createName(itPar->first);
117 (*it).addAttribute(parameterName, itPar->second);
124 SOAPCommand SOAPUtilities::translate(
const xoap::MessageReference& message)
127 const std::vector<xoap::SOAPElement>& bodyList =
128 message->getSOAPPart().getEnvelope().getBody().getChildElements();
129 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin();
130 it != bodyList.end();
133 xoap::SOAPElement element = *it;
134 soapCommand.setCommand(element.getElementName().getLocalName());
135 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes();
136 for(
unsigned int i = 0; i < parameters->getLength(); i++)
137 soapCommand.setParameter(
138 xoap::XMLCh2String(parameters->item(i)->getNodeName()),
139 xoap::XMLCh2String(parameters->item(i)->getNodeValue()));
145 std::string SOAPUtilities::receive(
const xoap::MessageReference& message,
148 return receive(message, soapCommand.getParametersRef());
152 std::string SOAPUtilities::receive(
const xoap::MessageReference& message)
156 return (message->getSOAPPart().getEnvelope().getBody().getChildElements())
163 std::string SOAPUtilities::receive(
const xoap::MessageReference& message,
166 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
167 std::vector<xoap::SOAPElement> bodyList = envelope.getBody().getChildElements();
168 xoap::SOAPElement command = bodyList[0];
169 std::string commandName = command.getElementName().getLocalName();
170 xoap::SOAPName name = envelope.createName(
"Key");
172 for(SOAPParameters::iterator it = parameters.
begin(); it != parameters.end(); it++)
174 name = envelope.createName(it->first);
178 it->second = command.getAttributeValue(name);
191 catch(xoap::exception::Exception& e)
193 __COUT__ <<
"Parameter " << it->first
194 <<
" does not exist in the list of incoming parameters!"
196 XCEPT_RETHROW(xoap::exception::Exception,
197 "Looking for parameter that does not exist!",
unsigned int size(void) const
Methods.
iterator begin(void)
Iterators.
const std::string & getCommand(void) const
Getters.