00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <sstream>
00034
00035 using std::ostringstream;
00036
00037 #include "BESDapTransmit.h"
00038 #include "DODSFilter.h"
00039 #include "BESContainer.h"
00040 #include "BESDapNames.h"
00041 #include "BESDataNames.h"
00042 #include "BESResponseNames.h"
00043 #include "mime_util.h"
00044 #include "BESDASResponse.h"
00045 #include "BESDDSResponse.h"
00046 #include "BESDataDDSResponse.h"
00047 #include "BESContextManager.h"
00048 #include "BESDapError.h"
00049 #include "BESInternalFatalError.h"
00050 #include "BESDebug.h"
00051 #include "Error.h"
00052
00053 BESDapTransmit::BESDapTransmit()
00054 : BESBasicTransmitter()
00055 {
00056 add_method( DAS_SERVICE, BESDapTransmit::send_basic_das ) ;
00057 add_method( DDS_SERVICE, BESDapTransmit::send_basic_dds ) ;
00058 add_method( DDX_SERVICE, BESDapTransmit::send_basic_ddx ) ;
00059 add_method( DATA_SERVICE, BESDapTransmit::send_basic_data ) ;
00060 add_method( DATADDX_SERVICE, BESDapTransmit::send_basic_dataddx ) ;
00061 }
00062
00063 void
00064 BESDapTransmit::send_basic_das(BESResponseObject * obj,
00065 BESDataHandlerInterface & dhi)
00066 {
00067 BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(obj);
00068 if( !bdas )
00069 throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00070 DAS *das = bdas->get_das();
00071 dhi.first_container();
00072
00073 bool found = false ;
00074 string context = "transmit_protocol" ;
00075 string protocol = BESContextManager::TheManager()->get_context( context,
00076 found ) ;
00077 bool print_mime = false ;
00078 if( protocol == "HTTP" ) print_mime = true ;
00079
00080 try
00081 {
00082 DODSFilter df ;
00083 df.set_dataset_name( dhi.container->get_real_name() ) ;
00084 df.send_das( dhi.get_output_stream(), *das, "", print_mime ) ;
00085 }
00086 catch( InternalErr &e )
00087 {
00088 string err = "libdap error transmitting DAS: "
00089 + e.get_error_message() ;
00090 throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00091 }
00092 catch( Error &e )
00093 {
00094 string err = "libdap error transmitting DAS: "
00095 + e.get_error_message() ;
00096 throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00097 }
00098 catch(...)
00099 {
00100 string s = "unknown error caught transmitting DAS" ;
00101 BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00102 throw ex;
00103 }
00104 }
00105
00106 void BESDapTransmit::send_basic_dds(BESResponseObject * obj,
00107 BESDataHandlerInterface & dhi)
00108 {
00109 BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00110 if( !bdds )
00111 throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00112 DDS *dds = bdds->get_dds();
00113 ConstraintEvaluator & ce = bdds->get_ce();
00114 dhi.first_container();
00115
00116 bool found = false ;
00117 string context = "transmit_protocol" ;
00118 string protocol = BESContextManager::TheManager()->get_context( context,
00119 found ) ;
00120 bool print_mime = false ;
00121 if( protocol == "HTTP" ) print_mime = true ;
00122
00123 try {
00124 DODSFilter df;
00125 df.set_dataset_name(dhi.container->get_real_name());
00126 df.set_ce(dhi.data[POST_CONSTRAINT]);
00127 df.send_dds(dhi.get_output_stream(), *dds, ce, true, "", print_mime);
00128 }
00129 catch( InternalErr &e )
00130 {
00131 string err = "libdap error transmitting DDS: "
00132 + e.get_error_message() ;
00133 throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00134 }
00135 catch( Error &e )
00136 {
00137 string err = "libdap error transmitting DDS: "
00138 + e.get_error_message() ;
00139 throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00140 }
00141 catch(...)
00142 {
00143 string s = "unknown error caught transmitting DDS" ;
00144 BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00145 throw ex;
00146 }
00147 }
00148
00149 void BESDapTransmit::send_basic_data(BESResponseObject * obj,
00150 BESDataHandlerInterface & dhi)
00151 {
00152 BESDataDDSResponse *bdds = dynamic_cast < BESDataDDSResponse * >(obj);
00153 if( !bdds )
00154 throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00155 DataDDS *dds = bdds->get_dds();
00156 ConstraintEvaluator & ce = bdds->get_ce();
00157 dhi.first_container();
00158
00159 bool found = false ;
00160 string context = "transmit_protocol" ;
00161 string protocol = BESContextManager::TheManager()->get_context( context,
00162 found ) ;
00163 bool print_mime = false ;
00164 if( protocol == "HTTP" ) print_mime = true ;
00165
00166 try {
00167 DODSFilter df;
00168 df.set_dataset_name(dds->filename());
00169 df.set_ce(dhi.data[POST_CONSTRAINT]);
00170 df.send_data(*dds, ce, dhi.get_output_stream(), "", print_mime);
00171 }
00172 catch( InternalErr &e )
00173 {
00174 string err = "libdap error transmitting DataDDS: "
00175 + e.get_error_message() ;
00176 throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00177 }
00178 catch( Error &e )
00179 {
00180 string err = "libdap error transmitting DataDDS: "
00181 + e.get_error_message() ;
00182 throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00183 }
00184 catch(...)
00185 {
00186 string s = "unknown error caught transmitting DataDDS" ;
00187 BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00188 throw ex;
00189 }
00190 }
00191
00192 void BESDapTransmit::send_basic_ddx(BESResponseObject * obj,
00193 BESDataHandlerInterface & dhi)
00194 {
00195 BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00196 if( !bdds )
00197 throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00198 DDS *dds = bdds->get_dds();
00199 ConstraintEvaluator & ce = bdds->get_ce();
00200 dhi.first_container();
00201
00202 bool found = false ;
00203 string context = "transmit_protocol" ;
00204 string protocol = BESContextManager::TheManager()->get_context( context,
00205 found ) ;
00206 bool print_mime = false ;
00207 if( protocol == "HTTP" ) print_mime = true ;
00208
00209 try {
00210 DODSFilter df;
00211 df.set_dataset_name(dhi.container->get_real_name());
00212 df.set_ce(dhi.data[POST_CONSTRAINT]);
00213 df.send_ddx(*dds, ce, dhi.get_output_stream(), print_mime);
00214 }
00215 catch( InternalErr &e )
00216 {
00217 string err = "libdap error transmitting DDX: "
00218 + e.get_error_message() ;
00219 throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00220 }
00221 catch( Error &e )
00222 {
00223 string err = "libdap error transmitting DDX: "
00224 + e.get_error_message() ;
00225 throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00226 }
00227 catch(...)
00228 {
00229 string s = "unknown error caught transmitting DDX" ;
00230 BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00231 throw ex;
00232 }
00233 }
00234
00235 void BESDapTransmit::send_basic_dataddx(BESResponseObject * obj,
00236 BESDataHandlerInterface & dhi)
00237 {
00238 BESDataDDSResponse *bdds = dynamic_cast < BESDataDDSResponse * >(obj);
00239 if( !bdds )
00240 throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00241 DataDDS *dds = bdds->get_dds();
00242 ConstraintEvaluator & ce = bdds->get_ce();
00243 dhi.first_container();
00244
00245 bool found = false ;
00246 string context = "transmit_protocol" ;
00247 string protocol = BESContextManager::TheManager()->get_context( context,
00248 found ) ;
00249 bool print_mime = false ;
00250 if( protocol == "HTTP" ) print_mime = true ;
00251
00252 try {
00253 DODSFilter df;
00254 df.set_dataset_name(dds->filename());
00255 df.set_ce(dhi.data[POST_CONSTRAINT]);
00256 BESDEBUG("dap", "dhi.data[DATADDX_STARTID]: " << dhi.data[DATADDX_STARTID] << endl);
00257 df.send_data_ddx(*dds, ce, dhi.get_output_stream(),
00258 dhi.data[DATADDX_STARTID], dhi.data[DATADDX_BOUNDARY],
00259 "", print_mime);
00260 }
00261 catch( InternalErr &e )
00262 {
00263 string err = "libdap error transmitting DataDDS: "
00264 + e.get_error_message() ;
00265 throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00266 }
00267 catch( Error &e )
00268 {
00269 string err = "libdap error transmitting DataDDS: "
00270 + e.get_error_message() ;
00271 throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00272 }
00273 catch(...)
00274 {
00275 string s = "unknown error caught transmitting DataDDS" ;
00276 BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00277 throw ex;
00278 }
00279 }
00280