47#include "BESStreamResponseHandler.h"
48#include "BESForbiddenError.h"
49#include "BESNotFoundError.h"
50#include "BESInternalError.h"
51#include "BESContainer.h"
52#include "BESDataHandlerInterface.h"
54#include "RequestServiceTimer.h"
56#define BES_STREAM_BUFFER_SIZE 4096
59#define prolog std::string("BESStreamResponseHandler::").append(__func__).append("() - ")
73 d_response_object =
nullptr;
89 if (dhi.containers.size() != 1) {
90 throw BESInternalError(
"Unable to stream file: no container specified", __FILE__, __LINE__);
95 string filename = container->
access();
96 if (filename.empty()) {
97 throw BESInternalError(
"Unable to stream file: filename not specified", __FILE__, __LINE__);
101 os.open(filename.c_str(), ios::in);
104 string serr =
"Unable to stream file because it cannot be opened. file: '" + filename +
"' msg: ";
105 char *err = strerror(myerrno);
106 serr += err ? err:
"Unknown error";
111 if (myerrno == ENOENT || myerrno == ENOTDIR) {
119 std::streamsize nbytes;
120 char block[BES_STREAM_BUFFER_SIZE];
121 os.read(block,
sizeof block);
122 nbytes = os.gcount();
124 dhi.get_output_stream().write((
char*) block, nbytes);
125 os.read(block,
sizeof block);
126 nbytes = os.gcount();
153 strm << BESIndent::LMarg <<
"BESStreamResponseHandler::dump - (" << (
void *)
this <<
")" << endl;
156 BESIndent::UnIndent();
160BESStreamResponseHandler::BESStreamResponseBuilder(
const string &name)
A container is something that holds data. E.G., a netcdf file or a database entry.
virtual std::string access()=0
returns the true name of this container
Structure storing information used by the BES to handle the request.
void first_container()
set the container pointer to the first container in the containers list
BESContainer * container
pointer to current container in this interface
error thrown if the BES is not allowed to access the resource requested
exception thrown if internal error encountered
error thrown if the resource requested cannot be found
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
void execute(BESDataHandlerInterface &r) override
executes the command 'get file <filename>;' by streaming the specified file
void dump(std::ostream &strm) const override
dumps information about this object
void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &r) override
transmit the file, streaming it back to the client
static void conditional_timeout_cancel()
Checks if the timeout alarm should be canceled based on the value of the BES key BES....
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...