bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESWWWGetCommand.cc
1// BesWWWGetCommand.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,2005 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 "BESWWWGetCommand.h"
34#include "BESTokenizer.h"
35#include "BESResponseHandlerList.h"
36#include "BESDefinitionStorageList.h"
37#include "BESDefinitionStorage.h"
38#include "BESDefine.h"
39#include "BESSyntaxUserError.h"
40#include "BESDataNames.h"
41#include "BESWWWNames.h"
42
69{
70 string def_name;
71 string url;
72
73 BESResponseHandler *retResponse =
74 BESResponseHandlerList::TheList()->find_handler(_cmd);
75 if (!retResponse) {
76 string err("Command ");
77 err += _cmd;
78 err += " does not have a registered response handler";
79 throw BESSyntaxUserError(err, __FILE__, __LINE__);
80 }
81 dhi.action = _cmd;
82
83 string my_token = parse_options(tokenizer, dhi);
84 if (my_token != "for") {
85 tokenizer.parse_error(my_token + " not expected\n");
86 } else {
87 def_name = tokenizer.get_next_token();
88
89 my_token = tokenizer.get_next_token();
90 if (my_token == "using") {
91 url = tokenizer.get_next_token();
92
93 my_token = tokenizer.get_next_token();
94 if (my_token != ";") {
95 tokenizer.parse_error(my_token +
96 " not expected, expecting ';'");
97 }
98 } else {
99 tokenizer.parse_error(my_token +
100 " not expected, expecting \"return\" or ';'");
101 }
102 }
103
104 // FIX: should this be using dot notation? Like get das for volatile.d ;
105 // Or do it like the containers, just find the first one available? Same
106 // question for containers then?
107 /*
108 string store_name = DEFAULT ;
109 BESDefinitionStorage *store =
110 BESDefinitionStorageList::TheList()->find_def( store_name ) ;
111 if( !store )
112 {
113 throw BESSyntaxUserError( (string)"Unable to find definition store " + store_name ) ;
114 }
115 */
116
117 BESDefine *d = BESDefinitionStorageList::TheList()->look_for(def_name);
118 if (!d) {
119 string s = (string) "Unable to find definition " + def_name;
120 throw BESSyntaxUserError(s, __FILE__, __LINE__);
121 }
122
123 BESDefine::containers_citer i = d->first_container();
124 BESDefine::containers_citer ie = d->end_container();
125 while (i != ie) {
126 dhi.containers.push_back(*i);
127 i++;
128 }
129 dhi.data[AGG_CMD] = d->get_agg_cmd();
130 dhi.data[AGG_HANDLER] = d->get_agg_handler();
131 dhi.data[WWW_URL] = url;
132
133 return retResponse;
134}
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.
std::string action
the response object requested, e.g. das, dds
handler object that knows how to create a specific response object
error thrown if there is a user syntax error in the request or any other user error
tokenizer for the BES request command string
void parse_error(const std::string &s="")
throws an exception giving the tokens up to the point of the problem
std::string & get_next_token()
returns the next token from the token list
virtual BESResponseHandler * parse_request(BESTokenizer &tokens, BESDataHandlerInterface &dhi)
knows how to parse a get request