36#include <libdap/DMR.h>
37#include <libdap/mime_util.h>
38#include <libdap/D4BaseTypeFactory.h>
39#include <libdap/InternalErr.h>
40#include <libdap/Ancillary.h>
42#include <dispatch/BESResponseHandler.h>
43#include <dispatch/BESServiceRegistry.h>
44#include <dispatch/BESResponseNames.h>
45#include <dispatch/BESVersionInfo.h>
46#include <dispatch/BESUtil.h>
47#include <dispatch/TheBESKeys.h>
49#include <dap/BESDapNames.h>
51#include <dap/BESDASResponse.h>
52#include <dap/BESDDSResponse.h>
53#include <dap/BESDataDDSResponse.h>
54#include <dap/BESDMRResponse.h>
56#include <dap/BESDapError.h>
57#include <dispatch/BESInternalFatalError.h>
62#include "GDALRequestHandler.h"
63#include "reader/gdal_utils.h"
65#define GDAL_NAME "gdal"
69GDALRequestHandler::GDALRequestHandler(
const string &name) :
72 add_method(DAS_RESPONSE, GDALRequestHandler::gdal_build_das);
73 add_method(DDS_RESPONSE, GDALRequestHandler::gdal_build_dds);
74 add_method(DATA_RESPONSE, GDALRequestHandler::gdal_build_data);
76 add_method(DMR_RESPONSE, GDALRequestHandler::gdal_build_dmr);
77 add_method(DAP4DATA_RESPONSE, GDALRequestHandler::gdal_build_dmr);
79 add_method(HELP_RESPONSE, GDALRequestHandler::gdal_build_help);
80 add_method(VERS_RESPONSE, GDALRequestHandler::gdal_build_version);
83 CPLSetErrorHandler(CPLQuietErrorHandler);
86GDALRequestHandler::~GDALRequestHandler()
100 DAS *das = bdas->get_das();
103 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
106 throw Error(
string(CPLGetLastErrorMsg()));
108 gdal_read_dataset_attributes(*das, hDS);
113 Ancillary::read_ancillary_das(*das, filename);
118 if (hDS) GDALClose(hDS);
121 catch (InternalErr & e) {
122 if (hDS) GDALClose(hDS);
123 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
126 if (hDS) GDALClose(hDS);
127 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
130 if (hDS) GDALClose(hDS);
144 GDALDatasetH hDS = 0;
150 dds->filename(filename);
151 dds->set_dataset_name(name_path(filename));
153 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
156 throw Error(
string(CPLGetLastErrorMsg()));
158 gdal_read_dataset_variables(dds, hDS, filename,
true);
167 if (hDS) GDALClose(hDS);
170 catch (InternalErr & e) {
171 if (hDS) GDALClose(hDS);
172 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
175 if (hDS) GDALClose(hDS);
176 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
179 if (hDS) GDALClose(hDS);
195 GDALDatasetH hDS = 0;
198 DDS *dds = bdds->get_dds();
201 dds->filename(filename);
202 dds->set_dataset_name(name_path(filename));
204 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
207 throw Error(
string(CPLGetLastErrorMsg()));
210 gdal_read_dataset_variables(dds, hDS, filename,
false);
216 BESDEBUG(
"gdal",
"Data ACCESS build_data(): set the including attribute flag to false: "<<filename << endl);
217 bdds->set_ia_flag(
false);
221 if (hDS) GDALClose(hDS);
224 catch (InternalErr & e) {
225 if (hDS) GDALClose(hDS);
226 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
229 if (hDS) GDALClose(hDS);
230 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
233 if (hDS) GDALClose(hDS);
252 BaseTypeFactory factory;
253 DDS dds(&factory, name_path(filename),
"3.2");
254 dds.filename(filename);
256 GDALDatasetH hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
259 throw Error(
string(CPLGetLastErrorMsg()));
262 gdal_read_dataset_variables(&dds, hDS, filename,
true);
267 catch (InternalErr &e) {
268 if (hDS) GDALClose(hDS);
269 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
272 if (hDS) GDALClose(hDS);
273 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
276 if (hDS) GDALClose(hDS);
277 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
285 DMR *dmr = bes_dmr.get_dmr();
286 D4BaseTypeFactory d4_factory;
287 dmr->set_factory(&d4_factory);
288 dmr->build_using_dds(dds);
310 DMR *dmr = bes_dmr.get_dmr();
311 D4BaseTypeFactory d4_factory;
312 dmr->set_factory(&d4_factory);
313 dmr->set_filename(filename);
314 dmr->set_name(name_path(filename));
316 GDALDatasetH hDS = 0;
319 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
320 if (hDS == NULL)
throw Error(
string(CPLGetLastErrorMsg()));
322 gdal_read_dataset_variables(dmr, hDS, filename);
327 catch (InternalErr &e) {
328 if (hDS) GDALClose(hDS);
329 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
332 if (hDS) GDALClose(hDS);
333 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
336 if (hDS) GDALClose(hDS);
337 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
358 map < string, string > attrs;
359 attrs[
"name"] = MODULE_NAME ;
360 attrs[
"version"] = MODULE_VERSION ;
361 list < string > services;
363 if (services.size() > 0) {
365 attrs[
"handles"] = handles;
367 info->begin_tag(
"module", &attrs);
368 info->end_tag(
"module");
380 info->add_module(MODULE_NAME, MODULE_VERSION);
391 DDS *dds = bdds->get_dds();
396 GDALDatasetH hDS = 0;
403 if (!container_name.empty()) das->container_name(container_name);
405 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
407 throw Error(
string(CPLGetLastErrorMsg()));
409 gdal_read_dataset_attributes(*das,hDS);
410 Ancillary::read_ancillary_das(*das, filename);
412 dds->transfer_attributes(das);
417 BESDEBUG(
"gdal",
"Data ACCESS in add_attributes(): set the including attribute flag to true: "<<filename << endl);
418 bdds->set_ia_flag(
true);
423 if (hDS) GDALClose(hDS);
427 catch (InternalErr & e) {
428 if (hDS) GDALClose(hDS);
430 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
433 if (hDS) GDALClose(hDS);
435 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
438 if (hDS) GDALClose(hDS);
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
Represents an OPeNDAP DAS DAP2 data object within the BES.
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
Holds a DDS object within the BES.
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
bool get_explicit_containers() const
Should containers be explicitly represented in the DD* responses?
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
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
Base exception class for the BES with basic string message.
informational response object
exception thrown if internal error encountered
exception thrown if an internal error is found and is fatal to the BES
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.
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)
static bool gdal_build_dmr_using_dds(BESDataHandlerInterface &dhi)
Unused.