37 #include <BESConstraintFuncs.h>
38 #include <BESContainerStorage.h>
39 #include <BESContainerStorageList.h>
40 #include <BESDapNames.h>
41 #include <BESDapResponse.h>
42 #include <BESDataDDSResponse.h>
43 #include <BESDataHandlerInterface.h>
44 #include <BESDDSResponse.h>
45 #include <BESStopWatch.h>
46 #include <BESInternalError.h>
47 #include <BESResponseHandler.h>
48 #include <BESResponseNames.h>
49 #include <BESRequestHandlerList.h>
50 #include <BESServiceRegistry.h>
51 #include <BESTextInfo.h>
53 #include <BESVersionInfo.h>
58 #include "DDSLoader.h"
59 #include "NCMLDebug.h"
69 long DDSLoader::_gensymID = 0L;
74 _dhi(dhi), _hijacked(false), _filename(
""), _store(0), _containerSymbol(
""), _origAction(
""), _origActionName(
75 ""), _origContainer(0), _origResponse(0)
81 _dhi(proto._dhi), _hijacked(false), _filename(
""), _store(0), _containerSymbol(
""), _origAction(
82 ""), _origActionName(
""), _origContainer(0), _origResponse(0)
87 DDSLoader::operator=(
const DDSLoader& rhs)
89 BESDEBUG(
"ncml",
"DDSLoader::operator=: " << endl);
126 if (&_dhi != &rhs._dhi) _dhi.
make_copy(rhs._dhi);
138 auto_ptr<BESDapResponse> DDSLoader::load(
const string& location, ResponseType type)
143 loadInto(location, type, response.get());
150 VALID_PTR(pResponse);
151 VALID_PTR(_dhi.response_handler);
157 _filename = location;
173 container = addNewContainerToStorage();
176 *(BESLog::TheLog()) <<
"WARNING - " <<
string(__PRETTY_FUNCTION__) <<
": " << e.
get_file() <<
":" << e.
get_line() <<
": "
177 << e.
get_message() <<
" (the exception was re-thrown)."<< endl;
180 removeContainerFromStorage();
211 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::load expected BESDDSResponse or BESDataDDSResponse but got neither!");
217 BESDEBUG(
"ncml",
"Before BESRequestHandlerList::TheList()->execute_current" << endl);
218 BESDEBUG(
"ncml",
"Handler name: " << BESRequestHandlerList::TheList()->get_handler_names() << endl);
225 if(type == eRT_RequestDataDDS) {
232 if(bdds->get_ia_flag() ==
false) {
235 besRH->add_attributes(_dhi);
239 BESDEBUG(
"ncml",
"After BESRequestHandlerList::TheList()->execute_current" << endl);
246 *(BESLog::TheLog()) <<
"WARNING - " <<
string(__PRETTY_FUNCTION__) <<
": " << e.
get_file() <<
":" << e.
get_line() <<
": "
247 << e.
get_message() <<
" (the exception was re-thrown)."<< endl;
261 bool is_url(std::string location){
262 std::string http(
"http://");
263 std::string https(
"https://");
266 std::string tip = location.substr(0,http.size());
267 std::transform(tip.begin(), tip.end(), tip.begin(), ::tolower);
268 bool result = http.compare(tip)==0;
271 tip = location.substr(0,https.size());
272 std::transform(tip.begin(), tip.end(), tip.begin(), ::tolower);
274 result = result || http.compare(tip)==0;
280 DDSLoader::addNewContainerToStorage()
284 VALID_PTR(store_list);
288 if(is_url(_filename)){
289 BESDEBUG(
"ncml", __func__ <<
"() - GATEWAY CONTAINER!" << endl);
296 throw BESInternalError(
"couldn't find the catalog storage", __FILE__, __LINE__);
302 string newSymbol = getNextContainerName() +
"__" + _filename;
313 _containerSymbol = newSymbol;
318 throw BESInternalError(
"couldn't find the container we just added:" + newSymbol, __FILE__, __LINE__);
324 void DDSLoader::removeContainerFromStorage()
335 *(BESLog::TheLog()) <<
"WARNING: tried to remove symbol " << _containerSymbol
336 <<
" from singleton but unexpectedly it was not there." << endl;
338 _containerSymbol =
"";
343 void DDSLoader::snapshotDHI()
345 VALID_PTR(_dhi.response_handler);
347 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Taking snapshot of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
348 BESDEBUG(
"ncml_verbose",
"original dhi = " << _dhi << endl );
353 _origAction = _dhi.
action;
354 _origActionName = _dhi.action_name;
358 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Replaced with DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
363 void DDSLoader::restoreDHI()
365 VALID_PTR(_dhi.response_handler);
389 _dhi.
action = _origAction;
390 _dhi.action_name = _origActionName;
394 BESDEBUG(
"ncml",
"DDSLoader::restoreDHI() - Restored of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
396 BESDEBUG(
"ncml_verbose",
"restored dhi = " << _dhi << endl );
400 _origActionName =
"";
411 void DDSLoader::ensureClean()
420 removeContainerFromStorage();
424 std::string DDSLoader::getNextContainerName()
426 static const string _sPrefix =
"__DDSLoader_Container_ID_";
428 std::ostringstream oss;
429 oss << _sPrefix << (_gensymID);
435 if (type == eRT_RequestDDX) {
437 return auto_ptr<BESDapResponse>(
new BESDDSResponse(
new DDS(0 ,
"virtual")));
439 else if (type == eRT_RequestDataDDS) {
444 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::makeResponseForType() got unknown type!");
450 if (type == eRT_RequestDDX) {
453 else if (type == eRT_RequestDataDDS) {
454 return DATA_RESPONSE;
457 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionForType(): unknown type!");
462 if (type == eRT_RequestDDX) {
463 return DDX_RESPONSE_STR;
465 else if (type == eRT_RequestDataDDS) {
466 return DATA_RESPONSE_STR;
469 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionNameForType(): unknown type!");
474 if (type == eRT_RequestDDX) {
477 else if (type == eRT_RequestDataDDS) {