31 #ifdef HAVE_UUID_UUID_H
32 #include <uuid/uuid.h>
33 #elif defined(HAVE_UUID_H)
36 #error "Could not find UUID library header"
57 #define CLEAR_LOCAL_DATA
58 #undef USE_LOCAL_TIMEOUT_SCHEME
62 #include <Structure.h>
63 #include <ConstraintEvaluator.h>
64 #include <DDXParserSAX2.h>
65 #include <Ancillary.h>
66 #include <XDRStreamMarshaller.h>
67 #include <XDRFileUnMarshaller.h>
71 #include <XMLWriter.h>
72 #include <D4AsyncUtil.h>
73 #include <D4StreamMarshaller.h>
74 #include <chunked_ostream.h>
75 #include <chunked_istream.h>
76 #include <D4ConstraintEvaluator.h>
77 #include <D4FunctionEvaluator.h>
78 #include <D4BaseTypeFactory.h>
80 #include <ServerFunctionsList.h>
82 #include <mime_util.h>
85 #if USE_LOCAL_TIMEOUT_SCHEME
87 #include <SignalHandler.h>
88 #include <EventHandler.h>
89 #include <AlarmHandler.h>
93 #include "TheBESKeys.h"
94 #include "BESDapResponseBuilder.h"
95 #include "BESContextManager.h"
96 #include "BESDapFunctionResponseCache.h"
97 #include "BESStoredDapResultCache.h"
99 #include "BESResponseObject.h"
100 #include "BESDDSResponse.h"
101 #include "BESDataDDSResponse.h"
102 #include "BESDataHandlerInterface.h"
103 #include "BESInternalFatalError.h"
104 #include "BESDataNames.h"
106 #include "BESRequestHandler.h"
107 #include "BESRequestHandlerList.h"
108 #include "BESNotFoundError.h"
111 #include "BESDebug.h"
112 #include "BESStopWatch.h"
113 #include "DapFunctionUtils.h"
118 const string CRLF =
"\r\n";
119 const string BES_KEY_TIMEOUT_CANCEL =
"BES.CancelTimeoutOnSend";
128 string cancel_timeout_on_send =
"";
130 if (found && !cancel_timeout_on_send.empty()) {
132 downcase(cancel_timeout_on_send);
133 if (cancel_timeout_on_send ==
"yes" || cancel_timeout_on_send ==
"true")
134 d_cancel_timeout_on_send =
true;
138 BESDapResponseBuilder::~BESDapResponseBuilder()
140 #if USE_LOCAL_TIMEOUT_SCHEME
144 delete dynamic_cast<AlarmHandler*
>(SignalHandler::instance()->remove_handler(SIGALRM));
171 d_dap2ce = www2id(_ce,
"%",
"%20");
194 d_dap4ce = www2id(_ce,
"%",
"%20");
202 return d_dap4function;
218 d_dap4function = www2id(_func,
"%",
"%20");
221 std::string BESDapResponseBuilder::get_store_result()
const
223 return d_store_result;
226 void BESDapResponseBuilder::set_store_result(std::string _sr)
228 d_store_result = _sr;
229 BESDEBUG(
"dap",
"BESDapResponseBuilder::set_store_result() - store_result: " << _sr << endl);
232 std::string BESDapResponseBuilder::get_async_accepted()
const
234 return d_async_accepted;
237 void BESDapResponseBuilder::set_async_accepted(std::string _aa)
239 d_async_accepted = _aa;
240 BESDEBUG(
"dap",
"BESDapResponseBuilder::set_async_accepted() - async_accepted: " << _aa << endl);
268 d_dataset = www2id(ds,
"%",
"%20");
296 #if USE_LOCAL_TIMEOUT_SCHEME
311 #if USE_LOCAL_TIMEOUT_SCHEME
334 if (d_cancel_timeout_on_send)
348 #if USE_LOCAL_TIMEOUT_SCHEME
350 SignalHandler *sh = SignalHandler::instance();
351 EventHandler *old_eh = sh->register_handler(SIGALRM,
new AlarmHandler());
365 #if USE_LOCAL_TIMEOUT_SCHEME
368 SignalHandler *sh = SignalHandler::instance();
369 EventHandler *old_eh = sh->register_handler(SIGALRM,
new AlarmHandler());
391 static string::size_type find_closing_paren(
const string &ce, string::size_type pos)
398 pos = ce.find_first_of(
"()", pos + 1);
399 if (pos == string::npos)
400 throw Error(malformed_expr,
"Expected to find a matching closing parenthesis in " + ce);
420 BESDEBUG(
"dap",
"BESDapResponseBuilder::split_ce() - source expression: " << expr << endl);
428 string btp_function_ce =
"";
429 string::size_type pos = 0;
433 string::size_type first_paren = ce.find(
"(", pos);
434 string::size_type closing_paren = string::npos;
435 if (first_paren != string::npos) closing_paren = find_closing_paren(ce, first_paren);
437 while (first_paren != string::npos && closing_paren != string::npos) {
439 string name = ce.substr(pos, first_paren - pos);
443 if (eval.find_function(name, &f)) {
445 if (!btp_function_ce.empty()) btp_function_ce +=
",";
446 btp_function_ce += ce.substr(pos, closing_paren + 1 - pos);
447 ce.erase(pos, closing_paren + 1 - pos);
448 if (ce[pos] ==
',') ce.erase(pos, 1);
451 pos = closing_paren + 1;
453 if (pos < ce.length() && ce.at(pos) ==
',') ++pos;
456 first_paren = ce.find(
"(", pos);
457 closing_paren = ce.find(
")", pos);
461 d_btp_func_ce = btp_function_ce;
463 BESDEBUG(
"dap",
"BESDapResponseBuilder::split_ce() - Modified constraint: " << d_dap2ce << endl);
464 BESDEBUG(
"dap",
"BESDapResponseBuilder::split_ce() - BTP Function part: " << btp_function_ce << endl);
465 BESDEBUG(
"dap",
"BESDapResponseBuilder::split_ce() - END" << endl);
475 throw_if_dap2_response_too_big(DDS *dds)
477 if (dds->get_response_limit() != 0 && ((dds->get_request_size(
true)) > dds->get_response_limit())) {
478 string msg =
"The Request for " + long_to_string(dds->get_request_size(
true) / 1024)
479 +
"KB is too large; requests on this server are limited to "
480 + long_to_string(dds->get_response_limit() /1024) +
"KB.";
499 void BESDapResponseBuilder::send_das(ostream &out, DAS &das,
bool with_mime_headers)
const
501 if (with_mime_headers) set_mime_text(out, dods_das, x_plain, last_modified_time(d_dataset),
"2.0");
525 void BESDapResponseBuilder::send_das(ostream &out, DDS **dds, ConstraintEvaluator &eval,
bool constrained,
526 bool with_mime_headers)
528 #if USE_LOCAL_TIMEOUT_SCHEME
530 establish_timeout(out);
531 dds.set_timeout(d_timeout);
534 if (with_mime_headers) set_mime_text(out, dods_das, x_plain, last_modified_time(d_dataset),
"2.0");
536 conditional_timeout_cancel();
538 (*dds)->print_das(out);
549 if (!d_btp_func_ce.empty()) {
550 ConstraintEvaluator func_eval;
554 if (responseCache && responseCache->can_be_cached(*dds, get_btp_func_ce())) {
558 func_eval.parse_constraint(get_btp_func_ce(), **dds);
559 fdds = func_eval.eval_function_clauses(**dds);
562 delete *dds; *dds = 0;
565 if (with_mime_headers)
566 set_mime_text(out, dods_das, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
568 conditional_timeout_cancel();
570 (*dds)->print_das(out);
573 eval.parse_constraint(d_dap2ce, **dds);
575 if (with_mime_headers)
576 set_mime_text(out, dods_das, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
578 conditional_timeout_cancel();
580 (*dds)->print_das(out);
606 bool with_mime_headers)
609 if (with_mime_headers)
610 set_mime_text(out, dods_dds, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
612 conditional_timeout_cancel();
619 #if USE_LOCAL_TIMEOUT_SCHEME
621 establish_timeout(out);
622 dds.set_timeout(d_timeout);
631 if (!d_btp_func_ce.empty()) {
632 ConstraintEvaluator func_eval;
637 if (responseCache && responseCache->can_be_cached(*dds, get_btp_func_ce())) {
641 func_eval.parse_constraint(get_btp_func_ce(), **dds);
642 fdds = func_eval.eval_function_clauses(**dds);
645 delete *dds; *dds = 0;
653 (*dds)->mark_all(
false);
665 promote_function_output_structures(*dds);
667 eval.parse_constraint(d_dap2ce, **dds);
669 if (with_mime_headers)
670 set_mime_text(out, dods_dds, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
673 conditional_timeout_cancel();
675 (*dds)->print_constrained(out);
678 eval.parse_constraint(d_dap2ce, **dds);
680 if (with_mime_headers)
681 set_mime_text(out, dods_dds, x_plain, last_modified_time(d_dataset),(*dds)->get_dap_version());
683 conditional_timeout_cancel();
685 (*dds)->print_constrained(out);
691 #ifdef DAP2_STORED_RESULTS
706 bool BESDapResponseBuilder::store_dap2_result(ostream &out, DDS &dds, ConstraintEvaluator &eval)
708 if (get_store_result().empty())
return false;
710 string serviceUrl = get_store_result();
721 string *stylesheet_ref = 0, ss_ref_value;
723 if (found && ss_ref_value.length() > 0) {
724 stylesheet_ref = &ss_ref_value;
728 if (resultCache == NULL) {
735 string msg =
"The Stored Result request cannot be serviced. ";
736 msg +=
"Unable to acquire StoredResultCache instance. ";
737 msg +=
"This is most likely because the StoredResultCache is not (correctly) configured.";
739 BESDEBUG(
"dap",
"[WARNING] " << msg << endl);
741 d4au.writeD4AsyncResponseRejected(xmlWrtr, UNAVAILABLE, msg, stylesheet_ref);
742 out << xmlWrtr.get_doc();
745 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap2_result() - Sent AsyncRequestRejected" << endl);
747 else if (get_async_accepted().length() != 0) {
752 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap2_result() - serviceUrl="<< serviceUrl << endl);
755 string storedResultId =
"";
756 storedResultId = resultCache->store_dap2_result(dds, get_ce(),
this, &eval);
759 "BESDapResponseBuilder::store_dap2_result() - storedResultId='"<< storedResultId <<
"'" << endl);
762 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap2_result() - targetURL='"<< targetURL <<
"'" << endl);
765 d4au.writeD4AsyncAccepted(xmlWrtr, 0, 0, targetURL, stylesheet_ref);
766 out << xmlWrtr.get_doc();
769 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap2_result() - sent DAP4 AsyncAccepted response" << endl);
776 d4au.writeD4AsyncRequired(xmlWrtr, 0, 0, stylesheet_ref);
777 out << xmlWrtr.get_doc();
780 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap2_result() - sent DAP4 AsyncRequired response" << endl);
794 if (BESISDEBUG(TIMING_LOG)) sw.
start(
"BESDapResponseBuilder::serialize_dap2_data_dds",
"");
796 BESDEBUG(
"dap",
"BESDapResponseBuilder::serialize_dap2_data_dds() - BEGIN" << endl);
798 (*dds)->print_constrained(out);
802 XDRStreamMarshaller m(out);
806 conditional_timeout_cancel();
809 for (DDS::Vars_iter i = (*dds)->var_begin(); i != (*dds)->var_end(); i++) {
810 if ((*i)->send_p()) {
811 (*i)->serialize(eval, **dds, m, ce_eval);
812 #ifdef CLEAR_LOCAL_DATA
813 (*i)->clear_local_data();
818 BESDEBUG(
"dap",
"BESDapResponseBuilder::serialize_dap2_data_dds() - END" << endl);
821 #ifdef DAP2_STORED_RESULTS
830 void BESDapResponseBuilder::serialize_dap2_data_ddx(ostream &out, DDS **dds, ConstraintEvaluator &eval,
831 const string &boundary,
const string &start,
bool ce_eval)
833 BESDEBUG(
"dap", __PRETTY_FUNCTION__ <<
" BEGIN" << endl);
836 libdap::set_mime_ddx_boundary(out, boundary, start, dods_ddx, x_plain);
842 uuid_unparse(uu, &uuid[0]);
844 if (getdomainname(domain, 255) != 0 || strlen(domain) == 0) strncpy(domain,
"opendap.org", 255);
846 string cid = string(&uuid[0]) +
"@" + string(&domain[0]);
850 (*dds)->print_xml_writer(out,
true, cid);
853 set_mime_data_boundary(out, boundary, cid, dods_data_ddx , x_plain);
855 XDRStreamMarshaller m(out);
857 conditional_timeout_cancel();
861 for (DDS::Vars_iter i = (*dds)->var_begin(); i != (*dds)->var_end(); i++) {
862 if ((*i)->send_p()) {
863 (*i)->serialize(eval, **dds, m, ce_eval);
864 #ifdef CLEAR_LOCAL_DATA
865 (*i)->clear_local_data();
870 BESDEBUG(
"dap", __PRETTY_FUNCTION__ <<
" END" << endl);
892 #if USE_LOCAL_TIMEOUT_SCHEME
913 BESDEBUG(
"dap",
"BESDapResponseBuilder::process_dap2_dds() - BEGIN"<< endl);
922 set_dataset_name(dds->filename());
923 set_ce(dhi.
data[POST_CONSTRAINT]);
924 set_async_accepted(dhi.
data[ASYNC]);
925 set_store_result(dhi.
data[STORE_RESULT]);
927 ConstraintEvaluator &eval = bdds->
get_ce();
935 if (!d_btp_func_ce.empty()) {
938 ConstraintEvaluator func_eval;
940 if (responseCache && responseCache->can_be_cached(dds, get_btp_func_ce())) {
944 func_eval.parse_constraint(get_btp_func_ce(), *dds);
945 fdds = func_eval.eval_function_clauses(*dds);
952 dds->mark_all(
false);
954 promote_function_output_structures(dds);
957 eval.parse_constraint(d_dap2ce, *dds);
982 BESDEBUG(
"dap",
"BESDapResponseBuilder::intern_dap2_data() - BEGIN"<< endl);
987 if (!bdds)
throw BESInternalFatalError(
"Expected a BESDataDDSResponse instance", __FILE__, __LINE__);
989 DDS *dds = bdds->get_dds();
991 set_dataset_name(dds->filename());
992 set_ce(dhi.
data[POST_CONSTRAINT]);
993 set_async_accepted(dhi.
data[ASYNC]);
994 set_store_result(dhi.
data[STORE_RESULT]);
999 if(bdds->get_ia_flag() ==
false) {
1001 besRH->add_attributes(dhi);
1004 ConstraintEvaluator &eval = bdds->get_ce();
1012 if (!get_btp_func_ce().empty()) {
1014 "BESDapResponseBuilder::intern_dap2_data() - Found function(s) in CE: " << get_btp_func_ce() << endl);
1018 ConstraintEvaluator func_eval;
1020 if (responseCache && responseCache->can_be_cached(dds, get_btp_func_ce())) {
1024 func_eval.parse_constraint(get_btp_func_ce(), *dds);
1025 fdds = func_eval.eval_function_clauses(*dds);
1037 dds->mark_all(
false);
1048 promote_function_output_structures(dds);
1052 eval.parse_constraint(get_ce(), *dds);
1054 dds->tag_nested_sequences();
1056 throw_if_dap2_response_too_big(dds);
1060 for (DDS::Vars_iter i = dds->var_begin(), e = dds->var_end(); i != e; ++i) {
1061 if ((*i)->send_p()) {
1062 (*i)->intern_data(eval, *dds);
1066 BESDEBUG(
"dap",
"BESDapResponseBuilder::intern_dap2_data() - END"<< endl);
1084 void BESDapResponseBuilder::send_dap2_data(ostream &data_stream, DDS **dds, ConstraintEvaluator &eval,
1085 bool with_mime_headers)
1087 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - BEGIN"<< endl);
1089 #if USE_LOCAL_TIMEOUT_SCHEME
1091 establish_timeout(data_stream);
1092 dds.set_timeout(d_timeout);
1101 if (!get_btp_func_ce().empty()) {
1103 "BESDapResponseBuilder::send_dap2_data() - Found function(s) in CE: " << get_btp_func_ce() << endl);
1107 ConstraintEvaluator func_eval;
1109 if (response_cache && response_cache->can_be_cached(*dds, get_btp_func_ce())) {
1113 func_eval.parse_constraint(get_btp_func_ce(), **dds);
1114 fdds = func_eval.eval_function_clauses(**dds);
1117 delete *dds; *dds = 0;
1120 (*dds)->mark_all(
false);
1122 promote_function_output_structures(*dds);
1125 eval.parse_constraint(get_ce(), **dds);
1127 (*dds)->tag_nested_sequences();
1129 throw_if_dap2_response_too_big(*dds);
1131 if (with_mime_headers)
1132 set_mime_binary(data_stream, dods_data, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1134 #if STORE_DAP2_RESULT_FEATURE
1136 if (!store_dap2_result(data_stream, **dds, eval)) {
1137 serialize_dap2_data_dds(data_stream, dds, eval,
true );
1140 serialize_dap2_data_dds(data_stream, dds, eval,
true );
1145 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - Simple constraint" << endl);
1147 eval.parse_constraint(get_ce(), **dds);
1149 (*dds)->tag_nested_sequences();
1151 throw_if_dap2_response_too_big(*dds);
1153 if (with_mime_headers)
1154 set_mime_binary(data_stream, dods_data, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1156 #if STORE_DAP2_RESULT_FEATURE
1158 if (!store_dap2_result(data_stream, **dds, eval)) {
1159 serialize_dap2_data_dds(data_stream, dds, eval);
1162 serialize_dap2_data_dds(data_stream, dds, eval);
1166 data_stream << flush;
1168 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - END"<< endl);
1172 void BESDapResponseBuilder::send_dap2_data(
BESDataHandlerInterface &dhi, DDS **dds, ConstraintEvaluator &eval,
1173 bool with_mime_headers)
1175 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - BEGIN"<< endl);
1177 ostream & data_stream = dhi.get_output_stream();
1178 #if USE_LOCAL_TIMEOUT_SCHEME
1180 establish_timeout(data_stream);
1181 dds.set_timeout(d_timeout);
1190 if (!get_btp_func_ce().empty()) {
1192 "BESDapResponseBuilder::send_dap2_data() - Found function(s) in CE: " << get_btp_func_ce() << endl);
1202 if(bdds->get_ia_flag() ==
false) {
1204 besRH->add_attributes(dhi);
1209 ConstraintEvaluator func_eval;
1211 if (response_cache && response_cache->can_be_cached(*dds, get_btp_func_ce())) {
1215 func_eval.parse_constraint(get_btp_func_ce(), **dds);
1216 fdds = func_eval.eval_function_clauses(**dds);
1219 delete *dds; *dds = 0;
1222 (*dds)->mark_all(
false);
1224 promote_function_output_structures(*dds);
1227 eval.parse_constraint(get_ce(), **dds);
1229 (*dds)->tag_nested_sequences();
1231 throw_if_dap2_response_too_big(*dds);
1233 if (with_mime_headers)
1234 set_mime_binary(data_stream, dods_data, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1236 #if STORE_DAP2_RESULT_FEATURE
1238 if (!store_dap2_result(data_stream, **dds, eval)) {
1239 serialize_dap2_data_dds(data_stream, dds, eval,
true );
1242 serialize_dap2_data_dds(data_stream, dds, eval,
true );
1247 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - Simple constraint" << endl);
1249 eval.parse_constraint(get_ce(), **dds);
1251 (*dds)->tag_nested_sequences();
1253 throw_if_dap2_response_too_big(*dds);
1255 if (with_mime_headers)
1256 set_mime_binary(data_stream, dods_data, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1258 #if STORE_DAP2_RESULT_FEATURE
1260 if (!store_dap2_result(data_stream, **dds, eval)) {
1261 serialize_dap2_data_dds(data_stream, dds, eval);
1264 serialize_dap2_data_dds(data_stream, dds, eval);
1268 data_stream << flush;
1270 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dap2_data() - END"<< endl);
1288 if (d_dap2ce.empty()) {
1289 if (with_mime_headers)
1290 set_mime_text(out, dods_ddx, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1292 (*dds)->print_xml_writer(out,
false ,
"");
1298 #if USE_LOCAL_TIMEOUT_SCHEME
1300 establish_timeout(out);
1301 dds.set_timeout(d_timeout);
1310 if (!d_btp_func_ce.empty()) {
1313 ConstraintEvaluator func_eval;
1315 if (response_cache && response_cache->can_be_cached(*dds, get_btp_func_ce())) {
1319 func_eval.parse_constraint(get_btp_func_ce(), **dds);
1320 fdds = func_eval.eval_function_clauses(**dds);
1323 delete *dds; *dds = 0;
1326 (*dds)->mark_all(
false);
1328 promote_function_output_structures(*dds);
1330 eval.parse_constraint(d_dap2ce, **dds);
1332 if (with_mime_headers)
1333 set_mime_text(out, dods_ddx, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1335 conditional_timeout_cancel();
1337 (*dds)->print_xml_writer(out,
true,
"");
1340 eval.parse_constraint(d_dap2ce, **dds);
1342 if (with_mime_headers)
1343 set_mime_text(out, dods_ddx, x_plain, last_modified_time(d_dataset), (*dds)->get_dap_version());
1345 conditional_timeout_cancel();
1349 (*dds)->print_xml_writer(out,
true,
"");
1355 void BESDapResponseBuilder::send_dmr(ostream &out, DMR &dmr,
bool with_mime_headers)
1360 if (!d_dap4ce.empty()) {
1362 BESDEBUG(
"dap",
"BESDapResponseBuilder::send_dmr() - Parsing DAP4 constraint: '"<< d_dap4ce <<
"'"<< endl);
1364 D4ConstraintEvaluator parser(&dmr);
1365 bool parse_ok = parser.parse(d_dap4ce);
1366 if (!parse_ok)
throw Error(malformed_expr,
"Constraint Expression (" + d_dap4ce +
") failed to parse.");
1372 dmr.root()->set_send_p(
true);
1375 if (with_mime_headers) set_mime_text(out, dap4_dmr, x_plain, last_modified_time(d_dataset), dmr.dap_version());
1377 conditional_timeout_cancel();
1381 dmr.print_dap4(xml, !d_dap4ce.empty() );
1382 out << xml.get_doc() << flush;
1385 void BESDapResponseBuilder::send_dap4_data_using_ce(ostream &out, DMR &dmr,
bool with_mime_headers)
1387 if (!d_dap4ce.empty()) {
1388 D4ConstraintEvaluator parser(&dmr);
1389 bool parse_ok = parser.parse(d_dap4ce);
1390 if (!parse_ok)
throw Error(malformed_expr,
"Constraint Expression (" + d_dap4ce +
") failed to parse.");
1396 dmr.root()->set_send_p(
true);
1399 if (dmr.response_limit() != 0 && (dmr.request_size(
true) > dmr.response_limit())) {
1400 string msg =
"The Request for " + long_to_string(dmr.request_size(
true))
1401 +
"KB is too large; requests for this server are limited to " + long_to_string(dmr.response_limit())
1406 if (!store_dap4_result(out, dmr)) {
1407 serialize_dap4_data(out, dmr, with_mime_headers);
1411 void BESDapResponseBuilder::send_dap4_data(ostream &out, DMR &dmr,
bool with_mime_headers)
1416 if (!d_dap4function.empty()) {
1417 D4BaseTypeFactory d4_factory;
1418 DMR function_result(&d4_factory,
"function_results");
1422 if (!ServerFunctionsList::TheList())
1424 "The function expression could not be evaluated because there are no server functions defined on this server");
1426 D4FunctionEvaluator parser(&dmr, ServerFunctionsList::TheList());
1427 bool parse_ok = parser.parse(d_dap4function);
1428 if (!parse_ok)
throw Error(
"Function Expression (" + d_dap4function +
") failed to parse.");
1430 parser.eval(&function_result);
1434 send_dap4_data_using_ce(out, function_result, with_mime_headers);
1437 send_dap4_data_using_ce(out, dmr, with_mime_headers);
1446 BESDEBUG(
"dap",
"BESDapResponseBuilder::serialize_dap4_data() - BEGIN" << endl);
1448 if (with_mime_headers) set_mime_binary(out, dap4_data, x_plain, last_modified_time(d_dataset), dmr.dap_version());
1452 dmr.print_dap4(xml, !d_dap4ce.empty());
1457 chunked_ostream cos(out, max((
unsigned int) CHUNK_SIZE, xml.get_doc_size() + 2));
1459 conditional_timeout_cancel();
1462 cos << xml.get_doc() << CRLF << flush;
1465 D4StreamMarshaller m(cos);
1466 dmr.root()->serialize(m, dmr, !d_dap4ce.empty());
1467 #ifdef CLEAR_LOCAL_DATA
1468 dmr.root()->clear_local_data();
1472 BESDEBUG(
"dap",
"BESDapResponseBuilder::serialize_dap4_data() - END" << endl);
1491 if (get_store_result().length() != 0) {
1492 string serviceUrl = get_store_result();
1499 string *stylesheet_ref = 0, ss_ref_value;
1501 if (found && ss_ref_value.length() > 0) {
1502 stylesheet_ref = &ss_ref_value;
1506 if (resultCache == NULL) {
1513 string msg =
"The Stored Result request cannot be serviced. ";
1514 msg +=
"Unable to acquire StoredResultCache instance. ";
1515 msg +=
"This is most likely because the StoredResultCache is not (correctly) configured.";
1517 BESDEBUG(
"dap",
"[WARNING] " << msg << endl);
1518 d4au.writeD4AsyncResponseRejected(xmlWrtr, UNAVAILABLE, msg, stylesheet_ref);
1519 out << xmlWrtr.get_doc();
1521 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap4_result() - Sent AsyncRequestRejected" << endl);
1526 if (get_async_accepted().length() != 0) {
1531 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap4_result() - serviceUrl="<< serviceUrl << endl);
1533 string storedResultId =
"";
1537 "BESDapResponseBuilder::store_dap4_result() - storedResultId='"<< storedResultId <<
"'" << endl);
1540 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap4_result() - targetURL='"<< targetURL <<
"'" << endl);
1542 d4au.writeD4AsyncAccepted(xmlWrtr, 0, 0, targetURL, stylesheet_ref);
1543 out << xmlWrtr.get_doc();
1545 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap4_result() - sent AsyncAccepted" << endl);
1553 d4au.writeD4AsyncRequired(xmlWrtr, 0, 0, stylesheet_ref);
1554 out << xmlWrtr.get_doc();
1556 BESDEBUG(
"dap",
"BESDapResponseBuilder::store_dap4_result() - sent AsyncAccepted" << endl);