$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h" 00002 00003 #include "otsdaq-core/Macros/CoutMacros.h" 00004 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00005 00006 #include <xdaq/NamespaceURI.h> 00007 #include <xoap/MessageReference.h> 00008 #include <xoap/Method.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/AttachmentPart.h> 00016 #include <xoap/SOAPBody.h> 00017 #include <xoap/SOAPEnvelope.h> 00018 #include <xoap/SOAPPart.h> 00019 #include <xoap/domutils.h> 00020 00021 using namespace ots; 00022 00023 //======================================================================================================================== 00024 SOAPUtilities::SOAPUtilities(void) {} 00025 00026 //======================================================================================================================== 00027 SOAPUtilities::~SOAPUtilities(void) {} 00028 00029 //======================================================================================================================== 00030 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(SOAPCommand soapCommand) 00031 { 00032 if(soapCommand.hasParameters()) 00033 return makeSOAPMessageReference(soapCommand.getCommand(), 00034 soapCommand.getParameters()); 00035 else 00036 return makeSOAPMessageReference(soapCommand.getCommand()); 00037 } 00038 00039 //======================================================================================================================== 00040 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command) 00041 { 00042 xoap::MessageReference message = xoap::createMessage(); 00043 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope(); 00044 xoap::SOAPName name = envelope.createName(command, "xdaq", XDAQ_NS_URI); 00045 xoap::SOAPBody body = envelope.getBody(); 00046 body.addBodyElement(name); 00047 return message; 00048 } 00049 00050 //======================================================================================================================== 00051 xoap::MessageReference SOAPUtilities::makeSOAPMessageReference(std::string command, 00052 SOAPParameters parameters) 00053 { 00054 //__COUT__ << "Command: " << command << " par size: " << parameters.size() << 00055 // std::endl; 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, 00075 std::string fileName) 00076 { 00077 __COUT__ << "SOAP XML file path : " << fileName << std::endl; 00078 xoap::MessageReference message = xoap::createMessage(); 00079 xoap::SOAPPart soap = message->getSOAPPart(); 00080 xoap::SOAPEnvelope envelope = soap.getEnvelope(); 00081 xoap::AttachmentPart* attachment; 00082 attachment = message->createAttachmentPart(); 00083 attachment->setContent(fileName); 00084 attachment->setContentId("SOAPTEST1"); 00085 attachment->addMimeHeader("Content-Description", 00086 "This is a SOAP message with attachments"); 00087 message->addAttachmentPart(attachment); 00088 xoap::SOAPName name = envelope.createName(command, "xdaq", XDAQ_NS_URI); 00089 xoap::SOAPBody body = envelope.getBody(); 00090 body.addBodyElement(name); 00091 return message; 00092 } 00093 00094 //======================================================================================================================== 00095 void SOAPUtilities::addParameters(xoap::MessageReference& message, 00096 SOAPParameters parameters) 00097 { 00098 //__COUT__ << "adding parameters!!!!!!" << std::endl; 00099 if(parameters.size() == 0) 00100 return; 00101 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope(); 00102 xoap::SOAPBody body = envelope.getBody(); 00103 xoap::SOAPName name(translate(message).getCommand(), "xdaq", XDAQ_NS_URI); 00104 00105 std::vector<xoap::SOAPElement> bodyList = body.getChildElements(); 00106 for(std::vector<xoap::SOAPElement>::iterator it = bodyList.begin(); 00107 it != bodyList.end(); 00108 it++) 00109 { 00110 if((*it).getElementName() == name) 00111 { 00112 for(SOAPParameters::iterator itPar = parameters.begin(); 00113 itPar != parameters.end(); 00114 itPar++) 00115 { 00116 xoap::SOAPName parameterName = envelope.createName(itPar->first); 00117 (*it).addAttribute(parameterName, itPar->second); 00118 } 00119 } 00120 } 00121 } 00122 00123 //======================================================================================================================== 00124 SOAPCommand SOAPUtilities::translate(const xoap::MessageReference& message) 00125 { 00126 SOAPCommand soapCommand; 00127 const std::vector<xoap::SOAPElement>& bodyList = 00128 message->getSOAPPart().getEnvelope().getBody().getChildElements(); 00129 for(std::vector<xoap::SOAPElement>::const_iterator it = bodyList.begin(); 00130 it != bodyList.end(); 00131 it++) 00132 { 00133 xoap::SOAPElement element = *it; 00134 soapCommand.setCommand(element.getElementName().getLocalName()); 00135 DOMNamedNodeMap* parameters = element.getDOM()->getAttributes(); 00136 for(unsigned int i = 0; i < parameters->getLength(); i++) 00137 soapCommand.setParameter( 00138 xoap::XMLCh2String(parameters->item(i)->getNodeName()), 00139 xoap::XMLCh2String(parameters->item(i)->getNodeValue())); 00140 } 00141 return soapCommand; 00142 } 00143 00144 //======================================================================================================================== 00145 std::string SOAPUtilities::receive(const xoap::MessageReference& message, 00146 SOAPCommand& soapCommand) 00147 { 00148 return receive(message, soapCommand.getParametersRef()); 00149 } 00150 00151 //======================================================================================================================== 00152 std::string SOAPUtilities::receive(const xoap::MessageReference& message) 00153 { 00154 // NOTE it is assumed that there is only 1 command for each message (that's why we use 00155 // begin) 00156 return (message->getSOAPPart().getEnvelope().getBody().getChildElements()) 00157 .begin() 00158 ->getElementName() 00159 .getLocalName(); 00160 } 00161 00162 //======================================================================================================================== 00163 std::string SOAPUtilities::receive(const xoap::MessageReference& message, 00164 SOAPParameters& parameters) 00165 { 00166 xoap::SOAPEnvelope envelope = message->getSOAPPart().getEnvelope(); 00167 std::vector<xoap::SOAPElement> bodyList = envelope.getBody().getChildElements(); 00168 xoap::SOAPElement command = bodyList[0]; 00169 std::string commandName = command.getElementName().getLocalName(); 00170 xoap::SOAPName name = envelope.createName("Key"); 00171 00172 for(SOAPParameters::iterator it = parameters.begin(); it != parameters.end(); it++) 00173 { 00174 name = envelope.createName(it->first); 00175 00176 try 00177 { 00178 it->second = command.getAttributeValue(name); 00179 // if( parameters.getParameter(it->first).isEmpty() ) 00180 //{ 00181 // __COUT__ << "Complaint from " << 00182 // (theApplication_->getApplicationDescriptor()->getClassName()) << 00183 // std::endl; 00184 // __COUT__ << " : Parameter "<< it->first 00185 // << " does not exist in the list of incoming parameters!" << std::endl; 00186 // __COUT__ << "It could also be because you passed an empty std::string" 00187 // << std::endl; 00188 // //assert(0); 00189 //}; 00190 } 00191 catch(xoap::exception::Exception& e) 00192 { 00193 __COUT__ << "Parameter " << it->first 00194 << " does not exist in the list of incoming parameters!" 00195 << std::endl; 00196 XCEPT_RETHROW(xoap::exception::Exception, 00197 "Looking for parameter that does not exist!", 00198 e); 00199 } 00200 } 00201 00202 return commandName; 00203 }