NCBI C++ ToolKit
gui_http_session_request.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: gui_http_session_request.cpp 38013 2017-03-14 21:20:31Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Vladislav Evgeniev, Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
38 
40 {
41  int response_timeout = CGuiRegistry::GetInstance().GetInt("GBENCH.System.SeqConfigTimeout", 40);
42  CRef<CHttpSession> session(new CHttpSession);
43  CHttpRequest request = session->NewRequest(url, CHttpSession::ePost);
44  request.SetDeadline(CTimeout(response_timeout)).SetRetryProcessing(eOn);
45  m_Response.Reset(new CHttpResponse(request.Execute()));
46 }
47 
49 {
50  if (!m_Response)
51  NCBI_THROW(CException, eUnknown, "CGuiHttpSessionRequest: response is unavailable");
52 
53  if (!m_Response->ContentStream().good())
54  NCBI_THROW(CException, eUnknown, "CGuiHttpSessionRequest: response content stream is invalid");
55 
56  return m_Response->ContentStream();
57 }
58 
CRef< CHttpResponse > m_Response
CGuiHttpSessionRequest(const string &url)
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
int GetInt(const string &key, int default_val=0) const
retrieve values by section and key.
Definition: registry.cpp:133
HTTP request.
HTTP response.
CTimeout – Timeout interval.
Definition: ncbitime.hpp:1693
@ eOn
Definition: ncbi_types.h:111
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
CNcbiIstream & ContentStream(void) const
Get input stream.
CHttpRequest & SetRetryProcessing(ESwitch on_off)
Set whether Execute() should wait for actual response.
CHttpRequest & SetDeadline(const CTimeout &deadline)
Set new deadline for Execute().
CHttpRequest NewRequest(const CUrl &url, ERequestMethod method=eGet, const CHttpParam &param={})
Initialize request.
CHttpResponse Execute(void)
Send the request, initialize and return the response.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
Modified on Wed Sep 04 14:59:56 2024 by modify_doxy.py rev. 669887