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         }
00092         case BES_INTERNAL_FATAL_ERROR:
00093         {
00094             string err = dhi.action + " Internal Fatal Error" ;
00095             throw BESInternalFatalError( err, __FILE__, __LINE__ ) ;
00096         }
00097         case BES_SYNTAX_USER_ERROR:
00098         {
00099             string err = dhi.action + " Syntax User Error" ;
00100             throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00101         }
00102         case BES_FORBIDDEN_ERROR:
00103         {
00104             string err = dhi.action + " Forbidden Error" ;
00105             throw BESForbiddenError( err, __FILE__, __LINE__ ) ;
00106         }
00107         case BES_NOT_FOUND_ERROR:
00108         {
00109             string err = dhi.action + " Not Found Error" ;
00110             throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
00111         }
00112     }
00113 }
00114 
00127 void
00128 BESShowErrorResponseHandler::transmit( BESTransmitter *transmitter,
00129                                         BESDataHandlerInterface &dhi )
00130 {
00131     string err = "An exception should have been thrown, nothing to transmit" ;
00132     throw BESInternalError( err, __FILE__, __LINE__ ) ;
00133 }
00134 
00141 void
00142 BESShowErrorResponseHandler::dump( ostream &strm ) const
00143 {
00144     strm << BESIndent::LMarg << "BESShowErrorResponseHandler::dump - ("
00145                              << (void *)this << ")" << endl ;
00146     BESIndent::Indent() ;
00147     BESResponseHandler::dump( strm ) ;
00148     BESIndent::UnIndent() ;
00149 }
00150 
00151 BESResponseHandler *
00152 BESShowErrorResponseHandler::ResponseBuilder( const string &name )
00153 {
00154     return new BESShowErrorResponseHandler( name ) ;
00155 }
00156