1 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
2 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
4 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
6 #include <xoap/Method.h>
7 #include <xdaq/NamespaceURI.h>
8 #include <xoap/MessageReference.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/SOAPPart.h>
16 #include <xoap/SOAPEnvelope.h>
17 #include <xoap/SOAPBody.h>
18 #include <xoap/domutils.h>
19 #include <xoap/AttachmentPart.h>
25 SOAPUtilities::SOAPUtilities(
void)
29 SOAPUtilities::~SOAPUtilities(
void)
33 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(
SOAPCommand soapCommand)
35 if(soapCommand.hasParameters())
36 return makeSOAPMessageReference(soapCommand.getCommand(), soapCommand.getParameters());
38 return makeSOAPMessageReference(soapCommand.getCommand());
42 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command)
44 xoap::MessageReference message = xoap::createMessage();
45 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
46 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
47 xoap::SOAPBody body = envelope.getBody();
48 body.addBodyElement(name);
53 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command,
SOAPParameters parameters)
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, std::string fileName)
76 std::cout << __COUT_HDR_FL__ <<
"SOAP XML file path : " << fileName << std::endl;
77 xoap::MessageReference message = xoap::createMessage();
78 xoap::SOAPPart soap = message->getSOAPPart();
79 xoap::SOAPEnvelope envelope = soap.getEnvelope();
80 xoap::AttachmentPart* attachment;
81 attachment = message->createAttachmentPart();
82 attachment->setContent(fileName);
83 attachment->setContentId(
"SOAPTEST1");
84 attachment->addMimeHeader(
"Content-Description",
"This is a SOAP message with attachments");
85 message->addAttachmentPart(attachment);
86 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
87 xoap::SOAPBody body= envelope.getBody();
88 body.addBodyElement(name);
93 void SOAPUtilities::addParameters(xoap::MessageReference& message,
SOAPParameters parameters)
95 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ <<
"adding parameters!!!!!!" << std::endl;
96 if(parameters.size() == 0)
return;
97 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
98 xoap::SOAPBody body = envelope.getBody();
99 xoap::SOAPName name(translate(message).getCommand(),
"xdaq", XDAQ_NS_URI);
101 std::vector<xoap::SOAPElement> bodyList = body.getChildElements();
102 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin(); it != bodyList.end(); it++)
104 if((*it).getElementName() == name)
106 for (SOAPParameters::iterator itPar=parameters.begin(); itPar!=parameters.end(); itPar++)
108 xoap::SOAPName parameterName = envelope.createName(itPar->first);
109 (*it).addAttribute(parameterName,itPar->second);
116 SOAPCommand SOAPUtilities::translate(
const xoap::MessageReference& message)
119 const std::vector<xoap::SOAPElement>& bodyList = message->getSOAPPart().getEnvelope().getBody().getChildElements();
120 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin(); it != bodyList.end(); it++)
122 xoap::SOAPElement element = *it;
123 soapCommand.setCommand(element.getElementName().getLocalName());
124 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes();
125 for(
unsigned int i=0; i<parameters->getLength(); i++)
126 soapCommand.setParameter(xoap::XMLCh2String(parameters->item(i)->getNodeName()), xoap::XMLCh2String(parameters->item(i)->getNodeValue()));