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);
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()));
206 gdal_read_dataset_variables(dds, hDS, filename);
215 if (hDS) GDALClose(hDS);
218 catch (InternalErr & e) {
219 if (hDS) GDALClose(hDS);
220 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
223 if (hDS) GDALClose(hDS);
224 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
227 if (hDS) GDALClose(hDS);
246 BaseTypeFactory factory;
247 DDS dds(&factory, name_path(filename),
"3.2");
248 dds.filename(filename);
250 GDALDatasetH hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
253 throw Error(
string(CPLGetLastErrorMsg()));
256 gdal_read_dataset_variables(&dds, hDS, filename);
261 catch (InternalErr &e) {
262 if (hDS) GDALClose(hDS);
263 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
266 if (hDS) GDALClose(hDS);
267 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
270 if (hDS) GDALClose(hDS);
271 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
277 BESDMRResponse &bes_dmr = dynamic_cast<BESDMRResponse &>(*response);
279 DMR *dmr = bes_dmr.get_dmr();
280 D4BaseTypeFactory d4_factory;
281 dmr->set_factory(&d4_factory);
282 dmr->build_using_dds(dds);
300 BESDMRResponse &bes_dmr = dynamic_cast<BESDMRResponse &>(*response);
304 DMR *dmr = bes_dmr.get_dmr();
305 D4BaseTypeFactory d4_factory;
306 dmr->set_factory(&d4_factory);
307 dmr->set_filename(filename);
308 dmr->set_name(name_path(filename));
310 GDALDatasetH hDS = 0;
313 hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
314 if (hDS == NULL)
throw Error(
string(CPLGetLastErrorMsg()));
316 gdal_read_dataset_variables(dmr, hDS, filename);
321 catch (InternalErr &e) {
322 if (hDS) GDALClose(hDS);
323 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
326 if (hDS) GDALClose(hDS);
327 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
330 if (hDS) GDALClose(hDS);
331 throw BESDapError(
"Caught unknown error building GDAL DMR response",
true, unknown_error, __FILE__, __LINE__);
348 BESInfo *info = dynamic_cast<BESInfo *> (response);
352 map < string, string > attrs;
353 attrs[
"name"] = MODULE_NAME ;
354 attrs[
"version"] = MODULE_VERSION ;
355 list < string > services;
357 if (services.size() > 0) {
359 attrs[
"handles"] = handles;
361 info->begin_tag(
"module", &attrs);
362 info->end_tag(
"module");
374 info->add_module(MODULE_NAME, MODULE_VERSION);