36 #include <mime_util.h>
37 #include <D4BaseTypeFactory.h>
39 #include "NCMLRequestHandler.h"
41 #include <BESConstraintFuncs.h>
42 #include <BESContainerStorage.h>
43 #include <BESContainerStorageList.h>
44 #include <BESDapNames.h>
45 #include "BESDataDDSResponse.h"
46 #include <BESDataNames.h>
47 #include <BESDASResponse.h>
48 #include <BESDDSResponse.h>
49 #include <BESDMRResponse.h>
52 #include "BESStopWatch.h"
53 #include <BESInternalError.h>
54 #include <BESDapError.h>
56 #include <BESRequestHandlerList.h>
57 #include <BESResponseHandler.h>
58 #include <BESResponseNames.h>
59 #include <BESServiceRegistry.h>
60 #include <BESTextInfo.h>
62 #include <BESVersionInfo.h>
63 #include <TheBESKeys.h>
65 #include "DDSLoader.h"
67 #include "NCMLDebug.h"
69 #include "NCMLParser.h"
70 #include "NCMLResponseNames.h"
71 #include "SimpleLocationParser.h"
77 bool NCMLRequestHandler::_global_attributes_container_name_set =
false;
78 string NCMLRequestHandler::_global_attributes_container_name =
"";
80 NCMLRequestHandler::NCMLRequestHandler(
const string &name) :
83 add_method(DAS_RESPONSE, NCMLRequestHandler::ncml_build_das);
84 add_method(DDS_RESPONSE, NCMLRequestHandler::ncml_build_dds);
85 add_method(DATA_RESPONSE, NCMLRequestHandler::ncml_build_data);
87 add_method(DMR_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
88 add_method(DAP4DATA_RESPONSE, NCMLRequestHandler::ncml_build_dmr);
90 add_method(VERS_RESPONSE, NCMLRequestHandler::ncml_build_vers);
91 add_method(HELP_RESPONSE, NCMLRequestHandler::ncml_build_help);
93 if (NCMLRequestHandler::_global_attributes_container_name_set ==
false) {
94 bool key_found =
false;
99 NCMLRequestHandler::_global_attributes_container_name_set =
true;
101 NCMLRequestHandler::_global_attributes_container_name = value;
106 NCMLRequestHandler::~NCMLRequestHandler()
131 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
136 string new_sym = sym_name +
"_location1";
141 throw BESInternalError(
"couldn't find the container" + sym_name, __FILE__, __LINE__);
164 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_das", dhi.
data[REQUEST_ID]);
172 auto_ptr<BESDapResponse> loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
182 DAS *das = bdas->get_das();
184 if (dds->get_dap_major() < 4)
185 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
186 NCMLRequestHandler::get_global_attributes_container_name());
199 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dds", dhi.
data[REQUEST_ID]);
205 auto_ptr<BESDapResponse> loaded_bdds(0);
209 loaded_bdds = parser.parse(filename, DDSLoader::eRT_RequestDDX);
211 if (!loaded_bdds.get()) {
212 throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
221 DDS *dds = bdds_out->
get_dds();
224 if (dds->get_dap_major() < 4)
225 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
226 NCMLRequestHandler::get_global_attributes_container_name());
240 dds->filename(name_path(filename));
241 dds->set_dataset_name(name_path(filename));
247 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dds", dhi.
data[REQUEST_ID]);
253 NCML_ASSERT_MSG(ddsResponse,
254 "NCMLRequestHandler::ncml_build_data(): expected BESDDSResponse* but didn't get it!!");
260 parser.parseInto(filename, DDSLoader::eRT_RequestDDX, ddsResponse);
263 DDS *dds = ddsResponse->
get_dds();
266 if (dds->get_dap_major() < 4)
267 NCMLUtil::hackGlobalAttributesForDAP2(dds->get_attr_table(),
268 NCMLRequestHandler::get_global_attributes_container_name());
275 dds->filename(name_path(filename));
276 dds->set_dataset_name(name_path(filename));
284 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_data", dhi.
data[REQUEST_ID]);
290 NCML_ASSERT_MSG(dataResponse,
291 "NCMLRequestHandler::ncml_build_data(): expected BESDataDDSResponse* but didn't get it!!");
297 parser.parseInto(filename, DDSLoader::eRT_RequestDataDDS, dataResponse);
312 dds->filename(name_path(filename));
313 dds->set_dataset_name(name_path(filename));
321 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"NCMLRequestHandler::ncml_build_dmr", dhi.
data[REQUEST_ID]);
329 auto_ptr<BESDapResponse> loaded_bdds(0);
333 loaded_bdds = parser.parse(data_path, DDSLoader::eRT_RequestDDX);
334 if (!loaded_bdds.get())
throw BESInternalError(
"Null BESDDSResonse in ncml DDS handler.", __FILE__, __LINE__);
337 dds->filename(data_path);
338 dds->set_dataset_name(data_path);
340 catch (InternalErr &e) {
341 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
344 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
350 throw BESDapError(
"Caught unknown error build ** DMR response",
true, unknown_error, __FILE__, __LINE__);
361 DMR *dmr = bdmr.get_dmr();
362 dmr->set_factory(
new D4BaseTypeFactory);
363 dmr->build_using_dds(*dds);
379 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
381 info->add_module(MODULE_NAME, MODULE_VERSION);
388 if (!info)
throw InternalErr(__FILE__, __LINE__,
"Expected a BESVersionInfo instance");
392 map<string, string> attrs;
393 attrs[
"name"] = MODULE_NAME;
394 attrs[
"version"] = MODULE_VERSION;
396 list<string> services;
398 if (services.size() > 0) {
400 attrs[
"handles"] = handles;
402 info->begin_tag(
"module", &attrs);
405 info->end_tag(
"module");
412 strm << BESIndent::LMarg <<
"NCMLRequestHandler::dump - (" << (
void *)
this <<
")" << endl;
415 BESIndent::UnIndent();