bes  Updated for version 3.19.1
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 <sstream>
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 
36 BESDap4ResponseHandler::BESDap4ResponseHandler(const string &name) : BESResponseHandler(name)
37 {
38 }
39 
40 BESDap4ResponseHandler::~BESDap4ResponseHandler()
41 {
42 }
43 
52 {
53  dhi.action_name = DAP4DATA_RESPONSE_STR;
54  DMR *dmr = new DMR();
55 
56  // Here we might set the dap and dmr version if they should be different from
57  // 4.0 and 1.0. jhrg 11/6/13
58 
59  // Also, the DataResponseHandler does stuff with containers and the constraint.
60  // ...might look into that. jhrg 11/7/13
61  bool found;
62  string response_size_limit = BESContextManager::TheManager()->get_context("max_response_size", found);
63  if (found && !response_size_limit.empty()) {
64  std::istringstream iss(response_size_limit);
65  long long rsl = -1;
66  iss >> rsl;
67  if (rsl == -1)
68  throw BESInternalError("The max_response_size context value (" + response_size_limit + ") not read",
69  __FILE__, __LINE__);
70  dmr->set_response_limit(rsl); // The default for this is zero
71  }
72 
73  string xml_base = BESContextManager::TheManager()->get_context("xml:base", found);
74  if (found && !xml_base.empty()) {
75  dmr->set_request_xml_base(xml_base);
76  }
77 
78  _response = new BESDMRResponse(dmr);
79 
80  BESRequestHandlerList::TheList()->execute_each(dhi);
81 }
82 
96 {
97  if (_response) {
98  transmitter->send_response(DAP4DATA_SERVICE, _response, dhi);
99  }
100 }
101 
108 void BESDap4ResponseHandler::dump(ostream &strm) const
109 {
110  strm << BESIndent::LMarg << "BESDap4ResponseHandler::dump - (" << (void *) this << ")" << endl;
111  BESIndent::Indent();
113  BESIndent::UnIndent();
114 }
115 
117 BESDap4ResponseHandler::Dap4ResponseBuilder(const string &name)
118 {
119  return new BESDap4ResponseHandler(name);
120 }
121 
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
exception thrown if inernal error encountered
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
response handler that builds an OPeNDAP Dap4 data response
Represents an OPeNDAP DMR DAP4 data object within the BES.
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get dap for def_name;'
Structure storing information used by the BES to handle the request.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object