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