30 #include <BESSyntaxUserError.h>
31 #include <BESInternalError.h>
34 #include <AllowedHosts.h>
36 #include "GatewayContainer.h"
37 #include "GatewayNames.h"
38 #include "RemoteResource.h"
41 using namespace gateway;
45 #define prolog std::string("GatewayContainer::").append(__func__).append("() - ")
57 GatewayContainer::GatewayContainer(
const string &sym_name,
58 const string &real_name,
const string &type) :
59 BESContainer(sym_name, real_name, type), d_remoteResource(0) {
68 string use_real_name = BESUtil::url_create(url_parts);
70 if (!AllowedHosts::theHosts()->is_allowed(use_real_name)) {
71 string err = (string)
"The specified URL " + real_name
72 +
" does not match any of the accessible services in"
73 +
" the allowed hosts list.";
86 BESContainer(copy_from), d_remoteResource(copy_from.d_remoteResource) {
89 if (d_remoteResource) {
90 string err = (string)
"The Container has already been accessed, "
91 +
"can not create a copy of this container.";
97 if (copy_to.d_remoteResource) {
98 string err = (string)
"The Container has already been accessed, "
99 +
"can not duplicate this resource.";
102 copy_to.d_remoteResource = d_remoteResource;
109 _duplicate(*container);
113 GatewayContainer::~GatewayContainer() {
114 if (d_remoteResource) {
126 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
131 BESDEBUG( MODULE, prolog <<
"Accessing " << url << endl);
134 if (type == GATEWAY_CONTAINER_TYPE)
137 if(!d_remoteResource) {
138 BESDEBUG( MODULE, prolog <<
"Building new RemoteResource." << endl );
142 BESDEBUG( MODULE, prolog <<
"Located remote resource." << endl );
146 BESDEBUG( MODULE, prolog <<
"Using local cache file: " << cachedResource << endl );
148 type = d_remoteResource->
getType();
150 BESDEBUG( MODULE, prolog <<
"Type: " << type << endl );
152 BESDEBUG( MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
153 BESDEBUG( MODULE, prolog <<
"Done accessing " << *
this << endl);
154 BESDEBUG( MODULE, prolog <<
"END" << endl);
156 return cachedResource;
168 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
169 if (d_remoteResource) {
170 BESDEBUG( MODULE, prolog <<
"Releasing RemoteResource" << endl);
171 delete d_remoteResource;
172 d_remoteResource = 0;
174 BESDEBUG( MODULE, prolog <<
"END" << endl);
186 strm << BESIndent::LMarg <<
"GatewayContainer::dump - (" << (
void *)
this
190 if (d_remoteResource) {
191 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->
getCacheFileName()
193 strm << BESIndent::LMarg <<
"response headers: ";
198 vector<string>::const_iterator i = hdrs->begin();
199 vector<string>::const_iterator e = hdrs->end();
200 for (; i != e; i++) {
201 string hdr_line = (*i);
202 strm << BESIndent::LMarg << hdr_line << endl;
204 BESIndent::UnIndent();
206 strm <<
"none" << endl;
209 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
211 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
std::string get_container_type() const
retrieve the type of data this container holds, such as cedar or netcdf.
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
error thrown if there is a user syntax error in the request or any other user error
static void url_explode(const std::string &url_str, BESUtil::url &url_parts)
Given a url, break the url into its different parts.
Container representing a remote request.
virtual std::string access()
access the remote target response by making the remote request
virtual bool release()
release the resources
virtual BESContainer * ptr_duplicate()
pure abstract method to duplicate this instances of BESContainer
virtual void dump(std::ostream &strm) const
dumps information about this object
std::string getCacheFileName()
std::vector< std::string > * getResponseHeaders()