bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
SetContextsResponseHandler.cc
1// SetContextsResponseHandler.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) 2018 OPeNDAP, Inc.
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// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <cassert>
28
29#include <string>
30#include <sstream>
31
32#include "BESContextManager.h"
33#include "BESDataNames.h"
34#include "BESSyntaxUserError.h"
35#include "BESDataHandlerInterface.h"
36
37#include "SetContextsNames.h"
38#include "SetContextsResponseHandler.h"
39
40#include "BESDebug.h"
41
42using namespace bes;
43using namespace std;
44
54{
55 // To record the information in the DHI data[] map, use one value to hold a
56 // list of all of Context names, then use the names to hold the values. Read
57 // this using names = data[CONTEXT_NAMES] and then:
58 //
59 // for each 'name' in names { value = data['context_'name] }
60 //
61 string names = dhi.data[CONTEXT_NAMES];
62 if (names.empty())
63 throw BESSyntaxUserError( "setContexts: No context names found in the data.", __FILE__, __LINE__);
64
65 BESDEBUG("besxml", "dhi.data[CONTEXT_NAMES]: " << names << endl);
66
67 istringstream iss(names);
68 string name;
69 iss >> name;
70 while (iss && !name.empty()) {
71
72 string value = dhi.data[name];
73
74 if (value.empty())
75 throw BESSyntaxUserError( "setContexts: Context value was not found in the data.", __FILE__, __LINE__);
76
77 // Remove the CONTEXT_PREFIX before adding the context
78 assert(name.find(CONTEXT_PREFIX) != string::npos); // Is the prefix really there?
79 name.erase(0, sizeof(CONTEXT_PREFIX)-1); // The constant includes the two double quotes
80
81 BESDEBUG("besxml", "BESContextManager::TheManager()->set_context(" << name << ", " << value << ")" << endl);
82
83 BESContextManager::TheManager()->set_context(name, value);
84
85 iss >> name;
86 }
87
88 // This would be used in the transmit() method below to send a response back to the
89 // BES's client, if this command returned data. Since it does not, this can be NULL
90 // and the transmit() method can be a no-op. jhrg 2/8/18
91 d_response_object = 0;
92}
93
102
109void SetContextsResponseHandler::dump(ostream &strm) const
110{
111 strm << BESIndent::LMarg << "BESSetContextResponseHandler::dump - (" << (void *) this << ")" << endl;
112 BESIndent::Indent();
114 BESIndent::UnIndent();
115}
116
118SetContextsResponseHandler::SetContextsResponseBuilder(const string &name)
119{
120 return new SetContextsResponseHandler(name);
121}
122
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
error thrown if there is a user syntax error in the request or any other user error
Set a number of context name-value pairs at once.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
For the setContexts command, this is a no-op.
virtual void execute(BESDataHandlerInterface &dhi)
Set multiple contexts in the BES's Context Manager.