32#include "BESSyntaxUserError.h"
33#include "BESInternalError.h"
36#include "AllowedHosts.h"
38#include "GatewayContainer.h"
39#include "GatewayNames.h"
40#include "RemoteResource.h"
43using namespace gateway;
47#define prolog std::string("GatewayContainer::").append(__func__).append("() - ")
59GatewayContainer::GatewayContainer(
const string &sym_name,
60 const string &real_name,
const string &type) :
61 BESContainer(sym_name, real_name, type), d_remoteResource(0) {
70 string url_string = BESUtil::url_create(url_parts);
72 std::shared_ptr<http::url> target_url(
new http::url(url_string));
74 if (!http::AllowedHosts::theHosts()->is_allowed(target_url)) {
75 string err = (string)
"The specified URL " + real_name
76 +
" does not match any of the accessible services in"
77 +
" the allowed hosts list.";
89GatewayContainer::GatewayContainer(
const GatewayContainer ©_from) :
90 BESContainer(copy_from), d_remoteResource(copy_from.d_remoteResource) {
93 if (d_remoteResource) {
94 string err = (string)
"The Container has already been accessed, "
95 +
"can not create a copy of this container.";
101 if (copy_to.d_remoteResource) {
102 string err = (string)
"The Container has already been accessed, "
103 +
"can not duplicate this resource.";
106 copy_to.d_remoteResource = d_remoteResource;
112 GatewayContainer *container =
new GatewayContainer;
113 _duplicate(*container);
117GatewayContainer::~GatewayContainer() {
118 if (d_remoteResource) {
130 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
135 BESDEBUG( MODULE, prolog <<
"Accessing " << url << endl);
138 if (type == GATEWAY_CONTAINER_TYPE)
141 if(!d_remoteResource) {
142 BESDEBUG( MODULE, prolog <<
"Building new RemoteResource." << endl );
143 std::shared_ptr<http::url> url_ptr(
new http::url(url));
145 d_remoteResource->retrieve_resource();
147 BESDEBUG( MODULE, prolog <<
"Located remote resource." << endl );
150 string local_name = d_remoteResource->get_filename();
151 BESDEBUG( MODULE, prolog <<
"Using local file: " << local_name << endl );
153 type = d_remoteResource->get_type();
155 BESDEBUG( MODULE, prolog <<
"Type: " << type << endl );
157 BESDEBUG( MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << local_name << endl);
158 BESDEBUG( MODULE, prolog <<
"Done accessing " << *
this << endl);
159 BESDEBUG( MODULE, prolog <<
"END" << endl);
173 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
174 if (d_remoteResource) {
175 BESDEBUG( MODULE, prolog <<
"Releasing RemoteResource" << endl);
176 delete d_remoteResource;
177 d_remoteResource = 0;
179 BESDEBUG( MODULE, prolog <<
"END" << endl);
191 strm << BESIndent::LMarg <<
"GatewayContainer::dump - (" << (
void *)
this
195 if (d_remoteResource) {
196 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->get_filename()
199 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
201 BESIndent::UnIndent();
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
void dump(std::ostream &strm) const override
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
Parse a URL into the protocol, host, path and query parts.