38 #include <sys/types.h>
47 #include <ConstraintEvaluator.h>
64 #define FO_JSON_TEMP_DIR "/tmp"
66 string FoDapJsonTransmitter::temp_dir;
84 if (FoDapJsonTransmitter::temp_dir.empty()) {
87 string key =
"FoJson.Tempdir";
89 if (!found || FoDapJsonTransmitter::temp_dir.empty()) {
92 string::size_type len = FoDapJsonTransmitter::temp_dir.length();
93 if (FoDapJsonTransmitter::temp_dir[len - 1] ==
'/') {
94 FoDapJsonTransmitter::temp_dir = FoDapJsonTransmitter::temp_dir.substr(0, len - 1);
120 DataDDS *dds = bdds->
get_dds();
122 throw BESInternalError(
"No DataDDS has been created for transmit", __FILE__, __LINE__);
124 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_data - parsing the constraint" << endl);
126 ConstraintEvaluator &eval = bdds->
get_ce();
130 throw BESInternalError(
"Output stream is not set, can not return as JSON", __FILE__, __LINE__);
135 eval.parse_constraint(ce, *dds);
138 throw BESInternalError(
"Failed to parse the constraint expression: " + e.get_error_message(), __FILE__, __LINE__);
141 throw BESInternalError(
"Failed to parse the constraint expression: Unknown exception caught", __FILE__, __LINE__);
145 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_data - reading data into DataDDS" << endl);
149 if (eval.function_clauses()) {
150 BESDEBUG(
"fojson",
"processing a functional constraint clause(s)." << endl);
151 DataDDS *tmp_dds = eval.eval_function_clauses(*dds);
159 for (DDS::Vars_iter i = dds->var_begin(); i != dds->var_end(); i++) {
160 if ((*i)->send_p()) {
161 (*i)->intern_data(eval, *dds);
167 throw BESInternalError(
"Failed to read data: " + e.get_error_message(), __FILE__, __LINE__);
170 throw BESInternalError(
"Failed to read data: Unknown exception caught", __FILE__, __LINE__);
176 ft.transform(
true );
182 throw BESInternalError(
"fileout_json: Failed to transform to JSON, unknown error", __FILE__, __LINE__);
185 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_data - done transmitting JSON" << endl);
211 throw BESInternalError(
"No DDS has been created for transmit", __FILE__, __LINE__);
213 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_metadata - parsing the constraint" << endl);
215 ConstraintEvaluator &eval = bdds->
get_ce();
219 throw BESInternalError(
"Output stream is not set, can not return as JSON", __FILE__, __LINE__);
224 eval.parse_constraint(ce, *dds);
227 throw BESInternalError(
"Failed to parse the constraint expression: " + e.get_error_message(), __FILE__, __LINE__);
230 throw BESInternalError(
"Failed to parse the constraint expression: Unknown exception caught", __FILE__, __LINE__);
234 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_data - reading data into DataDDS" << endl);
238 if (eval.function_clauses()) {
239 BESDEBUG(
"fojson",
"processing a functional constraint clause(s)." << endl);
240 DDS *tmp_dds = eval.eval_function_clauses(*dds);
247 for (DDS::Vars_iter i = dds->var_begin(); i != dds->var_end(); i++) {
248 if ((*i)->send_p()) {
249 (*i)->intern_data(eval, *dds);
255 throw BESInternalError(
"Failed to read data: " + e.get_error_message(), __FILE__, __LINE__);
258 throw BESInternalError(
"Failed to read data: Unknown exception caught", __FILE__, __LINE__);
264 ft.transform(
false );
269 throw BESInternalError(
"FoDapJsonTransmitter: Failed to transform to JSON, unknown error", __FILE__, __LINE__);
272 BESDEBUG(
"fojson",
"FoDapJsonTransmitter::send_data - done transmitting JSON" << endl);
284 void FoDapJsonTransmitter::return_temp_stream(
const string &filename, ostream &strm)
288 os.open(filename.c_str(), ios::binary | ios::in);
290 string err =
"Can not connect to file " + filename;
297 os.read(block,
sizeof block);
298 nbytes = os.gcount();
300 strm.write(block, nbytes);
307 string err = (string)
"0XAAE234F: failed to stream. Internal server "
308 +
"error, got zero count on stream buffer." + filename;
313 os.read(block,
sizeof block);
314 nbytes = os.gcount();
315 strm.write(block, nbytes);
void set_dds(DataDDS *ddsIn)
Set the response object's DDS.
exception thrown if inernal error encountered
ConstraintEvaluator & get_ce()
ostream & get_output_stream()
Represents an OPeNDAP DDS DAP2 data object within the BES.
virtual bool add_method(string method_name, p_transmitter trans_method)
static void send_data(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a JSON file.
static class NCMLUtil overview
Abstract exception class for the BES with basic string message.
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
ConstraintEvaluator & get_ce()
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
FoDapJsonTransmitter()
Construct the FoW10nJsonTransmitter.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static BESKeys * TheKeys()
Abstract base class representing a specific set of information in response to a request to the BES...
static void send_metadata(BESResponseObject *obj, BESDataHandlerInterface &dhi)
The static method registered to transmit OPeNDAP data objects as a JSON file.