bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESRequestHandler.cc
1// BESRequestHandler.cc
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#include <sys/stat.h>
34#include <string.h>
35
36#include "BESRequestHandler.h"
37#include "BESNotFoundError.h"
38
39using std::endl;
40using std::ostream;
41using std::string;
42
58bool BESRequestHandler::add_method(const string &handler_name, p_request_handler_method handler_method)
59{
60 if (find_method(handler_name) == 0) {
61 _handler_list[handler_name] = handler_method;
62 return true;
63 }
64 return false;
65}
66
74bool BESRequestHandler::remove_method(const string &handler_name)
75{
76 BESRequestHandler::Handler_iter i;
77 i = _handler_list.find(handler_name);
78 if (i != _handler_list.end()) {
79 _handler_list.erase(i);
80 return true;
81 }
82 return false;
83}
84
95p_request_handler_method BESRequestHandler::find_method(const string &handler_name)
96{
97 BESRequestHandler::Handler_citer i;
98 i = _handler_list.find(handler_name);
99 if (i != _handler_list.end()) {
100 return (*i).second;
101 }
102 return 0;
103}
104
113{
114 string ret = "";
115 bool first_name = true;
116 BESRequestHandler::Handler_citer i = _handler_list.begin();
117 for (; i != _handler_list.end(); i++) {
118 if (!first_name) ret += ", ";
119 ret += (*i).first;
120 first_name = false;
121 }
122 return ret;
123}
124
133time_t BESRequestHandler::get_lmt(const string &name){
134// 5/31/19 - SBL - Initial code
135// 6/03/19 - SBL - using BESUtil::pathConcat and throws BESNotFoundError
136 // Get the bes catalog root path from the conf info
137 //string root_dir = TheBESKeys::TheKeys()->read_string_key("BES.Catalog.catalog.RootDirectory", "");
138 // Get the name's LMT from the file system
139 //string filepath = BESUtil::pathConcat(root_dir, name, '/');
140 struct stat statbuf;
141 if (stat(name.c_str(), &statbuf) == -1){
142 //perror(filepath);
143 throw BESNotFoundError(strerror(errno), __FILE__, __LINE__);
144 }//end if
145
146 return statbuf.st_mtime;
147}//end get_lmt()
148
149//void BESRequestHandler::add_attributes(BESDataHandlerInterface &bdhi){
150void BESRequestHandler::add_attributes(BESDataHandlerInterface &){
151
152 // The current implementation ensures the execution of this function in the derived class.
153 // So will throw an error if code comes here. KY 10/30/19
154 throw BESNotFoundError("Cannot find the add_attributes() in the specific handler.", __FILE__, __LINE__);
155}
156
164void BESRequestHandler::dump(ostream &strm) const
165{
166 strm << BESIndent::LMarg << "BESRequestHandler::dump - (" << (void *) this << ")" << endl;
167 BESIndent::Indent();
168 strm << BESIndent::LMarg << "name: " << _name << endl;
169 if (_handler_list.size()) {
170 strm << BESIndent::LMarg << "registered handler functions:" << endl;
171 BESIndent::Indent();
172 BESRequestHandler::Handler_citer i = _handler_list.begin();
173 BESRequestHandler::Handler_citer ie = _handler_list.end();
174 for (; i != ie; i++) {
175 strm << BESIndent::LMarg << (*i).first << endl;
176 }
177 BESIndent::UnIndent();
178 }
179 else {
180 strm << BESIndent::LMarg << "registered handler functions: none" << endl;
181 }
182 BESIndent::UnIndent();
183}
184
Structure storing information used by the BES to handle the request.
error thrown if the resource requested cannot be found
virtual std::string get_method_names()
return a comma separated list of response object types handled by this request handler
virtual time_t get_lmt(const std::string &name)
Get the Last modified time for.
virtual p_request_handler_method find_method(const std::string &name)
find the method that can handle the specified response object type
virtual bool add_method(const std::string &name, p_request_handler_method method)
add a handler method to the request handler that knows how to fill in a specific response object
virtual bool remove_method(const std::string &name)
remove the specified handler method from this request handler
virtual void dump(std::ostream &strm) const
dumps information about this object