bes  Updated for version 3.19.1
BESDataResponseHandler.cc
1 // BESDataResponseHandler.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) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <cstdlib>
34 #include <cerrno>
35 #include <cstring>
36 
37 #include <DDS.h>
38 #include <DataDDS.h>
39 
40 #include "BESDataResponseHandler.h"
41 #include "BESDataDDSResponse.h"
42 #include "BESRequestHandlerList.h"
43 #include "BESDapNames.h"
44 #include "BESDataNames.h"
45 #include "BESContextManager.h"
46 #include "BESInternalError.h"
47 #include "BESDebug.h"
48 
49 using namespace libdap;
50 using namespace std;
51 
52 BESDataResponseHandler::BESDataResponseHandler( const string &name )
53  : BESResponseHandler( name )
54 {
55 }
56 
57 BESDataResponseHandler::~BESDataResponseHandler( )
58 {
59 }
60 
76 {
77  dhi.action_name = DATA_RESPONSE_STR;
78  // NOTE: It is the responsibility of the specific request handler to set
79  // the BaseTypeFactory. It is set to NULL here
80  DDS *dds = new DDS(NULL, "virtual");
81  BESDataDDSResponse *bdds = new BESDataDDSResponse(dds);
82 
83  // Set the DAP protocol version requested by the client. 2/25/11 jhrg
84 
85  dhi.first_container();
86 
87  BESDEBUG("version", "Initial CE: " << dhi.container->get_constraint() << endl);
88 
89  // FIXME Keywords should not be used and this should be removed. jhrg 2/20/15
90  dhi.container->set_constraint(dds->get_keywords().parse_keywords(dhi.container->get_constraint()));
91  BESDEBUG("version", "CE after keyword processing: " << dhi.container->get_constraint() << endl);
92 
93  bool found;
94  string response_size_limit = BESContextManager::TheManager()->get_context("max_response_size", found);
95  if (found && !response_size_limit.empty()) {
96  char *endptr;
97  errno = 0;
98  long rsl = strtol(response_size_limit.c_str(), &endptr, /*int base*/ 10);
99  if (rsl == 0 && errno > 0) {
100  string err = strerror(errno);
101  delete dds; dds = 0;
102  delete bdds; bdds = 0;
103  throw BESInternalError("The responseSizeLimit context value ("
104  + response_size_limit + ") was bad: " + err, __FILE__, __LINE__);
105  }
106 
107  dds->set_response_limit(rsl); // The default for this is zero
108  }
109 
110  // FIXME This should be fixed too... (see above re keywords). jhrg 2/20/15
111  if (dds->get_keywords().has_keyword("dap")) {
112  dds->set_dap_version(dds->get_keywords().get_keyword_value("dap"));
113  }
114  else if (!bdds->get_dap_client_protocol().empty()) {
115  dds->set_dap_version(bdds->get_dap_client_protocol());
116  }
117 
118  _response = bdds;
119  BESRequestHandlerList::TheList()->execute_each(dhi);
120 }
121 
133 void
136 {
137  if( _response )
138  {
139  transmitter->send_response( DATA_SERVICE, _response, dhi ) ;
140  }
141 }
142 
149 void
150 BESDataResponseHandler::dump( ostream &strm ) const
151 {
152  strm << BESIndent::LMarg << "BESDataResponseHandler::dump - ("
153  << (void *)this << ")" << endl ;
154  BESIndent::Indent() ;
155  BESResponseHandler::dump( strm ) ;
156  BESIndent::UnIndent() ;
157 }
158 
160 BESDataResponseHandler::DataResponseBuilder( const string &name )
161 {
162  return new BESDataResponseHandler( name ) ;
163 }
164 
exception thrown if inernal error encountered
response handler that builds an OPeNDAP Data DDS object
virtual string get_context(const string &name, bool &found)
retrieve the value of the specified context from the BES
handler object that knows how to create a specific response object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
void set_constraint(const string &s)
set the constraint for this container
Definition: BESContainer.h:104
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
string get_constraint() const
retrieve the constraint expression for this container
Definition: BESContainer.h:170
string get_dap_client_protocol() const
Return the dap version string sent by the client (e.g., the OLFS)
virtual void dump(ostream &strm) const
dumps information about this object
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get data for <def_name>' by executing the request for each container in the spe...
void first_container()
set the container pointer to the first container in the containers list
BESContainer * container
pointer to current container in this interface