40 #include "BESXMLInterface.h"
41 #include "BESXMLCommand.h"
42 #include "BESXMLUtils.h"
43 #include "BESDataNames.h"
44 #include "BESContextManager.h"
46 #include "BESResponseHandler.h"
47 #include "BESReturnManager.h"
49 #include "BESStopWatch.h"
53 #include "BESSyntaxUserError.h"
55 #define LOG_ONLY_GET_COMMANDS
57 BESXMLInterface::BESXMLInterface(
const string &xml_doc, ostream *strm) :
62 d_dhi_ptr = &d_xml_interface_dhi;
65 BESXMLInterface::~BESXMLInterface()
74 BESDEBUG(
"bes",
"Entering: " << __PRETTY_FUNCTION__ << endl);
75 BESDEBUG(
"bes",
"building request plan for xml document: " << endl << d_xml_document << endl);
85 xmlNode *root_element = NULL;
86 xmlNode *current_node = NULL;
90 vector<string> parseerrors;
94 doc = xmlReadMemory(d_xml_document.c_str(), d_xml_document.size(),
"" ,
95 NULL , XML_PARSE_NONET );
98 string err =
"Problem parsing the request xml document:\n";
100 vector<string>::const_iterator i = parseerrors.begin();
101 vector<string>::const_iterator e = parseerrors.end();
102 for (; i != e; i++) {
103 if (!isfirst && (*i).compare(0, 6,
"Entity") == 0) {
113 root_element = xmlDocGetRootElement(doc);
114 if (!root_element)
throw BESSyntaxUserError(
"There is no root element in the xml document", __FILE__, __LINE__);
118 map<string, string> attributes;
120 if (root_name !=
"request")
122 string(
"The root element should be a request element, name is ").append((
char *) root_element->name),
125 if (!root_val.empty())
126 throw BESSyntaxUserError(
string(
"The request element must not contain a value, ").append(root_val),
130 string &reqId = attributes[REQUEST_ID];
131 if (reqId.empty())
throw BESSyntaxUserError(
"The request id value empty", __FILE__, __LINE__);
135 BESDEBUG(
"besxml",
"request id = " <<
d_dhi_ptr->
data[REQUEST_ID] << endl);
139 bool has_response =
false;
140 current_node = root_element->children;
142 while (current_node) {
143 if (current_node->type == XML_ELEMENT_NODE) {
146 string node_name = (
char *) current_node->name;
155 throw BESSyntaxUserError(
string(
"Unable to find command for ").append(node_name), __FILE__,
160 throw BESInternalError(
string(
"Failed to build command object for ").append(node_name), __FILE__,
164 d_xml_cmd_list.push_back(current_cmd);
168 if (has_response && cmd_has_response)
169 throw BESSyntaxUserError(
"Commands with multiple responses not supported.", __FILE__, __LINE__);
171 has_response = cmd_has_response;
183 string return_as = current_dhi.
data[RETURN_CMD];
184 if (!return_as.empty() && !BESReturnManager::TheManager()->find_transmitter(return_as))
185 throw BESSyntaxUserError(
string(
"Unable to find transmitter ").append(return_as), __FILE__,
189 current_node = current_node->next;
212 BESDEBUG(
"bes",
"Done building request plan" << endl);
219 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
220 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
221 for (; i != e; i++) {
222 (*i)->prep_request();
233 #ifdef LOG_ONLY_GET_COMMANDS
238 string log_delim=
"|&|";
240 string new_log_info =
"";
244 string olfs_log_line = BESContextManager::TheManager()->
get_context(
"olfsLog", found);
246 new_log_info.append(
"OLFS").append(log_delim).append(olfs_log_line).append(log_delim);
247 new_log_info.append(
"BES").append(log_delim);
254 new_log_info.append(log_delim).append(
d_dhi_ptr->
data[RETURN_CMD]);
271 LOG(new_log_info << endl);
274 LOG(
"Warning: The previous command had multiple containers defined, but only the was logged.");
277 if (!BESLog::TheLog()->is_verbose()) {
327 LOG(
"Transmitting error: " << strm.str() << endl);
338 if (!return_as.empty()) {
339 d_transmitter = BESReturnManager::TheManager()->find_transmitter(return_as);
341 throw BESSyntaxUserError(
string(
"Unable to find transmitter ") + return_as, __FILE__, __LINE__);
358 if (BESLog::TheLog()->is_verbose()) {
359 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
360 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
361 for (; i != e; i++) {
377 vector<BESXMLCommand *>::iterator i = d_xml_cmd_list.begin();
378 vector<BESXMLCommand *>::iterator e = d_xml_cmd_list.end();
379 for (; i != e; i++) {
392 d_xml_cmd_list.clear();
403 strm << BESIndent::LMarg <<
"BESXMLInterface::dump - (" << (
void *)
this <<
")" << endl;
406 vector<BESXMLCommand *>::const_iterator i = d_xml_cmd_list.begin();
407 vector<BESXMLCommand *>::const_iterator e = d_xml_cmd_list.end();
408 for (; i != e; i++) {
412 BESIndent::UnIndent();