34#include <libdap/DDS.h>
35#include <libdap/DataDDS.h>
36#include <libdap/DMR.h>
37#include <libdap/D4BaseTypeFactory.h>
38#include <libdap/Ancillary.h>
39#include <libdap/Error.h>
40#include <libdap/InternalErr.h>
41#include <libdap/mime_util.h>
42#include <libdap/escaping.h>
44#include <BESResponseHandler.h>
45#include <BESResponseNames.h>
46#include <BESDapNames.h>
47#include <BESDASResponse.h>
48#include <BESDDSResponse.h>
49#include <BESDataDDSResponse.h>
50#include <BESDMRResponse.h>
51#include <BESVersionInfo.h>
53#include <BESDapError.h>
54#include <BESInternalFatalError.h>
55#include <BESDataNames.h>
56#include <TheBESKeys.h>
57#include <BESServiceRegistry.h>
60#include <BESContextManager.h>
62#include "FFRequestHandler.h"
64#include "ff_ce_functions.h"
76extern void ff_read_descriptors(DDS & dds,
const string & filename);
77extern void ff_get_attributes(DAS & das,
string filename);
79bool FFRequestHandler::d_RSS_format_support =
false;
80string FFRequestHandler::d_RSS_format_files =
"";
82bool FFRequestHandler::d_Regex_format_support =
false;
83std::map<string,string> FFRequestHandler::d_fmt_regex_map;
85FFRequestHandler::FFRequestHandler(
const string &name) :
88 add_method(DAS_RESPONSE, FFRequestHandler::ff_build_das);
89 add_method(DDS_RESPONSE, FFRequestHandler::ff_build_dds);
90 add_method(DATA_RESPONSE, FFRequestHandler::ff_build_data);
95 add_method(HELP_RESPONSE, FFRequestHandler::ff_build_help);
96 add_method(VERS_RESPONSE, FFRequestHandler::ff_build_version);
98 ff_register_functions();
100 bool key_found =
false;
105 if (doset ==
"true" || doset ==
"yes")
106 FFRequestHandler::d_RSS_format_support =
true;
108 FFRequestHandler::d_RSS_format_support =
false;
111 FFRequestHandler::d_RSS_format_support =
false;
117 FFRequestHandler::d_RSS_format_files = path;
119 FFRequestHandler::d_RSS_format_files =
"";
121 BESDEBUG(
"ff",
"d_RSS_format_support: " << d_RSS_format_support << endl);
122 BESDEBUG(
"ff",
"d_RSS_format_files: " << d_RSS_format_files << endl);
130 if (regex_doset ==
"true" || regex_doset ==
"yes")
131 FFRequestHandler::d_Regex_format_support =
true;
133 FFRequestHandler::d_Regex_format_support =
false;
136 FFRequestHandler::d_Regex_format_support =
false;
137 BESDEBUG(
"ff",
"d_Regex_format_support: " << d_Regex_format_support << endl);
141 vector<string> regex_fmt_files;
144 for (it = regex_fmt_files.begin(); it != regex_fmt_files.end(); it++) {
145 string fmt_entry = *it;
146 int index = fmt_entry.find(
":");
148 string regex = fmt_entry.substr(0, index);
149 string file = fmt_entry.substr(index + 1);
150 BESDEBUG(
"ff",
"regex: '" << regex <<
"' file: " << file << endl);
151 d_fmt_regex_map.insert(pair<string, string>(regex, file));
154 string(
"The configuration entry for the ")
156 +
" was incorrectly formatted. entry: "
157 + fmt_entry, __FILE__, __LINE__);
162FFRequestHandler::~FFRequestHandler()
169 BESDASResponse *bdas =
dynamic_cast<BESDASResponse *
>(response);
171 throw BESInternalError(
"cast error", __FILE__, __LINE__);
175 DAS *das = bdas->get_das();
178 ff_get_attributes(*das, accessed);
181 if (FFRequestHandler::get_RSS_format_support()) {
182 name = find_ancillary_rss_das(accessed);
189 if (!name.empty() && (stat(name.c_str(), &st) == 0)) {
194 }
catch (InternalErr & e) {
195 BESDapError ex(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
197 }
catch (Error & e) {
198 BESDapError ex(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
201 BESInternalFatalError ex(
"unknown exception caught building Freeform DAS", __FILE__, __LINE__);
211 BESDDSResponse *bdds =
dynamic_cast<BESDDSResponse *
>(response);
213 throw BESInternalError(
"cast error", __FILE__, __LINE__);
219 dds->filename(accessed);
221 BESDEBUG(
"ff",
"FFRequestHandler::ff_build_dds, accessed: " << accessed << endl);
223 ff_read_descriptors(*dds, accessed);
225 BESDEBUG(
"ff",
"FFRequestHandler::ff_build_dds, reading attributes" << endl);
228 BESDASResponse bdas(das);
230 ff_get_attributes(*das, accessed);
233 BESDEBUG(
"ff",
"FFRequestHandler::ff_build_dds, transferring attributes" << endl);
235 dds->transfer_attributes(das);
241 }
catch (InternalErr & e) {
242 BESDapError ex(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
244 }
catch (Error & e) {
245 BESDapError ex(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
248 BESInternalFatalError ex(
"unknown exception caught building Freeform DDS", __FILE__, __LINE__);
262 BESDataDDSResponse *bdds =
dynamic_cast<BESDataDDSResponse *
>(response);
264 throw BESInternalError(
"cast error", __FILE__, __LINE__);
267 DDS *dds = bdds->get_dds();
269 dds->filename(accessed);
270 ff_read_descriptors(*dds, accessed);
271 Ancillary::read_ancillary_dds(*dds, accessed);
274 BESDASResponse bdas(das);
276 ff_get_attributes(*das, accessed);
279 dds->transfer_attributes(das);
284 }
catch (InternalErr & e) {
285 BESDapError ex(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
287 }
catch (Error & e) {
288 BESDapError ex(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
291 BESInternalFatalError ex(
"unknown exception caught building Freeform DataDDS", __FILE__, __LINE__);
318 BaseTypeFactory factory;
319 DDS dds(&factory, name_path(data_path),
"3.2");
320 dds.filename(data_path);
323 ff_read_descriptors(dds, data_path);
328 ff_get_attributes(das, data_path);
330 dds.transfer_attributes(&das);
332 catch (InternalErr &e) {
333 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
336 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
339 throw BESDapError(
"Caught unknown error build FF DMR response",
true, unknown_error, __FILE__, __LINE__);
349 DMR *dmr = bdmr.get_dmr();
350 dmr->set_factory(
new D4BaseTypeFactory);
351 dmr->build_using_dds(dds);
372 map < string, string, std::less<>> attrs;
373 attrs[
"name"] = MODULE_NAME ;
374 attrs[
"version"] = MODULE_VERSION ;
376 attrs[
"name"] = PACKAGE_NAME;
377 attrs[
"version"] = PACKAGE_VERSION;
379 list < string > services;
380 BESServiceRegistry::TheRegistry()->services_handled(FF_NAME, services);
381 if (services.size() > 0) {
383 attrs[
"handles"] = handles;
385 info->begin_tag(
"module", &attrs);
386 info->end_tag(
"module");
394 BESVersionInfo *info =
dynamic_cast<BESVersionInfo *
>(response);
396 throw BESInternalError(
"cast error", __FILE__, __LINE__);
399 info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
401 info->add_module(MODULE_NAME, MODULE_VERSION);
std::string get_symbolic_name() const
retrieve the symbolic name for this container
virtual std::string access()=0
returns the true name of this container
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
virtual void clear_container()
clear the container in the DAP response object
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void clear_container()
clear the container in the DAP response object
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void clear_container()
clear the container in the DAP response object
Structure storing information used by the BES to handle the request.
BESContainer * container
pointer to current container in this interface
informational response object
exception thrown if internal error encountered
Represents a specific data type request handler.
virtual BESResponseObject * get_response_object()
return the current response object
Abstract base class representing a specific set of information in response to a request to the BES.
static std::string lowercase(const std::string &s)
static std::string implode(const std::list< std::string > &values, char delim)
static bool ff_build_dmr(BESDataHandlerInterface &dhi)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.