25 #include <BESSyntaxUserError.h>
26 #include <BESInternalError.h>
27 #include <BESNotFoundError.h>
30 #include <TheBESKeys.h>
31 #include <WhiteList.h>
33 #include "HttpdCatalogContainer.h"
34 #include "HttpdCatalogUtils.h"
35 #include "HttpdCatalogNames.h"
36 #include "HttpdCatalog.h"
37 #include "RemoteHttpResource.h"
42 #define prolog std::string("HttpdCatalogContainer::").append(__func__).append("() - ")
44 namespace httpd_catalog {
56 HttpdCatalogContainer::HttpdCatalogContainer(
const string &sym_name,
const string &real_name,
const string &type) :
57 BESContainer(sym_name, real_name, type), d_remoteResource(0)
60 BESDEBUG(MODULE, prolog <<
"BEGIN sym_name: " << sym_name <<
" real_name: " << real_name <<
" type: " << type << endl);
62 string path = real_name;
63 if (path.empty() || path[0] !=
'/') {
70 BESDEBUG(MODULE, prolog <<
"path: '" << path <<
"' path_elements.size(): " << path_elements.size() << endl);
83 BESDEBUG(MODULE, prolog <<
"END" << endl);
91 if (copy_from.d_remoteResource) {
92 throw BESInternalError(
"The Container has already been accessed, cannot create a copy of this container.", __FILE__, __LINE__);
96 void HttpdCatalogContainer::_duplicate(HttpdCatalogContainer ©_to)
98 if (copy_to.d_remoteResource) {
99 throw BESInternalError(
"The Container has already been accessed, cannot duplicate this resource.", __FILE__, __LINE__);
101 copy_to.d_remoteResource = d_remoteResource;
109 _duplicate(*container);
113 HttpdCatalogContainer::~HttpdCatalogContainer()
115 if (d_remoteResource) {
127 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
130 BESDEBUG(MODULE, prolog <<
"path: " << path << endl);
135 if (!d_remoteResource) {
136 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource." << endl);
141 BESDEBUG(MODULE, prolog <<
"Located remote resource." << endl);
144 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << cachedResource << endl);
146 string type = d_remoteResource->
getType();
149 BESDEBUG(MODULE, prolog <<
"Type: " << type << endl);
151 BESDEBUG(MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
152 BESDEBUG(MODULE, prolog <<
"Done accessing " << *
this << endl);
153 BESDEBUG(MODULE, prolog <<
"END" << endl);
155 return cachedResource;
166 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
167 if (d_remoteResource) {
168 BESDEBUG(MODULE, prolog <<
"Releasing RemoteResource" << endl);
169 delete d_remoteResource;
170 d_remoteResource = 0;
172 BESDEBUG(MODULE, prolog <<
"END" << endl);
185 strm << BESIndent::LMarg << prolog<<
"(" << (
void *)
this
189 if (d_remoteResource) {
190 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " <<d_remoteResource->
getCacheFileName()
192 strm << BESIndent::LMarg <<
"response headers: ";
199 vector<string>::const_iterator i = hdrs.begin();
200 vector<string>::const_iterator e = hdrs.end();
201 for (; i != e; i++) {
202 string hdr_line = (*i);
203 strm << BESIndent::LMarg << hdr_line << endl;
205 BESIndent::UnIndent();
208 strm <<
"none" << endl;
212 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
215 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...
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...
void getResponseHeaders(std::vector< std::string > &hdrs)
std::string getCacheFileName()