OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESExceptionManager.cc
Go to the documentation of this file.
1 // BESExceptionManager.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "BESExceptionManager.h"
34 
35 #include "BESError.h"
36 #include "TheBESKeys.h"
37 #include "BESInfoList.h"
38 
39 #define DEFAULT_ADMINISTRATOR "support@opendap.org"
40 
41 BESExceptionManager *BESExceptionManager::_instance = 0 ;
42 
44 {
45 }
46 
48 {
49 }
50 
64 void
66 {
67  _ehm_list.push_back( ehm ) ;
68 }
69 
90 int
93 {
94  // Let's see if any of these exception callbacks can handle the
95  // exception. The first callback that can handle the exception wins
96  ehm_iter i = _ehm_list.begin() ;
97  for( ; i != _ehm_list.end(); i++ )
98  {
99  p_bes_ehm p = *i ;
100  int handled = p( e, dhi ) ;
101  if( handled )
102  {
103  return handled ;
104  }
105  }
106 
108  string action_name = dhi.action_name ;
109  if( action_name == "" )
110  action_name = "BES" ;
111  dhi.error_info->begin_response( action_name, dhi ) ;
112 
113  string administrator = "" ;
114  try
115  {
116  bool found = false ;
117  vector<string> vals ;
118  string key = "BES.ServerAdministrator" ;
119  TheBESKeys::TheKeys()->get_value( key, administrator, found ) ;
120  }
121  catch( ... )
122  {
123  administrator = DEFAULT_ADMINISTRATOR ;
124  }
125  if( administrator.empty() )
126  {
127  administrator = DEFAULT_ADMINISTRATOR ;
128  }
129  dhi.error_info->add_exception( e, administrator ) ;
130  dhi.error_info->end_response() ;
131  return e.get_error_type() ;
132 }
133 
143 void
144 BESExceptionManager::dump( ostream &strm ) const
145 {
146  strm << BESIndent::LMarg << "BESExceptionManager::dump - ("
147  << (void *)this << ")" << endl ;
149  strm << BESIndent::LMarg << "# registered callbacks: " << _ehm_list.size() << endl ;
151 }
152 
155 {
156  if( _instance == 0 )
157  {
158  _instance = new BESExceptionManager( ) ;
159  }
160  return _instance ;
161 }
162 
virtual BESInfo * build_info()
Definition: BESInfoList.cc:77
#define DEFAULT_ADMINISTRATOR
virtual void end_response()
Definition: BESInfo.cc:131
static BESInfoList * TheList()
Definition: BESInfoList.cc:142
virtual void add_ehm_callback(p_bes_ehm ehm)
Register an exception handler with the manager.
static BESExceptionManager * TheEHM()
static void Indent()
Definition: BESIndent.cc:38
virtual int get_error_type()
Return the return code for this error class.
Definition: BESError.h:120
Abstract exception class for the BES with basic string message.
Definition: BESError.h:51
virtual void add_exception(BESError &e, const string &admin)
add exception information to this informational object
Definition: BESInfo.cc:255
manages exception handling code and default exceptions
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
int(* p_bes_ehm)(BESError &e, BESDataHandlerInterface &dhi)
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: BESKeys.cc:453
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
Definition: BESInfo.cc:123
BESInfo * error_info
error information object
virtual int handle_exception(BESError &e, BESDataHandlerInterface &dhi)
Manage any exceptions thrown during the handling of a request.
static void UnIndent()
Definition: BESIndent.cc:44
static BESKeys * TheKeys()
Definition: TheBESKeys.cc:48