bes  Updated for version 3.20.6
BESShowErrorResponseHandler.cc
1 // BESShowErrorResponseHandler.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 <sstream>
34 
35 using std::istringstream;
36 using std::endl;
37 using std::string;
38 using std::ostream;
39 
40 #include "BESShowErrorResponseHandler.h"
41 #include "BESDataNames.h"
42 #include "BESInternalError.h"
43 #include "BESInternalFatalError.h"
44 #include "BESSyntaxUserError.h"
45 #include "BESForbiddenError.h"
46 #include "BESNotFoundError.h"
47 #include "BESDataHandlerInterface.h"
48 
49 BESShowErrorResponseHandler::BESShowErrorResponseHandler(const string &name) :
50  BESResponseHandler(name)
51 {
52 }
53 
54 BESShowErrorResponseHandler::~BESShowErrorResponseHandler()
55 {
56 }
57 
73 {
74  string etype_s = dhi.data[SHOW_ERROR_TYPE];
75  if (etype_s.empty()) {
76  string err = dhi.action + " error type missing";
77  throw BESSyntaxUserError(err, __FILE__, __LINE__);
78  }
79  istringstream strm(etype_s);
80  unsigned int etype = 0;
81  strm >> etype;
82  if (!etype || etype > 5) {
83  string err = dhi.action + " invalid error type, should be 1-5";
84  throw BESSyntaxUserError(err, __FILE__, __LINE__);
85  }
86 
87  switch (etype) {
88  case BES_INTERNAL_ERROR: {
89  string err = dhi.action + " Internal Error";
90  throw BESInternalError(err, __FILE__, __LINE__);
91  }
92  case BES_INTERNAL_FATAL_ERROR: {
93  string err = dhi.action + " Internal Fatal Error";
94  throw BESInternalFatalError(err, __FILE__, __LINE__);
95  }
96  case BES_SYNTAX_USER_ERROR: {
97  string err = dhi.action + " Syntax User Error";
98  throw BESSyntaxUserError(err, __FILE__, __LINE__);
99  }
100  case BES_FORBIDDEN_ERROR: {
101  string err = dhi.action + " Forbidden Error";
102  throw BESForbiddenError(err, __FILE__, __LINE__);
103  }
104  case BES_NOT_FOUND_ERROR: {
105  string err = dhi.action + " Not Found Error";
106  throw BESNotFoundError(err, __FILE__, __LINE__);
107  }
108  }
109 }
110 
124 {
125  string err = "An exception should have been thrown, nothing to transmit";
126  throw BESInternalError(err, __FILE__, __LINE__);
127 }
128 
135 void BESShowErrorResponseHandler::dump(ostream &strm) const
136 {
137  strm << BESIndent::LMarg << "BESShowErrorResponseHandler::dump - (" << (void *) this << ")" << endl;
138  BESIndent::Indent();
140  BESIndent::UnIndent();
141 }
142 
144 BESShowErrorResponseHandler::ResponseBuilder(const string &name)
145 {
146  return new BESShowErrorResponseHandler(name);
147 }
148 
BESShowErrorResponseHandler
response handler that throws the requested exception type
Definition: BESShowErrorResponseHandler.h:50
BESInternalFatalError
exception thrown if an internal error is found and is fatal to the BES
Definition: BESInternalFatalError.h:43
BESDataHandlerInterface::action
std::string action
the response object requested, e.g. das, dds
Definition: BESDataHandlerInterface.h:79
BESNotFoundError
error thrown if the resource requested cannot be found
Definition: BESNotFoundError.h:40
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
BESDataHandlerInterface::data
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Definition: BESDataHandlerInterface.h:90
BESForbiddenError
error thrown if the BES is not allowed to access the resource requested
Definition: BESForbiddenError.h:40
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
BESResponseHandler
handler object that knows how to create a specific response object
Definition: BESResponseHandler.h:77
BESTransmitter
Definition: BESTransmitter.h:47
BESShowErrorResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESShowErrorResponseHandler.cc:135
BESShowErrorResponseHandler::transmit
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
Definition: BESShowErrorResponseHandler.cc:123
BESShowErrorResponseHandler::execute
virtual void execute(BESDataHandlerInterface &dhi)
throws a specific exception to test error handling in clients
Definition: BESShowErrorResponseHandler.cc:72
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56