40 #include "BESXMLInterface.h"
41 #include "BESXMLCommand.h"
42 #include "BESXMLUtils.h"
43 #include "BESDataNames.h"
45 #include "BESResponseHandler.h"
46 #include "BESReturnManager.h"
48 #include "BESStopWatch.h"
52 #include "BESSyntaxUserError.h"
54 #define LOG_ONLY_GET_COMMANDS
56 BESXMLInterface::BESXMLInterface(
const string &xml_doc, ostream *strm) :
61 d_dhi_ptr = &d_xml_interface_dhi;
64 BESXMLInterface::~BESXMLInterface()
73 BESDEBUG(
"bes",
"Entering: " << __PRETTY_FUNCTION__ << endl);
74 BESDEBUG(
"bes",
"building request plan for xml document: " << endl << d_xml_document << endl);
84 xmlNode *root_element = NULL;
85 xmlNode *current_node = NULL;
89 vector<string> parseerrors;
93 doc = xmlReadMemory(d_xml_document.c_str(), d_xml_document.size(),
"" ,
94 NULL , XML_PARSE_NONET );
97 string err =
"Problem parsing the request xml document:\n";
99 vector<string>::const_iterator i = parseerrors.begin();
100 vector<string>::const_iterator e = parseerrors.end();
101 for (; i != e; i++) {
102 if (!isfirst && (*i).compare(0, 6,
"Entity") == 0) {
112 root_element = xmlDocGetRootElement(doc);
113 if (!root_element)
throw BESSyntaxUserError(
"There is no root element in the xml document", __FILE__, __LINE__);
117 map<string, string> attributes;
119 if (root_name !=
"request")
121 string(
"The root element should be a request element, name is ").append((
char *) root_element->name),
124 if (!root_val.empty())
125 throw BESSyntaxUserError(
string(
"The request element must not contain a value, ").append(root_val),
129 string &reqId = attributes[REQUEST_ID];
130 if (reqId.empty())
throw BESSyntaxUserError(
"The request id value empty", __FILE__, __LINE__);
134 BESDEBUG(
"besxml",
"request id = " <<
d_dhi_ptr->
data[REQUEST_ID] << endl);
138 bool has_response =
false;
139 current_node = root_element->children;
141 while (current_node) {
142 if (current_node->type == XML_ELEMENT_NODE) {
145 string node_name = (
char *) current_node->name;
154 throw BESSyntaxUserError(
string(
"Unable to find command for ").append(node_name), __FILE__,
159 throw BESInternalError(
string(
"Failed to build command object for ").append(node_name), __FILE__,
163 d_xml_cmd_list.push_back(current_cmd);
167 if (has_response && cmd_has_response)
168 throw BESSyntaxUserError(
"Commands with multiple responses not supported.", __FILE__, __LINE__);
170 has_response = cmd_has_response;
182 string return_as = current_dhi.
data[RETURN_CMD];
183 if (!return_as.empty() && !BESReturnManager::TheManager()->find_transmitter(return_as))
184 throw BESSyntaxUserError(
string(
"Unable to find transmitter ").append(return_as), __FILE__,
188 current_node = current_node->next;
211 BESDEBUG(
"bes",
"Done building request plan" << endl);
218 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
219 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
220 for (; i != e; i++) {
221 (*i)->prep_request();
232 #ifdef LOG_ONLY_GET_COMMANDS
239 new_log_info.append(
",").append(
d_dhi_ptr->
data[RETURN_CMD]);
256 LOG(new_log_info << endl);
259 LOG(
"Warning: The previous command had multiple containers defined, but only the was logged.");
312 LOG(
"Transmitting error: " << strm.str() << endl);
323 if (!return_as.empty()) {
324 d_transmitter = BESReturnManager::TheManager()->find_transmitter(return_as);
326 throw BESSyntaxUserError(
string(
"Unable to find transmitter ") + return_as, __FILE__, __LINE__);
343 if (BESLog::TheLog()->is_verbose()) {
344 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
345 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
346 for (; i != e; i++) {
362 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
363 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
364 for (; i != e; i++) {
377 d_xml_cmd_list.clear();
388 strm << BESIndent::LMarg <<
"BESXMLInterface::dump - (" << (
void *)
this <<
")" << endl;
391 vector<BESXMLCommand *>::const_iterator i = d_xml_cmd_list.begin();
392 vector<BESXMLCommand *>::const_iterator e = d_xml_cmd_list.end();
393 for (; i != e; i++) {
397 BESIndent::UnIndent();