45#include <libdap/D4Group.h>
46#include <libdap/D4Attributes.h>
47#include <libdap/BaseType.h>
48#include <libdap/escaping.h>
50#include <BESContextManager.h>
51#include <BESDataDDSResponse.h>
52#include <BESDapNames.h>
53#include <BESDataNames.h>
57#include <RequestServiceTimer.h>
61#include <BESInternalFatalError.h>
62#include <BESDapError.h>
63#include "BESDMRResponse.h"
64#include <stringbuffer.h>
66#include "FONcBaseType.h"
67#include "FONcRequestHandler.h"
68#include "FONcTransmitter.h"
69#include "FONcTransform.h"
76#define prolog string("FONcTransmitter::").append(__func__).append("() - ")
116 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
118 uint64_t bytes_sent = 0;
122 if (!bdds)
throw BESInternalFatalError(
"Expected a BESDataDDSResponse instance", __FILE__, __LINE__);
123 auto dds = bdds->get_dds();
125 string base_name = dds->filename().substr(dds->filename().find_last_of(
"/\\") + 1);
129 string temp_file_name = temp_file.
create(FONcRequestHandler::temp_dir,
"dap2_nc_"+base_name);
131 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file_name << endl);
138 ostream &strm = dhi.get_output_stream();
139 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
145 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file_name << endl);
152 catch (
const Error &e) {
153 throw BESDapError(prolog +
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
156 BESDEBUG(MODULE, prolog <<
"Caught BESError. Message " << e.get_verbose_message() << endl);
159 catch (
const std::exception &e) {
160 throw BESInternalError(prolog +
"Failed to read data! Caught std::exception. Message; " +
string(e.what()), __FILE__, __LINE__);
163 throw BESInternalError(prolog +
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
165 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf. bytes_sent: " << bytes_sent<<endl);
187 BESDEBUG(MODULE, prolog <<
"BEGIN" << endl);
188 uint64_t bytes_sent = 0;
193 auto dmr = bdmr->get_dmr();
195 string base_name = dmr->filename().substr(dmr->filename().find_last_of(
"/\\") + 1);
199 string temp_file_name = temp_file.
create(FONcRequestHandler::temp_dir,
"dap4_nc_"+base_name);
201 BESDEBUG(MODULE, prolog <<
"Building response file " << temp_file_name << endl);
210 ostream &strm = dhi.get_output_stream();
214 msg << prolog <<
"Using ostream: " << (
void *) &strm << endl;
215 BESDEBUG(MODULE, msg.str());
216 INFO_LOG( msg.str());
219 if (!strm)
throw BESInternalError(
"Output stream is not set, can not return as", __FILE__, __LINE__);
225 BESDEBUG(MODULE, prolog <<
"Transmitting temp file " << temp_file_name << endl);
231 catch (
const Error &e) {
232 throw BESDapError(prolog +
"Failed to read data: " + e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
235 BESDEBUG(MODULE, prolog <<
"Caught BESError. Message " << e.get_verbose_message() << endl);
238 catch (
const std::exception &e) {
239 throw BESInternalError(prolog +
"Failed to read data! Caught std::exception. Message: " +
string(e.what()), __FILE__, __LINE__);
242 throw BESInternalError(prolog +
"Failed to get read data: Unknown exception caught", __FILE__, __LINE__);
245 BESDEBUG(MODULE, prolog <<
"END Transmitted as netcdf. bytes_sent: " << bytes_sent << endl);
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Base exception class for the BES with basic string message.
exception thrown if internal error encountered
exception thrown if an internal error is found and is fatal to the BES
Abstract base class representing a specific set of information in response to a request to the BES.
static void conditional_timeout_cancel()
Checks if the timeout alarm should be canceled based on the value of the BES key BES....
static uint64_t file_to_stream(const std::string &file_name, std::ostream &o_strm, uint64_t read_start_position=0)
Copies the contents of the file identified by file_name to the stream o_strm.
static void send_dap4_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
static void send_dap2_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a netcdf file.
FONcTransmitter()
Construct the FONcTransmitter, adding it with name netcdf to be able to transmit a data response.
static RequestServiceTimer * TheTimer()
Return a pointer to a singleton timer instance. If an instance does not exist it will create and init...
void throw_if_timeout_expired(const std::string &message, const std::string &file, const int line)
Checks the RequestServiceTimer to determine if the time spent servicing the request at this point has...
Get a new temporary file.
std::string create(const std::string &dir_name="/tmp/hyrax_tmp", const std::string &path_template="opendap")
Create a new temporary file.