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

Go to the SVN repository for this file.

1 /* $Id: soap_client.cpp 84532 2018-11-16 02:45:42Z lavr $
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  * Author: Andrei Gourianov
27  *
28  * File Description:
29  * SOAP http client
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
35 #include <serial/objistrxml.hpp>
36 #include <serial/objostrxml.hpp>
38 
39 #include <algorithm>
40 
41 
43 
44 CSoapHttpClient::CSoapHttpClient(const string& server_url,
45  const string& namespace_name)
46  : m_ServerUrl(server_url), m_DefNamespace(namespace_name),
47  m_OmitScopePrefixes(false)
48 {
49 }
50 
52 {
53 }
54 
55 void CSoapHttpClient::SetServerUrl(const string& server_url)
56 {
57  m_ServerUrl = server_url;
58 }
59 const string& CSoapHttpClient::GetServerUrl(void) const
60 {
61  return m_ServerUrl;
62 }
63 void CSoapHttpClient::SetDefaultNamespaceName(const string& namespace_name)
64 {
65  m_DefNamespace = namespace_name;
66 }
68 {
69  return m_DefNamespace;
70 }
71 
72 void CSoapHttpClient::SetUserHeader(const string& user_header)
73 {
74  m_UserHeader = user_header;
75 }
76 const string& CSoapHttpClient::GetUserHeader(void) const
77 {
78  return m_UserHeader;
79 }
80 
82 {
83  if (find(m_Types.begin(), m_Types.end(), type_getter) == m_Types.end()) {
84  m_Types.push_back(type_getter);
85  }
86 }
87 
88 extern "C" {
89 static EHTTP_HeaderParse x_ParseHttpHeader(const char* /*http_header*/,
90  void* /*user_data*/,
91  int /*server_error*/)
92 {
93  return eHTTP_HeaderContinue;
94 }
95 }
96 
97 
99  const CSoapMessage& request,
100  CConstRef<CSoapFault>* fault /*=0*/,
101  const string& soap_action /*= kEmptyStr*/) const
102 {
103  response.Reset();
104  vector< TTypeInfoGetter >::const_iterator types_in;
105  for (types_in = m_Types.begin(); types_in != m_Types.end(); ++types_in) {
106  response.RegisterObjectType(*types_in);
107  }
108 
109  char content_type[CONN_CONTENT_TYPE_LEN+1];
110 
111 // SOAPAction:
112 // http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528
113 // "An HTTP client MUST use this header field when issuing a SOAP HTTP Request"
114 
115  string header;
116  header = "SOAPAction: \"" + soap_action + "\"\r\n";
117  if (!m_UserHeader.empty()) {
118  header += m_UserHeader;
119  header += "\r\n";
120  }
123  eENCOD_None, content_type, sizeof(content_type) - 1)),
125 
126  unique_ptr<CObjectOStream> os(CObjectOStream::Open(eSerial_Xml, http));
127  unique_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_Xml, http));
128 
129 // allow unknown data
130  is->SetSkipUnknownMembers(eSerialSkipUnknown_Yes);
131 // allow missing mandatory data
132  is->SetVerifyData(eSerialVerifyData_No);
133 
134  if (m_OmitScopePrefixes) {
135  dynamic_cast<CObjectOStreamXml*>(os.get())->SetEnforcedStdXml(true);
136  dynamic_cast<CObjectIStreamXml*>(is.get())->SetEnforcedStdXml(true);
137  }
138 
139  *os << request;
140  dynamic_cast<CObjectIStreamXml*>(is.get())->FindFileHeader(false);
141  *is >> response;
142  if (fault) {
143  *fault = SOAP_GetKnownObject<CSoapFault>(response);
144  }
145 }
146 
148 {
149  m_OmitScopePrefixes = bOmit;
150 }
151 
This stream exchanges data with an HTTP server located at the URL: http[s]://host[:port]/path[?...
CConstRef –.
Definition: ncbiobj.hpp:1266
CObjectIStreamXml –.
Definition: objistrxml.hpp:56
CObjectOStreamXml –.
Definition: objostrxml.hpp:54
const string & GetDefaultNamespaceName(void) const
Get default namespace name.
Definition: soap_client.cpp:67
void SetDefaultNamespaceName(const string &namespace_name)
Set default namespace name.
Definition: soap_client.cpp:63
void SetOmitScopePrefixes(bool bOmit)
vector< TTypeInfoGetter > m_Types
~CSoapHttpClient(void)
Definition: soap_client.cpp:51
void SetServerUrl(const string &server_url)
Set SOAP server URL.
Definition: soap_client.cpp:55
const string & GetServerUrl(void) const
Get SOAP server URL.
Definition: soap_client.cpp:59
CSoapHttpClient(const string &server_url, const string &namespace_name)
Definition: soap_client.cpp:44
const string & GetUserHeader(void) const
Get additional HTTP user header.
Definition: soap_client.cpp:76
void RegisterObjectType(TTypeInfoGetter type_getter)
Register incoming object type.
Definition: soap_client.cpp:81
void Invoke(CSoapMessage &response, const CSoapMessage &request, CConstRef< CSoapFault > *fault=0, const string &soap_action=kEmptyStr) const
Invoke SOAP server procedure synchronously: send 'request' and receive 'response'.
Definition: soap_client.cpp:98
void SetUserHeader(const string &user_header)
Set additional HTTP user header to use in Invoke calls.
Definition: soap_client.cpp:72
void RegisterObjectType(TTypeInfoGetter type_getter)
void Reset(void)
#define false
Definition: bool.h:36
EHTTP_HeaderParse
The extended version HTTP_CreateConnectorEx() is able to track the HTTP response chain and also chang...
@ eHTTP_HeaderContinue
Parse succeeded, continue with body.
TTypeInfo(* TTypeInfoGetter)(void)
Definition: serialdef.hpp:63
@ eSerialSkipUnknown_Yes
do skip
Definition: serialdef.hpp:122
@ eSerialVerifyData_No
do not verify
Definition: serialdef.hpp:109
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
char * MIME_ComposeContentTypeEx(EMIME_Type type, EMIME_SubType subtype, EMIME_Encoding encoding, char *buf, size_t bufsize)
#define CONN_CONTENT_TYPE_LEN
@ eMIME_T_Text
@ eMIME_Xml
@ eENCOD_None
static EHTTP_HeaderParse x_ParseHttpHeader(const char *, void *, int)
Definition: soap_client.cpp:89
Modified on Sat Jul 13 13:41:19 2024 by modify_doxy.py rev. 669887