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";
58 _dhi->data[
"XMLDoc"] = xml_doc;
61 BESXMLInterface::~BESXMLInterface()
89 BESDEBUG(
"bes",
"Entering: " << __PRETTY_FUNCTION__ << endl);
90 BESDEBUG(
"besxml",
"building request plan for xml document: " << endl << _dhi->
data[
"XMLDoc"] << endl);
92 if (BESLog::TheLog()->is_verbose()) {
93 *(BESLog::TheLog()) << _dhi->
data[SERVER_PID] <<
" from " << _dhi->
data[REQUEST_FROM] <<
"] building" << endl;
103 xmlNode *root_element = NULL;
104 xmlNode *current_node = NULL;
108 vector<string> parseerrors;
112 doc = xmlReadMemory(_dhi->
data[
"XMLDoc"].c_str(), _dhi->
data[
"XMLDoc"].size(),
"" ,
113 NULL , XML_PARSE_NONET );
116 string err =
"Problem parsing the request xml document:\n";
118 vector<string>::const_iterator i = parseerrors.begin();
119 vector<string>::const_iterator e = parseerrors.end();
120 for (; i != e; i++) {
121 if (!isfirst && (*i).compare(0, 6,
"Entity") == 0) {
131 root_element = xmlDocGetRootElement(doc);
133 string err =
"There is no root element in the xml document";
139 map<string, string> props;
141 if (root_name !=
"request") {
142 string err = (string)
"The root element should be a request element, " +
"name is " 143 + (
char *) root_element->name;
146 if (root_val !=
"") {
147 string err = (string)
"The request element must not contain a value, " + root_val;
152 string &reqId = props[REQUEST_ID];
154 string err = (string)
"request id value empty";
157 _dhi->
data[REQUEST_ID] = reqId;
159 BESDEBUG(
"besxml",
"request id = " << _dhi->
data[REQUEST_ID] << endl);
163 bool has_response =
false;
164 current_node = root_element->children;
166 while (current_node) {
167 if (current_node->type == XML_ELEMENT_NODE) {
170 string node_name = (
char *) current_node->name;
176 string err = (string)
"Failed to build command object for " + node_name;
181 _cmd_list.push_back(current_cmd);
186 if (has_response && cmd_has_response) {
187 string err =
"Multiple responses not allowed";
190 has_response = cmd_has_response;
193 BESDEBUG(
"besxml",
"parse request using " << node_name << endl);
198 BESDEBUG(
"besxml", node_name <<
" parsed request, dhi = " << current_dhi << endl);
200 string returnAs = current_dhi.
data[RETURN_CMD];
201 if (returnAs !=
"") {
202 BESDEBUG(
"xml",
"Finding transmitter: " << returnAs <<
" ... " << endl);
203 BESTransmitter *transmitter = BESReturnManager::TheManager()->find_transmitter(returnAs);
205 string s = (string)
"Unable to find transmitter " + returnAs;
208 BESDEBUG(
"xml",
"OK" << endl);
212 string err = (string)
"Unable to find command for " + node_name;
216 current_node = current_node->next;
239 BESDEBUG(
"besxml",
"Done building request plan" << endl);
248 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
249 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
250 for (; i != e; i++) {
251 (*i)->prep_request();
252 _dhi = &(*i)->get_dhi();
268 string returnAs = _dhi->
data[RETURN_CMD];
269 if (returnAs !=
"") {
270 BESDEBUG(
"xml",
"Setting transmitter: " << returnAs <<
" ... " << endl);
271 _transmitter = BESReturnManager::TheManager()->find_transmitter(returnAs);
273 string s = (string)
"Unable to find transmitter " + returnAs;
276 BESDEBUG(
"xml",
"OK" << endl);
288 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
289 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
290 for (; i != e; i++) {
291 _dhi = &(*i)->get_dhi();
313 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
314 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
315 for (; i != e; i++) {
316 _dhi = &(*i)->get_dhi();
325 vector<BESXMLCommand *>::iterator i = _cmd_list.begin();
326 vector<BESXMLCommand *>::iterator e = _cmd_list.end();
327 for (; i != e; i++) {
344 strm << BESIndent::LMarg <<
"BESXMLInterface::dump - (" << (
void *)
this <<
")" << endl;
347 vector<BESXMLCommand *>::const_iterator i = _cmd_list.begin();
348 vector<BESXMLCommand *>::const_iterator e = _cmd_list.end();
349 for (; i != e; i++) {
353 BESIndent::UnIndent();
virtual int execute_request(const string &from)
Override execute_request in order to register memory pool.
exception thrown if inernal error encountered
virtual void dump(ostream &strm) const
dumps information about this object
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 dump(ostream &strm) const
dumps information about this object
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 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