bes  Updated for version 3.20.6
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 <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 
47 using namespace libdap;
48 using namespace bes;
49 using namespace std;
50 
51 BESDASResponseHandler::BESDASResponseHandler( const string &name )
52  : BESResponseHandler( name )
53 {
54 }
55 
56 BESDASResponseHandler::~BESDASResponseHandler( )
57 {
58 }
59 
78 void
80 {
81  dhi.action_name = DAS_RESPONSE_STR;
82 
83  GlobalMetadataStore *mds = GlobalMetadataStore::get_instance();
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  auto_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 
143 void
146 {
147  if( d_response_object )
148  {
149  transmitter->send_response( DAS_SERVICE, d_response_object, dhi ) ;
150  }
151 }
152 
159 void
160 BESDASResponseHandler::dump( ostream &strm ) const
161 {
162  strm << BESIndent::LMarg << "BESDASResponseHandler::dump - ("
163  << (void *)this << ")" << endl ;
164  BESIndent::Indent() ;
165  BESResponseHandler::dump( strm ) ;
166  BESIndent::UnIndent() ;
167 }
168 
170 BESDASResponseHandler::DASResponseBuilder( const string &name )
171 {
172  return new BESDASResponseHandler( name ) ;
173 }
174 
BESDataHandlerInterface::container
BESContainer * container
pointer to current container in this interface
Definition: BESDataHandlerInterface.h:75
bes::GlobalMetadataStore::MDSReadLock
Unlock and close the MDS item when the ReadLock goes out of scope.
Definition: GlobalMetadataStore.h:193
bes::GlobalMetadataStore::is_das_available
virtual MDSReadLock is_das_available(const std::string &name)
Is the DAS response for.
Definition: GlobalMetadataStore.cc:879
BESDASResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDASResponseHandler.cc:160
BESDASResponseHandler::execute
virtual void execute(BESDataHandlerInterface &dhi)
executes the command <get type="das" definition=...>
Definition: BESDASResponseHandler.cc:79
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESDASResponse
Represents an OPeNDAP DAS DAP2 data object within the BES.
Definition: BESDASResponse.h:44
BESContainer::get_relative_name
std::string get_relative_name() const
Get the relative name of the object in this container.
Definition: BESContainer.h:186
BESDASResponseHandler
response handler that builds an OPeNDAP DAS response object
Definition: BESDASResponseHandler.h:50
bes::GlobalMetadataStore::write_das_response
virtual void write_das_response(const std::string &name, std::ostream &os)
Write the stored DAS response to a stream.
Definition: GlobalMetadataStore.cc:1094
BESRequestHandlerList::execute_each
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
Definition: BESRequestHandlerList.cc:167
libdap
Definition: BESDapFunctionResponseCache.h:35
bes::GlobalMetadataStore
Store the DAP metadata responses.
Definition: GlobalMetadataStore.h:89
BESDASResponseHandler::transmit
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object
Definition: BESDASResponseHandler.cc:144
BESResponseHandler
handler object that knows how to create a specific response object
Definition: BESResponseHandler.h:77
BESTransmitter
Definition: BESTransmitter.h:47
BESDataHandlerInterface::first_container
void first_container()
set the container pointer to the first container in the containers list
Definition: BESDataHandlerInterface.h:135
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56