bes  Updated for version 3.20.6
BESDap4ResponseHandler.cc
1 // BESDap4ResponseHandler.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2013 OPeNDAP
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 #include "config.h"
24 
25 #include <memory>
26 
27 #include <DMR.h>
28 
29 #include "BESDap4ResponseHandler.h"
30 #include "BESDMRResponse.h"
31 #include "BESRequestHandlerList.h"
32 #include "BESDapNames.h"
33 #include "BESDapTransmit.h"
34 #include "BESContextManager.h"
35 #include "TheBESKeys.h"
36 #include "BESDebug.h"
37 
38 #include "GlobalMetadataStore.h"
39 
40 using namespace std;
41 using namespace bes;
42 
43 BESDap4ResponseHandler::BESDap4ResponseHandler(const string &name)
44  : BESResponseHandler(name), d_use_dmrpp(false), d_dmrpp_name(DMRPP_DEFAULT_NAME)
45 {
46  d_use_dmrpp = TheBESKeys::TheKeys()->read_bool_key(USE_DMRPP_KEY, false); // defined in BESDapNames.h
47  d_dmrpp_name = TheBESKeys::TheKeys()->read_string_key(DMRPP_NAME_KEY, DMRPP_DEFAULT_NAME);
48 }
49 
50 BESDap4ResponseHandler::~BESDap4ResponseHandler()
51 {
52 }
53 
62 {
63  dhi.action_name = DAP4DATA_RESPONSE_STR;
64 
65  if (d_use_dmrpp) {
66  GlobalMetadataStore *mds = GlobalMetadataStore::get_instance(); // mds may be NULL
67 
69  dhi.first_container();
70  if (mds) lock = mds->is_dmrpp_available(*(dhi.container));
71 
72  // If we were able to lock the DMR++ it must exist; use it.
73  if (mds && lock()) {
74  BESDEBUG("dmrpp",
75  "In BESDap4ResponseHandler::execute(): Found a DMR++ response for '" << dhi.container->get_relative_name() << "'" << endl);
76 
77  // Redirect the request to the DMR++ handler
78  dhi.container->set_container_type(d_dmrpp_name);
79 
80  // Add information to the container so the dmrpp handler works
81  // This tells DMR++ handler to look for this in the MDS
82  dhi.container->set_attributes(MDS_HAS_DMRPP);
83  }
84  }
85 
86  auto_ptr<DMR> dmr(new DMR());
87 
88  bool found;
89  int response_size_limit = BESContextManager::TheManager()->get_context_int("max_response_size", found);
90 
91  if (found)
92  dmr->set_response_limit(response_size_limit);
93 
94  string xml_base = BESContextManager::TheManager()->get_context("xml:base", found);
95  if (found && !xml_base.empty())
96  dmr->set_request_xml_base(xml_base);
97 
98  d_response_object = new BESDMRResponse(dmr.release());
99 
100  BESRequestHandlerList::TheList()->execute_each(dhi);
101 }
102 
116 {
117  if (d_response_object) {
118  transmitter->send_response(DAP4DATA_SERVICE, d_response_object, dhi);
119  }
120 }
121 
128 void BESDap4ResponseHandler::dump(ostream &strm) const
129 {
130  strm << BESIndent::LMarg << "BESDap4ResponseHandler::dump - (" << (void *) this << ")" << endl;
131  BESIndent::Indent();
133  BESIndent::UnIndent();
134 }
135 
137 BESDap4ResponseHandler::Dap4ResponseBuilder(const string &name)
138 {
139  return new BESDap4ResponseHandler(name);
140 }
141 
BESDataHandlerInterface::container
BESContainer * container
pointer to current container in this interface
Definition: BESDataHandlerInterface.h:75
BESDap4ResponseHandler::transmit
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
Definition: BESDap4ResponseHandler.cc:115
bes::GlobalMetadataStore::MDSReadLock
Unlock and close the MDS item when the ReadLock goes out of scope.
Definition: GlobalMetadataStore.h:193
BESContainer::set_attributes
void set_attributes(const std::string &attrs)
set desired attributes for this container
Definition: BESContainer.h:170
TheBESKeys::read_string_key
std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Definition: TheBESKeys.cc:351
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESContainer::get_relative_name
std::string get_relative_name() const
Get the relative name of the object in this container.
Definition: BESContainer.h:186
BESRequestHandlerList::execute_each
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
Definition: BESRequestHandlerList.cc:167
TheBESKeys::read_bool_key
bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
Definition: TheBESKeys.cc:326
bes::GlobalMetadataStore
Store the DAP metadata responses.
Definition: GlobalMetadataStore.h:89
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
BESDap4ResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDap4ResponseHandler.cc:128
BESContextManager::get_context_int
virtual int get_context_int(const std::string &name, bool &found)
Get the value of the given context and return it as an integer.
Definition: BESContextManager.cc:99
BESDap4ResponseHandler::execute
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get dap for def_name;'
Definition: BESDap4ResponseHandler.cc:61
BESResponseHandler
handler object that knows how to create a specific response object
Definition: BESResponseHandler.h:77
BESTransmitter
Definition: BESTransmitter.h:47
BESDap4ResponseHandler
response handler that builds an OPeNDAP Dap4 data response
Definition: BESDap4ResponseHandler.h:49
bes::GlobalMetadataStore::is_dmrpp_available
virtual MDSReadLock is_dmrpp_available(const std::string &name)
Is the DMR++ response for.
Definition: GlobalMetadataStore.cc:928
BESDataHandlerInterface::first_container
void first_container()
set the container pointer to the first container in the containers list
Definition: BESDataHandlerInterface.h:135
BESContextManager::get_context
virtual std::string get_context(const std::string &name, bool &found)
retrieve the value of the specified context from the BES
Definition: BESContextManager.cc:77
BESContainer::set_container_type
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
Definition: BESContainer.h:161
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESDMRResponse
Represents an OPeNDAP DMR DAP4 data object within the BES.
Definition: BESDMRResponse.h:39