30 #include <BESSyntaxUserError.h>
31 #include <BESInternalError.h>
34 #include <TheBESKeys.h>
35 #include <WhiteList.h>
37 #include "GatewayContainer.h"
38 #include "GatewayUtils.h"
39 #include "GatewayResponseNames.h"
40 #include "RemoteHttpResource.h"
43 using namespace gateway;
56 GatewayContainer::GatewayContainer(
const string &sym_name,
57 const string &real_name,
const string &type) :
58 BESContainer(sym_name, real_name, type), d_remoteResource(0) {
67 string use_real_name = BESUtil::url_create(url_parts);
69 if (!WhiteList::get_white_list()->is_white_listed(use_real_name)) {
70 string err = (string)
"The specified URL " + real_name
71 +
" does not match any of the accessible services in"
85 BESContainer(copy_from), d_remoteResource(copy_from.d_remoteResource) {
88 if (d_remoteResource) {
89 string err = (string)
"The Container has already been accessed, "
90 +
"can not create a copy of this container.";
96 if (copy_to.d_remoteResource) {
97 string err = (string)
"The Container has already been accessed, "
98 +
"can not duplicate this resource.";
101 copy_to.d_remoteResource = d_remoteResource;
108 _duplicate(*container);
112 GatewayContainer::~GatewayContainer() {
113 if (d_remoteResource) {
125 BESDEBUG(
"gateway",
"GatewayContainer::access() - BEGIN" << endl);
130 BESDEBUG(
"gateway",
"GatewayContainer::access() - Accessing " << url << endl);
133 if (type ==
"gateway")
136 if(!d_remoteResource) {
137 BESDEBUG(
"gateway",
"GatewayContainer::access() - Building new RemoteResource." << endl );
141 BESDEBUG(
"gateway",
"GatewayContainer::access() - Located remote resource." << endl );
145 BESDEBUG(
"gateway",
"GatewayContainer::access() - Using local cache file: " << cachedResource << endl );
147 type = d_remoteResource->
getType();
149 BESDEBUG(
"gateway",
"GatewayContainer::access() - Type: " << type << endl );
152 BESDEBUG(
"gateway",
"GatewayContainer::access() - Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
153 BESDEBUG(
"gateway",
"GatewayContainer::access() - Done accessing " << *
this << endl);
154 BESDEBUG(
"gateway",
"GatewayContainer::access() - END" << endl);
156 return cachedResource;
168 if (d_remoteResource) {
169 BESDEBUG(
"gateway",
"GatewayContainer::release() - Releasing RemoteResource" << endl);
170 delete d_remoteResource;
171 d_remoteResource = 0;
174 BESDEBUG(
"gateway",
"done releasing gateway response" << 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::vector< std::string > * getResponseHeaders()
std::string getCacheFileName()