bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
S3RequestHandler.cc
1// S3Container.cc
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of S3_module, A C++ module that can be loaded in to
6// the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
7
8// Copyright (c) 2020 OPeNDAP, Inc.
9// Author: Nathan Potter <ndp@opendap.org>
10//
11// This library is free software; you can redistribute it and/or
12// modify it under the terms of the GNU Lesser General Public
13// License as published by the Free Software Foundation; either
14// version 2.1 of the License, or (at your option) any later version.
15//
16// This library is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19// Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License along with this library; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26// Authors:
27// ndp Nathan Potter <ndp@opendap.org>
28
29#include "config.h"
30
31#include <libdap/InternalErr.h>
32
33#include <BESResponseHandler.h>
34#include <BESResponseNames.h>
35#include <BESVersionInfo.h>
36
37#include <BESServiceRegistry.h>
38#include <TheBESKeys.h>
39#include <BESUtil.h>
40
41#include "S3RequestHandler.h"
42#include "S3Names.h"
43
44using namespace std;
45using namespace libdap;
46using namespace s3;
47using namespace http;
48
49bool S3RequestHandler::d_inject_data_url;
50
51S3RequestHandler::S3RequestHandler(const string &name) : BESRequestHandler(name)
52{
53 add_method(VERS_RESPONSE, S3RequestHandler::S3_build_vers);
54 add_method(HELP_RESPONSE, S3RequestHandler::S3_build_help);
55
56 d_inject_data_url = TheBESKeys::TheKeys()->read_bool_key(S3_INJECT_DATA_URL_KEY, false);
57}
58
59bool S3RequestHandler::S3_build_vers(BESDataHandlerInterface &dhi)
60{
61 auto info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
62 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
63
64 info->add_module(MODULE_NAME, MODULE_VERSION);
65 return true;
66}
67
68bool S3RequestHandler::S3_build_help(BESDataHandlerInterface &dhi)
69{
70 auto info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
71 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
72
73 // This is an example. If you had a help file you could load it like
74 // this and if your handler handled the following responses.
75 map<string, string, std::less<>> attrs;
76 attrs["name"] = MODULE_NAME;
77 attrs["version"] = MODULE_VERSION;
78
79 list<string> services;
80 BESServiceRegistry::TheRegistry()->services_handled(S3_NAME, services);
81 if (!services.empty()) {
82 string handles = BESUtil::implode(services, ',');
83 attrs["handles"] = handles;
84 }
85 info->begin_tag("module", &attrs);
86
87 info->end_tag("module");
88
89 return true;
90}
91
92void S3RequestHandler::dump(ostream &strm) const
93{
94 strm << BESIndent::LMarg << "S3RequestHandler::dump - (" << (void *) this << ")" << endl;
95 BESIndent::Indent();
97 BESIndent::UnIndent();
98}
Structure storing information used by the BES to handle the request.
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
static std::string implode(const std::list< std::string > &values, char delim)
Definition BESUtil.cc:620
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
static bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
void dump(std::ostream &strm) const override
dumps information about this object
utility class for the HTTP catalog module
Definition TheBESKeys.h:51