37 #include <mime_util.h>
38 #include <D4BaseTypeFactory.h>
39 #include <InternalErr.h>
40 #include <Ancillary.h>
42 #include <BESResponseHandler.h>
43 #include <BESServiceRegistry.h>
45 #include <BESResponseNames.h>
46 #include <BESDapNames.h>
48 #include <BESDASResponse.h>
49 #include <BESDDSResponse.h>
50 #include <BESDataDDSResponse.h>
51 #include <BESDMRResponse.h>
52 #include <BESVersionInfo.h>
54 #include <BESDapError.h>
55 #include <BESInternalFatalError.h>
60 #include "GDALRequestHandler.h"
61 #include "gdal_utils.h"
63 #define GDAL_NAME "gdal"
67 GDALRequestHandler::GDALRequestHandler(
const string &name) :
70 add_method(DAS_RESPONSE, GDALRequestHandler::gdal_build_das);
71 add_method(DDS_RESPONSE, GDALRequestHandler::gdal_build_dds);
72 add_method(DATA_RESPONSE, GDALRequestHandler::gdal_build_data);
74 add_method(DMR_RESPONSE, GDALRequestHandler::gdal_build_dmr);
75 add_method(DAP4DATA_RESPONSE, GDALRequestHandler::gdal_build_dmr);
77 add_method(HELP_RESPONSE, GDALRequestHandler::gdal_build_help);
78 add_method(VERS_RESPONSE, GDALRequestHandler::gdal_build_version);
83 GDALRequestHandler::~GDALRequestHandler()
97 DAS *das = bdas->get_das();
100 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
103 throw Error(
string(CPLGetLastErrorMsg()));
105 gdal_read_dataset_attributes(*das, hDS);
110 Ancillary::read_ancillary_das(*das, filename);
115 if (hDS) GDALClose(hDS);
118 catch (InternalErr & e) {
119 if (hDS) GDALClose(hDS);
120 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
123 if (hDS) GDALClose(hDS);
124 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
127 if (hDS) GDALClose(hDS);
141 GDALDatasetH hDS = 0;
147 dds->filename(filename);
148 dds->set_dataset_name(name_path(filename));
150 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
153 throw Error(
string(CPLGetLastErrorMsg()));
155 gdal_read_dataset_variables(dds, hDS, filename,
true);
164 if (hDS) GDALClose(hDS);
167 catch (InternalErr & e) {
168 if (hDS) GDALClose(hDS);
169 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
172 if (hDS) GDALClose(hDS);
173 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
176 if (hDS) GDALClose(hDS);
192 GDALDatasetH hDS = 0;
195 DDS *dds = bdds->get_dds();
198 dds->filename(filename);
199 dds->set_dataset_name(name_path(filename));
201 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
204 throw Error(
string(CPLGetLastErrorMsg()));
207 gdal_read_dataset_variables(dds, hDS, filename,
false);
213 BESDEBUG(
"gdal",
"Data ACCESS build_data(): set the including attribute flag to false: "<<filename << endl);
214 bdds->set_ia_flag(
false);
218 if (hDS) GDALClose(hDS);
221 catch (InternalErr & e) {
222 if (hDS) GDALClose(hDS);
223 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
226 if (hDS) GDALClose(hDS);
227 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
230 if (hDS) GDALClose(hDS);
249 BaseTypeFactory factory;
250 DDS dds(&factory, name_path(filename),
"3.2");
251 dds.filename(filename);
253 GDALDatasetH hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
256 throw Error(
string(CPLGetLastErrorMsg()));
259 gdal_read_dataset_variables(&dds, hDS, filename,
true);
264 catch (InternalErr &e) {
265 if (hDS) GDALClose(hDS);
266 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
269 if (hDS) GDALClose(hDS);
270 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
273 if (hDS) GDALClose(hDS);
274 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
282 DMR *dmr = bes_dmr.get_dmr();
283 D4BaseTypeFactory d4_factory;
284 dmr->set_factory(&d4_factory);
285 dmr->build_using_dds(dds);
307 DMR *dmr = bes_dmr.get_dmr();
308 D4BaseTypeFactory d4_factory;
309 dmr->set_factory(&d4_factory);
310 dmr->set_filename(filename);
311 dmr->set_name(name_path(filename));
313 GDALDatasetH hDS = 0;
316 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
317 if (hDS == NULL)
throw Error(
string(CPLGetLastErrorMsg()));
319 gdal_read_dataset_variables(dmr, hDS, filename);
324 catch (InternalErr &e) {
325 if (hDS) GDALClose(hDS);
326 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
329 if (hDS) GDALClose(hDS);
330 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
333 if (hDS) GDALClose(hDS);
334 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
355 map < string, string > attrs;
356 attrs[
"name"] = MODULE_NAME ;
357 attrs[
"version"] = MODULE_VERSION ;
358 list < string > services;
360 if (services.size() > 0) {
362 attrs[
"handles"] = handles;
364 info->begin_tag(
"module", &attrs);
365 info->end_tag(
"module");
377 info->add_module(MODULE_NAME, MODULE_VERSION);
388 DDS *dds = bdds->get_dds();
393 GDALDatasetH hDS = 0;
400 if (!container_name.empty()) das->container_name(container_name);
402 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
404 throw Error(
string(CPLGetLastErrorMsg()));
406 gdal_read_dataset_attributes(*das,hDS);
407 Ancillary::read_ancillary_das(*das, filename);
409 dds->transfer_attributes(das);
414 BESDEBUG(
"gdal",
"Data ACCESS in add_attributes(): set the including attribute flag to true: "<<filename << endl);
415 bdds->set_ia_flag(
true);
420 if (hDS) GDALClose(hDS);
424 catch (InternalErr & e) {
425 if (hDS) GDALClose(hDS);
427 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
430 if (hDS) GDALClose(hDS);
432 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
435 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
Abstract 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.