25 #include <BESSyntaxUserError.h>
26 #include <BESInternalError.h>
28 #include <AllowedHosts.h>
29 #include "RemoteResource.h"
31 #include "HttpdCatalogContainer.h"
32 #include "HttpdCatalog.h"
37 #define prolog std::string("HttpdCatalogContainer::").append(__func__).append("() - ")
39 namespace httpd_catalog {
51 HttpdCatalogContainer::HttpdCatalogContainer(
const string &sym_name,
const string &real_name,
const string &type) :
52 BESContainer(sym_name, real_name, type), d_remoteResource(0)
55 BESDEBUG(MODULE, prolog <<
"BEGIN sym_name: " << sym_name <<
" real_name: " << real_name <<
" type: " << type << endl);
57 string path = real_name;
58 if (path.empty() || path[0] !=
'/') {
65 BESDEBUG(MODULE, prolog <<
"path: '" << path <<
"' path_elements.size(): " << path_elements.size() << endl);
78 BESDEBUG(MODULE, prolog <<
"END" << endl);
86 if (copy_from.d_remoteResource) {
87 throw BESInternalError(
"The Container has already been accessed, cannot create a copy of this container.", __FILE__, __LINE__);
91 void HttpdCatalogContainer::_duplicate(HttpdCatalogContainer ©_to)
93 if (copy_to.d_remoteResource) {
94 throw BESInternalError(
"The Container has already been accessed, cannot duplicate this resource.", __FILE__, __LINE__);
96 copy_to.d_remoteResource = d_remoteResource;
104 _duplicate(*container);
108 HttpdCatalogContainer::~HttpdCatalogContainer()
110 if (d_remoteResource) {
122 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
125 BESDEBUG(MODULE, prolog <<
"path: " << path << endl);
130 if (!d_remoteResource) {
131 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource." << endl);
136 BESDEBUG(MODULE, prolog <<
"Located remote resource." << endl);
139 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << cachedResource << endl);
141 string type = d_remoteResource->
getType();
144 BESDEBUG(MODULE, prolog <<
"Type: " << type << endl);
146 BESDEBUG(MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
147 BESDEBUG(MODULE, prolog <<
"Done accessing " << *
this << endl);
148 BESDEBUG(MODULE, prolog <<
"END" << endl);
150 return cachedResource;
161 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
162 if (d_remoteResource) {
163 BESDEBUG(MODULE, prolog <<
"Releasing RemoteResource" << endl);
164 delete d_remoteResource;
165 d_remoteResource = 0;
167 BESDEBUG(MODULE, prolog <<
"END" << endl);
180 strm << BESIndent::LMarg << prolog<<
"(" << (
void *)
this
184 if (d_remoteResource) {
185 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->
getCacheFileName()
187 strm << BESIndent::LMarg <<
"response headers: ";
193 vector<string>::const_iterator i = hdrs->begin();
194 vector<string>::const_iterator e = hdrs->end();
195 for (; i != e; i++) {
196 string hdr_line = (*i);
197 strm << BESIndent::LMarg << hdr_line << endl;
199 BESIndent::UnIndent();
202 strm <<
"none" << endl;
206 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
209 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...