OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESShowErrorResponseHandler.cc
Go to the documentation of this file.
00001 // BESShowErrorResponseHandler.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include <sstream>
00034 
00035 using std::istringstream ;
00036 
00037 #include "BESShowErrorResponseHandler.h"
00038 #include "BESDataNames.h"
00039 #include "BESInternalError.h"
00040 #include "BESInternalFatalError.h"
00041 #include "BESSyntaxUserError.h"
00042 #include "BESForbiddenError.h"
00043 #include "BESNotFoundError.h"
00044 
00045 BESShowErrorResponseHandler::BESShowErrorResponseHandler( const string &name )
00046     : BESResponseHandler( name )
00047 {
00048 }
00049 
00050 BESShowErrorResponseHandler::~BESShowErrorResponseHandler( )
00051 {
00052 }
00053 
00068 void
00069 BESShowErrorResponseHandler::execute( BESDataHandlerInterface &dhi )
00070 {
00071     string etype_s = dhi.data[SHOW_ERROR_TYPE] ;
00072     if( etype_s.empty() )
00073     {
00074         string err = dhi.action + " error type missing" ;
00075         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00076     }
00077     istringstream strm( etype_s ) ;
00078     unsigned int etype = 0 ;
00079     strm >> etype ;
00080     if( !etype || etype > 5 )
00081     {
00082         string err = dhi.action + " invalid error type, should be 1-5" ;
00083         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00084     }
00085     switch( etype )
00086     {
00087         case BES_INTERNAL_ERROR:
00088         {
00089             string err = dhi.action + " Internal Error" ;
00090             throw BESInternalError( err, __FILE__, __LINE__ ) ;
00091             break ;
00092         }
00093         case BES_INTERNAL_FATAL_ERROR:
00094         {
00095             string err = dhi.action + " Internal Fatal Error" ;
00096             throw BESInternalFatalError( err, __FILE__, __LINE__ ) ;
00097             break ;
00098         }
00099         case BES_SYNTAX_USER_ERROR:
00100         {
00101             string err = dhi.action + " Syntax User Error" ;
00102             throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00103             break ;
00104         }
00105         case BES_FORBIDDEN_ERROR:
00106         {
00107             string err = dhi.action + " Forbidden Error" ;
00108             throw BESForbiddenError( err, __FILE__, __LINE__ ) ;
00109             break ;
00110         }
00111         case BES_NOT_FOUND_ERROR:
00112         {
00113             string err = dhi.action + " Not Found Error" ;
00114             throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
00115             break ;
00116         }
00117     }
00118 }
00119 
00132 void
00133 BESShowErrorResponseHandler::transmit( BESTransmitter *transmitter,
00134                                         BESDataHandlerInterface &dhi )
00135 {
00136     string err = "An exception should have been thrown, nothing to transmit" ;
00137     throw BESInternalError( err, __FILE__, __LINE__ ) ;
00138 }
00139 
00146 void
00147 BESShowErrorResponseHandler::dump( ostream &strm ) const
00148 {
00149     strm << BESIndent::LMarg << "BESShowErrorResponseHandler::dump - ("
00150                              << (void *)this << ")" << endl ;
00151     BESIndent::Indent() ;
00152     BESResponseHandler::dump( strm ) ;
00153     BESIndent::UnIndent() ;
00154 }
00155 
00156 BESResponseHandler *
00157 BESShowErrorResponseHandler::ResponseBuilder( const string &name )
00158 {
00159     return new BESShowErrorResponseHandler( name ) ;
00160 }
00161