bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BESDASResponseHandler.cc
1// BESDASResponseHandler.cc
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#include "config.h"
34
35#include <memory>
36
37#include <libdap/DAS.h>
38
39#include "BESDASResponseHandler.h"
40#include "BESDASResponse.h"
41#include "BESRequestHandlerList.h"
42#include "BESDapNames.h"
43#include "BESTransmitter.h"
44
45#include "GlobalMetadataStore.h"
46
47using namespace libdap;
48using namespace bes;
49using namespace std;
50
51BESDASResponseHandler::BESDASResponseHandler( const string &name )
52 : BESResponseHandler( name )
53{
54}
55
56BESDASResponseHandler::~BESDASResponseHandler( )
57{
58}
59
78void
80{
81 dhi.action_name = DAS_RESPONSE_STR;
82
84
86
87 dhi.first_container();
88 if (mds) lock = mds->is_das_available(*(dhi.container));
89
90 if (mds && lock()) {
91 // send the response
92 mds->write_das_response(dhi.container->get_relative_name(), dhi.get_output_stream());
93 // suppress transmitting a ResponseObject in transmit()
94 d_response_object = 0;
95 }
96 else {
97 DAS *das = new DAS();
98
99 d_response_object = new BESDASResponse( das ) ;
100
101 BESRequestHandlerList::TheList()->execute_each(dhi);
102
103#if ANNOTATION_SYSTEM
104 // Support for the experimental Dataset Annotation system. jhrg 12/19/18
105 if (!d_annotation_service_url.empty()) {
106 // resp_dds is a convenience object
107 BESDASResponse *resp_das = static_cast<BESDASResponse *>(d_response_object);
108
109 // Add the Annotation Service URL attribute in the DODS_EXTRA container.
110 AttrTable *dods_extra = resp_das->get_das()->get_table(DODS_EXTRA_ATTR_TABLE);
111 if (dods_extra)
112 dods_extra->append_attr(DODS_EXTRA_ANNOTATION_ATTR, "String", d_annotation_service_url);
113 else {
114 unique_ptr<AttrTable> new_dods_extra(new AttrTable);
115 new_dods_extra->append_attr(DODS_EXTRA_ANNOTATION_ATTR, "String", d_annotation_service_url);
116 resp_das->get_das()->add_table(DODS_EXTRA_ATTR_TABLE, new_dods_extra.release());
117 }
118 }
119#endif
120 // The DDS and DMR ResponseHandler code stores those responses when the
121 // MDS is configured (*mds is not null) and can make all of the DDS, DAS
122 // and DMR from either the DDS or DMR alone. But the DAS is different -
123 // the MDS code cannot generate the DDS and DMR responses from the DAS.
124 // We could re-work the software to build a DDS even when the request is
125 // for a DAS, but that would involve a number of modifications to the code
126 // for an optimization of dubious value. If a client asked for a DAS, it
127 // will likely ask for a DDS very soon... jhrg 3/18/18
128 }
129}
130
143void
146{
147 if( d_response_object )
148 {
149 transmitter->send_response( DAS_SERVICE, d_response_object, dhi ) ;
150 }
151}
152
159void
160BESDASResponseHandler::dump( ostream &strm ) const
161{
162 strm << BESIndent::LMarg << "BESDASResponseHandler::dump - ("
163 << (void *)this << ")" << endl ;
164 BESIndent::Indent() ;
166 BESIndent::UnIndent() ;
167}
168
170BESDASResponseHandler::DASResponseBuilder( const string &name )
171{
172 return new BESDASResponseHandler( name ) ;
173}
174
std::string get_relative_name() const
Get the relative name of the object in this container.
response handler that builds an OPeNDAP DAS response object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
virtual void execute(BESDataHandlerInterface &dhi)
executes the command <get type="das" definition=...>
Represents an OPeNDAP DAS DAP2 data object within the BES.
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
handler object that knows how to create a specific response object
void dump(std::ostream &strm) const override
dumps information about this object
Store the DAP metadata responses.
static GlobalMetadataStore * get_instance()
virtual void write_das_response(const std::string &name, std::ostream &os)
Write the stored DAS response to a stream.
virtual MDSReadLock is_das_available(const std::string &name)
Is the DAS response for.
Unlock and close the MDS item when the ReadLock goes out of scope.