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();