35#include <libdap/DataDDS.h>
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>
69long 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)
89 BESDEBUG(
"ncml",
"DDSLoader::operator=: " << endl);
126 if (&_dhi != &rhs._dhi) _dhi.
make_copy(rhs._dhi);
138unique_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 ERROR_LOG(
"WARNING - " <<
string(__PRETTY_FUNCTION__) <<
": " << e.
get_file() <<
":" << e.
get_line() <<
": "
247 << e.
get_message() <<
" (the exception was re-thrown)."<< endl);
261bool is_url(
const 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 == tip;
271 tip = location.substr(0,https.size());
272 std::transform(tip.begin(), tip.end(), tip.begin(), ::tolower);
274 result = result ||
http == tip;
280DDSLoader::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__);
300 string newSymbol = getNextContainerName() +
"__" + _filename;
311 _containerSymbol = newSymbol;
316 throw BESInternalError(
"couldn't find the container we just added:" + newSymbol, __FILE__, __LINE__);
322void DDSLoader::removeContainerFromStorage()
333 ERROR_LOG(
"WARNING: tried to remove symbol " << _containerSymbol
334 <<
" from singleton but unexpectedly it was not there." << endl);
336 _containerSymbol =
"";
341void DDSLoader::snapshotDHI()
343 VALID_PTR(_dhi.response_handler);
345 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Taking snapshot of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
346 BESDEBUG(
"ncml_verbose",
"original dhi = " << _dhi << endl );
351 _origAction = _dhi.
action;
352 _origActionName = _dhi.action_name;
356 BESDEBUG(
"ncml",
"DDSLoader::snapshotDHI() - Replaced with DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
361void DDSLoader::restoreDHI()
363 VALID_PTR(_dhi.response_handler);
387 _dhi.
action = _origAction;
388 _dhi.action_name = _origActionName;
392 BESDEBUG(
"ncml",
"DDSLoader::restoreDHI() - Restored of DataHAndlerInterface for (action: " << _dhi.
action <<
" action_name: " << _dhi.action_name <<
")" << endl );
394 BESDEBUG(
"ncml_verbose",
"restored dhi = " << _dhi << endl );
398 _origActionName =
"";
409void DDSLoader::ensureClean()
418 removeContainerFromStorage();
422std::string DDSLoader::getNextContainerName()
424 static const string _sPrefix =
"__DDSLoader_Container_ID_";
426 std::ostringstream oss;
427 oss << _sPrefix << (_gensymID);
433 if (type == eRT_RequestDDX) {
435 return unique_ptr<BESDapResponse>(
new BESDDSResponse(
new DDS(
nullptr ,
"virtual")));
437 else if (type == eRT_RequestDataDDS) {
439 return unique_ptr<BESDapResponse>(
new BESDataDDSResponse(
new DDS(
nullptr ,
"virtual")));
442 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::makeResponseForType() got unknown type!");
448 if (type == eRT_RequestDDX) {
451 else if (type == eRT_RequestDataDDS) {
452 return DATA_RESPONSE;
455 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionForType(): unknown type!");
460 if (type == eRT_RequestDDX) {
461 return DDX_RESPONSE_STR;
463 else if (type == eRT_RequestDataDDS) {
464 return DATA_RESPONSE_STR;
467 THROW_NCML_INTERNAL_ERROR(
"DDSLoader::getActionNameForType(): unknown type!");
472 if (type == eRT_RequestDDX) {
475 else if (type == eRT_RequestDataDDS) {
Provides a mechanism for accessing container information from different container stores registered w...
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
provides persistent storage for data storage information represented by a container.
virtual bool del_container(const std::string &s_name)=0
removes a container with the given symbolic name
virtual void add_container(const std::string &sym_name, const std::string &real_name, const std::string &type)=0
adds a container with the provided information
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
A container is something that holds data. E.G., a netcdf file or a database entry.
std::string get_container_type() const
retrieve the type of data this container holds, such as cedar or netcdf.
Holds a DDS object within the BES.
Represents an OPeNDAP DAP response object within the BES.
std::string get_request_xml_base() const
Return the xml:base URL for this request.
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
void make_copy(const BESDataHandlerInterface ©_from)
deprecated
std::string action
the response object requested, e.g. das, dds
BESContainer * container
pointer to current container in this interface
Base exception class for the BES with basic string message.
unsigned int get_line() const
get the line number where the exception was thrown
std::string get_file() const
get the file name where the exception was thrown
std::string get_message() const
get the error message for this exception
exception thrown if internal error encountered
virtual void execute_current(BESDataHandlerInterface &dhi)
Execute a single method for the current container that will fill in the response object rather than i...
virtual BESRequestHandler * find_handler(const std::string &handler_name)
find and return the specified request handler
Represents a specific data type request handler.
virtual BESResponseObject * set_response_object(BESResponseObject *o)
replaces the current response object with the specified one, returning the current response object
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.
static std::unique_ptr< BESDapResponse > makeResponseForType(ResponseType type)
void loadInto(const std::string &location, ResponseType type, BESDapResponse *pResponse)
Load a DDX or DataDDS response into the given pResponse object, which must be non-null.
DDSLoader(BESDataHandlerInterface &dhi)
Create a loader that will hijack dhi on a load call, then restore it's state.
static bool checkResponseIsValidType(ResponseType type, BESDapResponse *pResponse)
void cleanup()
restore dhi to clean state
static std::string getActionForType(ResponseType type)
static std::string getActionNameForType(ResponseType type)
virtual ~DDSLoader()
Dtor restores the state of dhi Restores the state of the dhi to what it was when object if it is stil...
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
utility class for the HTTP catalog module