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"
9 #include "xoap/MessageFactory.h"
10 #include "xoap/SOAPPart.h"
11 #include "xoap/SOAPEnvelope.h"
12 #include "xoap/SOAPBody.h"
13 #include "xoap/domutils.h"
14 #include "xoap/AttachmentPart.h"
20 SOAPUtilities::SOAPUtilities(
void)
24 SOAPUtilities::~SOAPUtilities(
void)
28 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(
SOAPCommand soapCommand)
30 if(soapCommand.hasParameters())
31 return makeSOAPMessageReference(soapCommand.getCommand(), soapCommand.getParameters());
33 return makeSOAPMessageReference(soapCommand.getCommand());
37 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command)
39 xoap::MessageReference message = xoap::createMessage();
40 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
41 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
42 xoap::SOAPBody body = envelope.getBody();
43 body.addBodyElement(name);
48 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command,
SOAPParameters parameters)
51 if(parameters.size() == 0)
52 return makeSOAPMessageReference(command);
53 xoap::MessageReference message = xoap::createMessage();
54 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
55 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
56 xoap::SOAPBody body = envelope.getBody();
57 xoap::SOAPElement bodyCommand = body.addBodyElement(name);
58 xoap::SOAPName parameterName = envelope.createName(
"Null");
59 for (SOAPParameters::iterator it=parameters.begin(); it!=parameters.end(); it++)
61 parameterName = envelope.createName(it->first);
62 bodyCommand.addAttribute(parameterName,it->second);
69 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command, std::string fileName)
71 std::cout << __COUT_HDR_FL__ <<
"SOAP XML file path : " << fileName << std::endl;
72 xoap::MessageReference message = xoap::createMessage();
73 xoap::SOAPPart soap = message->getSOAPPart();
74 xoap::SOAPEnvelope envelope = soap.getEnvelope();
75 xoap::AttachmentPart* attachment;
76 attachment = message->createAttachmentPart();
77 attachment->setContent(fileName);
78 attachment->setContentId(
"SOAPTEST1");
79 attachment->addMimeHeader(
"Content-Description",
"This is a SOAP message with attachments");
80 message->addAttachmentPart(attachment);
81 xoap::SOAPName name = envelope.createName(command,
"xdaq", XDAQ_NS_URI);
82 xoap::SOAPBody body= envelope.getBody();
83 body.addBodyElement(name);
88 void SOAPUtilities::addParameters(xoap::MessageReference& message,
SOAPParameters parameters)
90 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ <<
"adding parameters!!!!!!" << std::endl;
91 if(parameters.size() == 0)
return;
92 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
93 xoap::SOAPBody body = envelope.getBody();
94 xoap::SOAPName name(translate(message).getCommand(),
"xdaq", XDAQ_NS_URI);
96 std::vector<xoap::SOAPElement> bodyList = body.getChildElements();
97 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin(); it != bodyList.end(); it++)
99 if((*it).getElementName() == name)
101 for (SOAPParameters::iterator itPar=parameters.begin(); itPar!=parameters.end(); itPar++)
103 xoap::SOAPName parameterName = envelope.createName(itPar->first);
104 (*it).addAttribute(parameterName,itPar->second);
111 SOAPCommand SOAPUtilities::translate(
const xoap::MessageReference& message)
114 const std::vector<xoap::SOAPElement>& bodyList = message->getSOAPPart().getEnvelope().getBody().getChildElements();
115 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin(); it != bodyList.end(); it++)
117 xoap::SOAPElement element = *it;
118 soapCommand.setCommand(element.getElementName().getLocalName());
119 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes();
120 for(
unsigned int i=0; i<parameters->getLength(); i++)
121 soapCommand.setParameter(xoap::XMLCh2String(parameters->item(i)->getNodeName()), xoap::XMLCh2String(parameters->item(i)->getNodeValue()));