libdap++  Updated for version 3.11.7
libdap::ResponseBuilder Class Reference

Build responses for Hyrax server modules/handlers. More...

#include <ResponseBuilder.h>

Collaboration diagram for libdap::ResponseBuilder:
Collaboration graph

Public Member Functions

virtual void cache_data_ddx (const string &cache_file_name, DDS &dds)
 Cache data. More...
 
virtual void dataset_constraint (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool ce_eval=true) const
 
virtual void dataset_constraint_ddx (ostream &out, DDS &dds, ConstraintEvaluator &eval, const string &boundary, const string &start, bool ce_eval=true) const
 
virtual void establish_timeout (ostream &stream) const
 
virtual string get_btp_func_ce () const
 
virtual DDSget_cached_data_ddx (const string &cache_file_name, BaseTypeFactory *factory)
 
virtual string get_ce () const
 Get the constraint expression. More...
 
virtual string get_dataset_name () const
 Get the dataset name. More...
 
int get_timeout () const
 
virtual bool is_valid (const string &cache_file_name)
 
virtual DDSread_cached_dataset (DDS &dds, ConstraintEvaluator &eval, string &cache_token)
 
virtual void read_data_from_cache (FILE *data, DDS *fdds)
 
 ResponseBuilder ()
 
virtual void send_das (ostream &out, DAS &das, bool with_mime_headers=true)
 Transmit a DAS. More...
 
virtual void send_das (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool constrained=false, bool with_mime_headers=true)
 Transmit a DAS using the DDS. More...
 
