00001 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
00002 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
00003 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00004 #include "otsdaq-core/Macros/CoutMacros.h"
00005
00006 #include <xoap/Method.h>
00007 #include <xdaq/NamespaceURI.h>
00008 #include <xoap/MessageReference.h>
00009
00010 #pragma GCC diagnostic push
00011 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
00012 #include <xoap/MessageFactory.h>
00013 #pragma GCC diagnostic pop
00014
00015 #include <xoap/SOAPPart.h>
00016 #include <xoap/SOAPEnvelope.h>
00017 #include <xoap/SOAPBody.h>
00018 #include <xoap/domutils.h>
00019 #include <xoap/AttachmentPart.h>
00020
00021 using namespace ots;
00022
00023
00024
00025 SOAPUtilities::SOAPUtilities(void)
00026 {}
00027
00028
00029 SOAPUtilities::~SOAPUtilities(void)
00030 {}
00031
00032
00033 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(SOAPCommand soapCommand)
00034 {
00035 if(soapCommand.hasParameters())
00036 return makeSOAPMessageReference(soapCommand.getCommand(), soapCommand.getParameters());
00037 else
00038 return makeSOAPMessageReference(soapCommand.getCommand());
00039 }
00040
00041
00042 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command)
00043 {
00044 xoap::MessageReference message = xoap::createMessage();
00045 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
00046 xoap::SOAPName name = envelope.createName(command, "xdaq", XDAQ_NS_URI);
00047 xoap::SOAPBody body = envelope.getBody();
00048 body.addBodyElement(name);
00049 return message;
00050 }
00051
00052
00053 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command, SOAPParameters parameters)
00054 {
00055
00056 if(parameters.size() == 0)
00057 return makeSOAPMessageReference(command);
00058 xoap::MessageReference message = xoap::createMessage();
00059 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
00060 xoap::SOAPName name = envelope.createName(command, "xdaq", XDAQ_NS_URI);
00061 xoap::SOAPBody body = envelope.getBody();
00062 xoap::SOAPElement bodyCommand = body.addBodyElement(name);
00063 xoap::SOAPName parameterName = envelope.createName("Null");
00064 for (SOAPParameters::iterator it=parameters.begin(); it!=parameters.end(); it++)
00065 {
00066 parameterName = envelope.createName(it->first);
00067 bodyCommand.addAttribute(parameterName,it->second);
00068 }
00069
00070 return message;
00071 }
00072
00073
00074 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command, std::string fileName)
00075 {
00076 std::cout << __COUT_HDR_FL__ << "SOAP XML file path : " << fileName << std::endl;
00077 xoap::MessageReference message = xoap::createMessage();
00078 xoap::SOAPPart soap = message->getSOAPPart();
00079 xoap::SOAPEnvelope envelope = soap.getEnvelope();
00080 xoap::AttachmentPart* attachment;
00081 attachment = message->createAttachmentPart();
00082 attachment->setContent(fileName);
00083 attachment->setContentId("SOAPTEST1");
00084 attachment->addMimeHeader("Content-Description", "This is a SOAP message with attachments");
00085 message->addAttachmentPart(attachment);
00086 xoap::SOAPName name = envelope.createName(command, "xdaq", XDAQ_NS_URI);
00087 xoap::SOAPBody body= envelope.getBody();
00088 body.addBodyElement(name);
00089 return message;
00090 }
00091
00092
00093 void SOAPUtilities::addParameters(xoap::MessageReference& message, SOAPParameters parameters)
00094 {
00095 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "adding parameters!!!!!!" << std::endl;
00096 if(parameters.size() == 0) return;
00097 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope();
00098 xoap::SOAPBody body = envelope.getBody();
00099 xoap::SOAPName name(translate(message).getCommand(), "xdaq", XDAQ_NS_URI);
00100
00101 std::vector<xoap::SOAPElement> bodyList = body.getChildElements();
00102 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin(); it != bodyList.end(); it++)
00103 {
00104 if((*it).getElementName() == name)
00105 {
00106 for (SOAPParameters::iterator itPar=parameters.begin(); itPar!=parameters.end(); itPar++)
00107 {
00108 xoap::SOAPName parameterName = envelope.createName(itPar->first);
00109 (*it).addAttribute(parameterName,itPar->second);
00110 }
00111 }
00112 }
00113 }
00114
00115
00116 SOAPCommand SOAPUtilities::translate(const xoap::MessageReference& message)
00117 {
00118 SOAPCommand soapCommand;
00119 const std::vector<xoap::SOAPElement>& bodyList = message->getSOAPPart().getEnvelope().getBody().getChildElements();
00120 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin(); it != bodyList.end(); it++)
00121 {
00122 xoap::SOAPElement element = *it;
00123 soapCommand.setCommand(element.getElementName().getLocalName());
00124 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes();
00125 for(unsigned int i=0; i<parameters->getLength(); i++)
00126 soapCommand.setParameter(xoap::XMLCh2String(parameters->item(i)->getNodeName()), xoap::XMLCh2String(parameters->item(i)->getNodeValue()));
00127 }
00128 return soapCommand;
00129 }