27#include <BESSyntaxUserError.h>
28#include <BESInternalError.h>
30#include <AllowedHosts.h>
31#include "RemoteResource.h"
33#include "HttpdCatalogContainer.h"
34#include "HttpdCatalog.h"
39#define prolog std::string("HttpdCatalogContainer::").append(__func__).append("() - ")
41namespace httpd_catalog {
53HttpdCatalogContainer::HttpdCatalogContainer(
const string &sym_name,
const string &real_name,
const string &type) :
54 BESContainer(sym_name, real_name, type), d_remoteResource(0)
57 BESDEBUG(MODULE, prolog <<
"BEGIN sym_name: " << sym_name <<
" real_name: " << real_name <<
" type: " << type << endl);
59 string path = real_name;
60 if (path.empty() || path[0] !=
'/') {
67 BESDEBUG(MODULE, prolog <<
"path: '" << path <<
"' path_elements.size(): " << path_elements.size() << endl);
80 BESDEBUG(MODULE, prolog <<
"END" << endl);
88 if (copy_from.d_remoteResource) {
89 throw BESInternalError(
"The Container has already been accessed, cannot create a copy of this container.", __FILE__, __LINE__);
93void HttpdCatalogContainer::_duplicate(HttpdCatalogContainer ©_to)
95 if (copy_to.d_remoteResource) {
96 throw BESInternalError(
"The Container has already been accessed, cannot duplicate this resource.", __FILE__, __LINE__);
98 copy_to.d_remoteResource = d_remoteResource;
106 _duplicate(*container);
110HttpdCatalogContainer::~HttpdCatalogContainer()
112 if (d_remoteResource) {
124 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
127 BESDEBUG(MODULE, prolog <<
"path: " << path << endl);
132 if (!d_remoteResource) {
133 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource." << endl);
134 std::shared_ptr<http::url> access_url_ptr(
new http::url(access_url));
139 BESDEBUG(MODULE, prolog <<
"Located remote resource." << endl);
142 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << cachedResource << endl);
144 string type = d_remoteResource->
getType();
147 BESDEBUG(MODULE, prolog <<
"Type: " << type << endl);
149 BESDEBUG(MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
150 BESDEBUG(MODULE, prolog <<
"Done accessing " << *
this << endl);
151 BESDEBUG(MODULE, prolog <<
"END" << endl);
153 return cachedResource;
164 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
165 if (d_remoteResource) {
166 BESDEBUG(MODULE, prolog <<
"Releasing RemoteResource" << endl);
167 delete d_remoteResource;
168 d_remoteResource = 0;
170 BESDEBUG(MODULE, prolog <<
"END" << endl);
183 strm << BESIndent::LMarg << prolog<<
"(" << (
void *)
this
187 if (d_remoteResource) {
188 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->
getCacheFileName()
190 strm << BESIndent::LMarg <<
"response headers: ";
196 vector<string>::const_iterator i = hdrs->begin();
197 vector<string>::const_iterator e = hdrs->end();
198 for (; i != e; i++) {
199 string hdr_line = (*i);
200 strm << BESIndent::LMarg << hdr_line << endl;
202 BESIndent::UnIndent();
205 strm <<
"none" << endl;
209 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
212 BESIndent::UnIndent();
A container is something that holds data. E.G., a netcdf file or a database entry.
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
virtual void dump(std::ostream &strm) const
dumps information about this object
void set_relative_name(const std::string &relative)
Set the relative name of the object in this container.
void _duplicate(BESContainer ©_to)
duplicate this instance into the passed container
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
exception thrown if internal error encountered
static std::vector< std::string > split(const std::string &s, char delim='/', bool skip_empty=true)
Splits the string s into the return vector of tokens using the delimiter delim and skipping empty val...
std::string getCacheFileName()
std::vector< std::string > * getResponseHeaders()
Container representing a remote request.
virtual bool release()
release the resources
virtual std::string access()
access the remote target response by making the remote request
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESContainer * ptr_duplicate()
pure abstract method to duplicate this instances of BESContainer
builds catalogs from a directory structure exposed by Apache httpd
virtual std::string path_to_access_url(const std::string &path) const
Takes a path which begins with the name of an HttpdCatalog collection and returns the associated acce...