38 using std::stringstream;
40 #include "BESXMLInterface.h" 41 #include "BESXMLCommand.h" 42 #include "BESXMLUtils.h" 43 #include "BESDataNames.h" 46 #include "BESSyntaxUserError.h" 47 #include "BESReturnManager.h" 49 BESXMLInterface::BESXMLInterface(
const string &xml_doc, ostream *strm) :
53 _dhi->data[DATA_REQUEST] =
"xml document";
54 _dhi->data[
"XMLDoc"] = xml_doc;
57 BESXMLInterface::~BESXMLInterface()
85 BESDEBUG(
"bes",
"Entering: " << __PRETTY_FUNCTION__ << endl);
86 BESDEBUG(
"besxml",
"building request plan for xml document: " << endl << _dhi->data[
"XMLDoc"] << endl);
88 if (BESLog::TheLog()->is_verbose()) {
89 *(BESLog::TheLog()) << _dhi->data[SERVER_PID] <<
" from " << _dhi->data[REQUEST_FROM] <<
"] building" << endl;
99 xmlNode *root_element = NULL;
100 xmlNode *current_node = NULL;
104 vector<string> parseerrors;
108 doc = xmlReadMemory(_dhi->data[
"XMLDoc"].c_str(), _dhi->data[
"XMLDoc"].size(),
"" ,
109 NULL , XML_PARSE_NONET );
112 string err =
"Problem parsing the request xml document:\n";
114 vector<string>::const_iterator i = parseerrors.begin();
115 vector<string>::const_iterator e = parseerrors.end();
116 for (; i != e; i++) {
117 if (!isfirst && (*i).compare(0, 6,
"Entity") == 0) {
127 root_element = xmlDocGetRootElement(doc);
129 string err =
"There is no root element in the xml document";
135 map<string, string> props;
137 if (root_name !=
"request") {
138 string err = (string)
"The root element should be a request element, " +
"name is " 139 + (
char *) root_element->name;
142 if (root_val !=
"") {
143 string err = (string)
"The request element must not contain a value, " + root_val;
148 string &reqId = props[REQUEST_ID];
150 string err = (string)
"request id value empty";
153 _dhi->data[REQUEST_ID] = reqId;
155 BESDEBUG(
"besxml",
"request id = " << _dhi->data[REQUEST_ID] << endl);
159 bool has_response =
false;
160 current_node = root_element->children;
162 while (current_node) {
163 if (current_node->type == XML_ELEMENT_NODE) {
166 string node_name = (
char *) current_node->name;
172 string err = (string)
"Failed to build command object for " + node_name;
177 _cmd_list.push_back(current_cmd);
182 if (has_response && cmd_has_response) {
183 string err =
"Multiple responses not allowed";
186 has_response = cmd_has_response;
189 BESDEBUG(
"besxml",
"parse request using " << node_name << endl);
194 BESDEBUG(
"besxml", node_name <<
" parsed request, dhi = " << current_dhi << endl);
196 string returnAs = current_dhi.
data[RETURN_CMD];
197 if (returnAs !=
"") {
198 BESDEBUG(
"xml",
"Finding transmitter: " << returnAs <<
" ... " << endl);
199 BESTransmitter *transmitter = BESReturnManager::TheManager()->find_transmitter(returnAs);
201 string s = (string)
"Unable to find transmitter " + returnAs;
204 BESDEBUG(
"xml",
"OK" << endl);
208 string err = (string)
"Unable to find command for " + node_name;
212 current_node = current_node->next;
235 BESDEBUG(
"besxml",
"Done building request plan" << endl);
244 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
245 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
246 for (; i != e; i++) {
247 (*i)->prep_request();
248 _dhi = &(*i)->get_dhi();
264 string returnAs = _dhi->data[RETURN_CMD];
265 if (returnAs !=
"") {
266 BESDEBUG(
"xml",
"Setting transmitter: " << returnAs <<
" ... " << endl);
267 _transmitter = BESReturnManager::TheManager()->find_transmitter(returnAs);
269 string s = (string)
"Unable to find transmitter " + returnAs;
272 BESDEBUG(
"xml",
"OK" << endl);
284 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
285 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
286 for (; i != e; i++) {
287 _dhi = &(*i)->get_dhi();
309 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
310 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
311 for (; i != e; i++) {
312 _dhi = &(*i)->get_dhi();
321 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
322 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
323 for (; i != e; i++) {
340 strm << BESIndent::LMarg <<
"BESXMLInterface::dump - (" << (
void *)
this <<
")" << endl;
343 vector<BESXMLCommand *>::const_iterator i = _cmd_list.begin();
344 vector<BESXMLCommand *>::const_iterator e = _cmd_list.end();
345 for (; i != e; i++) {
349 BESIndent::UnIndent();
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
exception thrown if inernal error encountered
Entry point into BES using string command requests.
virtual void invoke_aggregation()
Invoke the aggregation server, if there is one.
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
virtual void initialize()
Initialize the BES.
virtual void parse_request(xmlNode *node)=0
Parse the XML request document begining at the given node.
virtual void log_status()
Log the status of the request to the BESLog file.
virtual BESDataHandlerInterface & get_dhi()
Return the current BESDataHandlerInterface.
virtual void transmit_data()
Transmit the response object.
virtual void build_data_request_plan()
Build the data request plan using the BESCmdParser.
error thrown if there is a user syntax error in the request or any other user error ...
virtual void build_data_request_plan()
Build the data request plan using the BESCmdParser.
virtual void execute_data_request_plan()
Execute the data request plan.
static void XMLErrorFunc(void *context, const char *msg,...)
error function used by libxml2 to report errors
virtual void log_status()
Log the status of the request to the BESLog file.
virtual void clean()
Clean up after the request is completed.
virtual void report_request()
Report the request and status of the request to BESReporterList::TheList()
virtual void invoke_aggregation()
Invoke the aggregation server, if there is one.
virtual void report_request()
Report the request and status of the request.
virtual void validate_data_request()
Validate the incoming request information.
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
virtual void transmit_data()
Transmit the response object.
virtual void validate_data_request()
Validate the incoming request information.
virtual void execute_data_request_plan()
Execute the data request plan.
virtual void initialize()
Initialize the BES.
virtual void clean()
Clean up after the request is completed.
virtual bool has_response()=0
Has a response handler been created given the request document?
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
static p_xmlcmd_builder find_command(const string &cmd_str)
Find the BESXMLCommand creation function with the given name.
virtual void dump(ostream &strm) const
dumps information about this object