virtual void send_data (ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
 Transmit data. More...
 
virtual void send_data_ddx (ostream &data_stream, DDS &dds, ConstraintEvaluator &eval, const string &start, const string &boundary, bool with_mime_headers=true)
 Transmit data. More...
 
virtual void send_dds (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool constrained=false, bool with_mime_headers=true)
 Transmit a DDS. More...
 
virtual void send_ddx (ostream &out, DDS &dds, ConstraintEvaluator &eval, bool with_mime_headers=true)
 
virtual void set_btp_func_ce (string _ce)
 
virtual void set_ce (string _ce)
 
virtual void set_dataset_name (const string _dataset)
 
void set_mime_binary (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_mime_data_boundary (ostream &out, const string &boundary, const string &cid, ObjectType type=unknown_type, EncodingType enc=x_plain) const
 
void set_mime_ddx_boundary (ostream &out, const string &boundary, const string &start, ObjectType type=unknown_type, EncodingType enc=x_plain) const
 
void set_mime_error (ostream &out, int code=404, const string &reason="Dataset not found", const string &protocol="") const
 
void set_mime_html (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_mime_multipart (ostream &out, const string &boundary, const string &start, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_mime_text (ostream &out, ObjectType type=unknown_type, EncodingType enc=x_plain, const time_t last_modified=0, const string &protocol="") const
 
void set_timeout (int timeout=0)
 
virtual void split_ce (ConstraintEvaluator &eval, const string &expr="")
 
virtual ~ResponseBuilder ()
 

Protected Member Functions

void initialize ()
 

Protected Attributes

string d_btp_func_ce
 Constraint expression. More...
 
DAPCache3d_cache
 Version string for the library's default protocol version. More...
 
string d_ce
 Name of the dataset/database. More...
 
string d_dataset
 
string d_default_protocol
 Response timeout after N seconds. More...
 
int d_timeout
 The BTP functions, extracted from the CE. More...
 

Friends

class ResponseBuilderTest
 

Detailed Description

Author
jhrg 1/28/2011

Definition at line 62 of file ResponseBuilder.h.

Constructor & Destructor Documentation

libdap::ResponseBuilder::ResponseBuilder ( )
inline

Make an empty instance. Use the set_*() methods to load with needed values. You must call at least set_dataset_name() or be requesting version information.

Definition at line 87 of file ResponseBuilder.h.

References initialize().

Here is the call graph for this function:

libdap::ResponseBuilder::~ResponseBuilder ( )
virtual

Definition at line 89 of file ResponseBuilder.cc.

Member Function Documentation

void libdap::ResponseBuilder::cache_data_ddx ( const string &  cache_file_name,
DDS dds 
)
virtual

Write a DDS to an output stream. This method is intended to be used to write to a cache so that interim results can be reused w/o needing to be recomputed. I chose the 'data ddx' response because it combines the syntax and semantic metadata along with the data and all three DAP2 requests can be satisfied using it.

Parameters
cache_file_namePut the data here
ddsA DDS object containing the data to be sent.
Returns
void

Definition at line 1149 of file ResponseBuilder.cc.

References CRLF, libdap::dap4_data_ddx, DBG, libdap::last_modified_time(), libdap::DDS::set_dap_version(), libdap::set_mime_multipart(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::dataset_constraint ( ostream &  out,
DDS dds,
ConstraintEvaluator eval,
bool  ce_eval = true 
) const
virtual
void libdap::ResponseBuilder::dataset_constraint_ddx ( ostream &  out,
DDS dds,
ConstraintEvaluator eval,
const string &  boundary,
const string &  start,
bool  ce_eval = true 
) const
virtual
void libdap::ResponseBuilder::establish_timeout ( ostream &  stream) const
virtual

Use values of this instance to establish a timeout alarm for the server. If the timeout value is zero, do nothing.

Todo:
When the alarm handler is called, two CRLF pairs are dumped to the stream and then an Error object is sent. No attempt is made to write the 'correct' MIME headers for an Error object. Instead, a savvy client will know that when an exception is thrown during a deserialize operation, it should scan ahead in the input stream for an Error object. Add this, or a sensible variant once libdap++ supports reliable error delivery. Dumb clients will never get the Error object...

Definition at line 185 of file ResponseBuilder.cc.

References libdap::SignalHandler::register_handler().

Here is the call graph for this function:

virtual string libdap::ResponseBuilder::get_btp_func_ce ( ) const
inlinevirtual

Definition at line 103 of file ResponseBuilder.h.

References d_btp_func_ce.

DDS * libdap::ResponseBuilder::get_cached_data_ddx ( const string &  cache_file_name,
BaseTypeFactory factory 
)
virtual
string libdap::ResponseBuilder::get_ce ( ) const
virtual

Return the entire constraint expression in a string. This includes both the projection and selection clauses, but not the question mark.

Returns
A string object that contains the constraint expression.

Definition at line 138 of file ResponseBuilder.cc.

string libdap::ResponseBuilder::get_dataset_name ( ) const
virtual

The ``dataset name'' is the filename or other string that the filter program will use to access the data. In some cases this will indicate a disk file containing the data. In others, it may represent a database query or some other exotic data access method.

Returns
A string object that contains the name of the dataset.

Definition at line 154 of file ResponseBuilder.cc.

int libdap::ResponseBuilder::get_timeout ( ) const

Get the server's timeout value.

Definition at line 171 of file ResponseBuilder.cc.

void libdap::ResponseBuilder::initialize ( )
protected

Called when initializing a ResponseBuilder that's not going to be passed a command line arguments.

Definition at line 94 of file ResponseBuilder.cc.

References DAP_PROTOCOL_VERSION, DBG, libdap::dir_exists(), FUNCTION_CACHE, FUNCTION_CACHE_PREFIX, FUNCTION_CACHE_SIZE, and DAPCache3::get_instance().

Referenced by ResponseBuilder().

Here is the call graph for this function:

bool libdap::ResponseBuilder::is_valid ( const string &  cache_file_name)
virtual

Is the item named by cache_entry_name valid? This code tests that the cache entry is non-zero in size (returns false if that is the case, although that might not be correct) and that the dataset associated with this ResponseBulder instance is at least as old as the cached entry.

Parameters
cache_file_nameFile name of the cached entry
Returns
True if the thing is valid, false otherwise.

Definition at line 292 of file ResponseBuilder.cc.

DDS * libdap::ResponseBuilder::read_cached_dataset ( DDS dds,
ConstraintEvaluator eval,
string &  cache_token 
)
virtual

Get the cache DDS pointer - which will contain both attributes and data values.

Note
Do not call this when d_cache is null or when d_btp_func_ce is empty!
Parameters
ddsThe DDS of the dataset referenced by the URL
Returns
The cached DDS that resulted from calling the server functions in the original CE.
Parameters
cache_tokenA value-result parameter that contains teh name of the file in the cache. Used to release the lock on the cached file.

Definition at line 340 of file ResponseBuilder.cc.

References DBG, libdap::ConstraintEvaluator::eval_function_clauses(), and libdap::ConstraintEvaluator::parse_constraint().

Here is the call graph for this function:

void libdap::ResponseBuilder::read_data_from_cache ( FILE *  data,
DDS fdds 
)
virtual

Read the data from the saved response document.

Note
this method is made of code copied from Connect (process_data(0) but this copy assumes ot is reading a DDX with data written using the code in ResponseBuilder::cache_data_ddx().
I put this code here instead of using what was in Connect because I did not want all of the handlers to be modified to inlcude libdapclient and thus libcurl and libuuid.
Todo:
Maybe move this code into libdap as a general 'get it from disk' method. Use that code in libdapclient.
Parameters
dataThe input stream fdds Load this DDS object with the variables, attributes and data values from the cached DDS.

Definition at line 1198 of file ResponseBuilder.cc.

References libdap::cid_to_header_value(), libdap::dap4_data, libdap::dap4_ddx, DBG, libdap::DDS::get_factory(), libdap::get_next_mime_header(), libdap::parse_mime_header(), libdap::read_multipart_boundary(), libdap::read_multipart_headers(), libdap::DDS::var_begin(), and libdap::DDS::var_end().

Here is the call graph for this function:

void libdap::ResponseBuilder::send_das ( ostream &  out,
DAS das,
bool  with_mime_headers = true 
)
virtual

This function formats and prints an ASCII representation of a DAS on stdout. This has the effect of sending the DAS object back to the client program.

Parameters
outThe output stream to which the DAS is to be sent.
dasThe DAS object to be sent.
with_mime_headersIf true (the default) send MIME headers.
Returns
void
See Also
DAS

Definition at line 422 of file ResponseBuilder.cc.

References libdap::dods_das, libdap::last_modified_time(), libdap::DAS::print(), libdap::set_mime_text(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::send_das ( ostream &  out,
DDS dds,
ConstraintEvaluator eval,
bool  constrained = false,
bool  with_mime_headers = true 
)
virtual

This function formats and prints an ASCII representation of a DAS on stdout. This has the effect of sending the DAS object back to the client program. This version of send_das() uses the DDS object (and assumes it's populated with attributes). If the request contains a CE, that's fine and if the request has been cached, it will read the DDS from the cache.

Todo:
Test me! Modify the BES to use this code!!
Parameters
outThe output stream to which the DAS is to be sent.
dasThe DAS object to be sent.
with_mime_headersIf true (the default) send MIME headers.
Returns
void
See Also
DAS

Definition at line 447 of file ResponseBuilder.cc.

References DBG, libdap::dods_das, libdap::ConstraintEvaluator::eval_function_clauses(), libdap::DDS::get_dap_version(), libdap::last_modified_time(), libdap::ConstraintEvaluator::parse_constraint(), libdap::DDS::print_das(), libdap::set_mime_text(), libdap::DDS::set_timeout(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::send_data ( ostream &  data_stream,
DDS dds,
ConstraintEvaluator eval,
bool  with_mime_headers = true 
)
virtual

Send the data in the DDS object back to the client program. The data is encoded using a Marshaller, and enclosed in a MIME document which is all sent to data_stream. If this is being called from a CGI, data_stream is probably stdout and writing to it has the effect of sending the response back to the client.

Parameters
ddsA DDS object containing the data to be sent.
evalA reference to the ConstraintEvaluator to use.
data_streamWrite the response to this stream.
anc_locationA directory to search for ancillary files (in addition to the CWD). This is used in a call to get_data_last_modified_time().
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.
Returns
void

Definition at line 812 of file ResponseBuilder.cc.

References DBG, libdap::dods_data, libdap::ConstraintEvaluator::eval_function_clauses(), libdap::DDS::filename(), libdap::ConstraintEvaluator::function_clauses(), libdap::DDS::get_dap_version(), libdap::DDS::get_request_size(), libdap::DDS::get_response_limit(), libdap::Response::get_stream(), libdap::last_modified_time(), libdap::long_to_string(), libdap::DDS::mark_all(), libdap::name_path(), libdap::ConstraintEvaluator::parse_constraint(), libdap::DDS::print_constrained(), libdap::Connect::read_data(), libdap::DDS::set_dap_version(), libdap::DDS::set_dataset_name(), libdap::DDS::set_factory(), libdap::set_mime_binary(), libdap::BaseType::set_read_p(), libdap::DDS::set_timeout(), libdap::DDS::tag_nested_sequences(), libdap::DDS::transfer_attributes(), libdap::DDS::var_begin(), libdap::DDS::var_end(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::send_data_ddx ( ostream &  data_stream,
DDS dds,
ConstraintEvaluator eval,
const string &  start,
const string &  boundary,
bool  with_mime_headers = true 
)
virtual

Send the data in the DDS object back to the client program. The data is encoded using a Marshaller, and enclosed in a MIME document which is all sent to data_stream. If this is being called from a CGI, data_stream is probably stdout and writing to it has the effect of sending the response back to the client.

FIXME!!!

Todo:
I am broken WRT the other code here for sending data and DDS responses
Parameters
ddsA DDS object containing the data to be sent.
evalA reference to the ConstraintEvaluator to use.
data_streamWrite the response to this stream.
anc_locationA directory to search for ancillary files (in addition to the CWD). This is used in a call to get_data_last_modified_time().
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.
Returns
void

Definition at line 1095 of file ResponseBuilder.cc.

References CRLF, libdap::dap4_data_ddx, libdap::ConstraintEvaluator::eval_function_clauses(), libdap::ConstraintEvaluator::function_clauses(), libdap::DDS::get_request_size(), libdap::DDS::get_response_limit(), libdap::last_modified_time(), libdap::long_to_string(), libdap::ConstraintEvaluator::parse_constraint(), libdap::set_mime_multipart(), libdap::DDS::set_timeout(), libdap::DDS::tag_nested_sequences(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::send_dds ( ostream &  out,
DDS dds,
ConstraintEvaluator eval,
bool  constrained = false,
bool  with_mime_headers = true 
)
virtual

This function formats and prints an ASCII representation of a DDS on stdout. Either an entire DDS or a constrained DDS may be sent. This function looks in the local cache and uses a DDS object there if it's valid. Otherwise, if the request CE contains server functions that build data for the response, the resulting DDS will be cached.

Parameters
outThe output stream to which the DAS is to be sent.
ddsThe DDS to send back to a client.
evalA reference to the ConstraintEvaluator to use.
constrainedIf this argument is true, evaluate the current constraint expression and send the `constrained DDS' back to the client.
anc_locationThe directory in which the external DAS file resides.
with_mime_headersIf true (the default) send MIME headers.
Returns
void
See Also
DDS

Definition at line 588 of file ResponseBuilder.cc.

References DBG, libdap::dods_dds, libdap::ConstraintEvaluator::eval_function_clauses(), libdap::DDS::get_dap_version(), libdap::last_modified_time(), libdap::DDS::mark_all(), libdap::ConstraintEvaluator::parse_constraint(), libdap::DDS::print(), libdap::DDS::print_constrained(), libdap::set_mime_text(), libdap::DDS::set_timeout(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::send_ddx ( ostream &  out,
DDS dds,
ConstraintEvaluator eval,
bool  with_mime_headers = true 
)
virtual

Send the DDX response. The DDX never contains data, instead it holds a reference to a Blob response which is used to get the data values. The DDS and DAS objects are built using code that already exists in the servers.

FIXME!!!

Todo:
I am broken WRT the other code here for sending data and DDS responses
Parameters
ddsThe dataset's DDS with attributes in the variables.
evalA reference to the ConstraintEvaluator to use.
outDestination
with_mime_headersIf true, include the MIME headers in the response. Defaults to true.

Definition at line 1060 of file ResponseBuilder.cc.

References libdap::dap4_ddx, libdap::ConstraintEvaluator::functional_expression(), libdap::DDS::get_dap_version(), libdap::last_modified_time(), libdap::ConstraintEvaluator::parse_constraint(), libdap::DDS::print_xml_writer(), libdap::set_mime_text(), and libdap::x_plain.

Here is the call graph for this function:

virtual void libdap::ResponseBuilder::set_btp_func_ce ( string  _ce)
inlinevirtual

Definition at line 104 of file ResponseBuilder.h.

References d_btp_func_ce.

void libdap::ResponseBuilder::set_ce ( string  _ce)
virtual

Definition at line 142 of file ResponseBuilder.cc.

References libdap::www2id().

Here is the call graph for this function:

void libdap::ResponseBuilder::set_dataset_name ( const string  _dataset)
virtual

Definition at line 158 of file ResponseBuilder.cc.

References libdap::www2id().

Here is the call graph for this function:

void libdap::ResponseBuilder::set_mime_binary ( ostream &  strm,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain,
const time_t  last_modified = 0,
const string &  protocol = "" 
) const

Write an HTTP 1.0 response header for our binary response document (i.e., the DataDDS object).

Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response. Defaults to application/octet-stream.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1399 of file ResponseBuilder.cc.

References CRLF, DVR, libdap::rfc822_date(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::set_mime_data_boundary ( ostream &  out,
const string &  boundary,
const string &  cid,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain 
) const

Definition at line 1470 of file ResponseBuilder.cc.

References CRLF, and libdap::x_plain.

void libdap::ResponseBuilder::set_mime_ddx_boundary ( ostream &  out,
const string &  boundary,
const string &  start,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain 
) const

Definition at line 1458 of file ResponseBuilder.cc.

References CRLF, and libdap::x_plain.

void libdap::ResponseBuilder::set_mime_error ( ostream &  strm,
int  code = 404,
const string &  reason = "Dataset not found",
const string &  protocol = "" 
) const

Generate an HTTP 1.0 response header for an Error object.

Parameters
strmWrite the MIME header to this stream.
codeHTTP 1.0 response code. Should be 400, ... 500, ...
reasonReason string of the HTTP 1.0 response header.
versionThe version string; denotes the DAP spec and implementation version.

Definition at line 1488 of file ResponseBuilder.cc.

References CRLF, DVR, and libdap::rfc822_date().

Here is the call graph for this function:

void libdap::ResponseBuilder::set_mime_html ( ostream &  strm,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain,
const time_t  last_modified = 0,
const string &  protocol = "" 
) const

Generate an HTTP 1.0 response header for a html document.

Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1353 of file ResponseBuilder.cc.

References CRLF, libdap::dods_error, DVR, libdap::rfc822_date(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::set_mime_multipart ( ostream &  out,
const string &  boundary,
const string &  start,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain,
const time_t  last_modified = 0,
const string &  protocol = "" 
) const

Definition at line 1428 of file ResponseBuilder.cc.

References CRLF, DVR, libdap::rfc822_date(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::set_mime_text ( ostream &  strm,
ObjectType  type = unknown_type,
EncodingType  enc = x_plain,
const time_t  last_modified = 0,
const string &  protocol = "" 
) const

Generate an HTTP 1.0 response header for a text document. This is used when returning a serialized DAS or DDS object.

Parameters
strmWrite the MIME header to this stream.
typeThe type of this this response. Defaults to application/octet-stream.
verThe version string; denotes the libdap implementation version.
encHow is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain.
last_modifiedThe time to use for the Last-Modified header value. Default is zero which means use the current time.

Definition at line 1305 of file ResponseBuilder.cc.

References CRLF, libdap::dap4_ddx, libdap::dods_error, DVR, libdap::rfc822_date(), and libdap::x_plain.

Here is the call graph for this function:

void libdap::ResponseBuilder::set_timeout ( int  t = 0)

Set the server's timeout value. A value of zero (the default) means no timeout.

Parameters
tServer timeout in seconds. Default is zero (no timeout).

Definition at line 166 of file ResponseBuilder.cc.

void libdap::ResponseBuilder::split_ce ( ConstraintEvaluator eval,
const string &  expr = "" 
)
virtual

Split the CE so that the server functions that compute new values are separated into their own string and can be evaluated separately from the rest of the CE (which can contain simple and slicing projection as well as other types of function calls).

Definition at line 204 of file ResponseBuilder.cc.

References DBG, and libdap::ConstraintEvaluator::find_function().

Here is the call graph for this function:

Friends And Related Function Documentation

friend class ResponseBuilderTest
friend

Definition at line 65 of file ResponseBuilder.h.

Member Data Documentation

string libdap::ResponseBuilder::d_btp_func_ce
protected

Definition at line 70 of file ResponseBuilder.h.

Referenced by get_btp_func_ce(), and set_btp_func_ce().

DAPCache3* libdap::ResponseBuilder::d_cache
protected

Definition at line 74 of file ResponseBuilder.h.

string libdap::ResponseBuilder::d_ce
protected

Definition at line 69 of file ResponseBuilder.h.

string libdap::ResponseBuilder::d_dataset
protected

Definition at line 68 of file ResponseBuilder.h.

string libdap::ResponseBuilder::d_default_protocol
protected

Definition at line 72 of file ResponseBuilder.h.

int libdap::ResponseBuilder::d_timeout
protected

Definition at line 71 of file ResponseBuilder.h.


The documentation for this class was generated from the following files: