sptk2 logo
SPTK Home Page
WSRequest.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/cthreads>
30#include <sptk5/net/HttpAuthentication.h>
31
32namespace sptk {
33
42class SP_EXPORT WSNameSpace
43{
44public:
50 WSNameSpace(const String& alias = "", const String& location = "")
51 : m_alias(alias)
52 , m_location(location)
53 {
54 }
55
61 : m_alias(other.m_alias)
62 , m_location(other.m_location)
63 {
64 }
65
69 ~WSNameSpace() noexcept = default;
70
76 WSNameSpace& operator=(const WSNameSpace& other)
77 {
78 if (&other != this)
79 {
80 std::scoped_lock lock(m_mutex);
81 m_alias = other.m_alias;
82 m_location = other.m_location;
83 }
84 return *this;
85 }
86
92 {
93 std::scoped_lock lock(m_mutex);
94 return m_alias;
95 }
96
102 {
103 std::scoped_lock lock(m_mutex);
104 return m_location;
105 }
106
107private:
108 mutable std::mutex m_mutex;
109 String m_alias;
110 String m_location;
111};
112
116class SP_EXPORT WSRequest
117 : public std::mutex
118{
119public:
124 explicit WSRequest(sptk::LogEngine* logEngine = nullptr)
125 : m_logEngine(logEngine)
126 {
127 }
128
132 virtual ~WSRequest() = default;
133
140 void processRequest(const xdoc::SNode& xmlContent, const xdoc::SNode& jsonContent,
141 HttpAuthentication* authentication, String& requestName);
142
148 [[nodiscard]] virtual String title() const
149 {
150 return "Generic SPTK WS Request Broker";
151 }
152
158 [[nodiscard]] virtual String defaultPage() const
159 {
160 return "index.html";
161 }
162
166 virtual String wsdl() const
167 {
168 return String("Not defined");
169 }
170
171 static String tagName(const String& nodeName);
172
173 static String nameSpace(const String& nodeName);
174
175 sptk::LogEngine* getLogEngine()
176 {
177 return m_logEngine;
178 }
179
180protected:
181 using RequestMethod = std::function<void(const sptk::xdoc::SNode&, const sptk::xdoc::SNode&,
183
194 virtual void requestBroker(const String& requestName, const xdoc::SNode& xmlContent, const xdoc::SNode& jsonContent,
195 HttpAuthentication* authentication, const WSNameSpace& requestNameSpace);
196
206 virtual void handleError(const xdoc::SNode& xmlContent, const xdoc::SNode& jsonContent,
207 const sptk::String& error, int errorCode) const;
208
217 virtual void logError(const sptk::String& requestName, const sptk::String& error, int errorCode) const;
218
224 xdoc::SNode findSoapBody(const xdoc::SNode& soapEnvelope, const WSNameSpace& soapNamespace);
225
226 void setRequestMethods(std::map<sptk::String, RequestMethod>&& requestMethods);
227
228private:
229 sptk::LogEngine* m_logEngine;
230 std::map<sptk::String, RequestMethod> m_requestMethods;
231};
232
233using SWSRequest = std::shared_ptr<WSRequest>;
234
235} // namespace sptk
Definition: HttpAuthentication.h:41
Definition: LogEngine.h:60
Definition: String.h:49
Definition: WSRequest.h:43
Definition: WSRequest.h:118
virtual String title() const
Definition: WSRequest.h:148
String getLocation() const
Definition: WSRequest.h:101
virtual void logError(const sptk::String &requestName, const sptk::String &error, int errorCode) const
String getAlias() const
Definition: WSRequest.h:91
WSRequest(sptk::LogEngine *logEngine=nullptr)
Definition: WSRequest.h:124
virtual void handleError(const xdoc::SNode &xmlContent, const xdoc::SNode &jsonContent, const sptk::String &error, int errorCode) const
virtual ~WSRequest()=default
virtual String wsdl() const
Definition: WSRequest.h:166
WSNameSpace(const String &alias="", const String &location="")
Definition: WSRequest.h:50
WSNameSpace(const WSNameSpace &other)
Definition: WSRequest.h:60
virtual String defaultPage() const
Definition: WSRequest.h:158
void processRequest(const xdoc::SNode &xmlContent, const xdoc::SNode &jsonContent, HttpAuthentication *authentication, String &requestName)
virtual void requestBroker(const String &requestName, const xdoc::SNode &xmlContent, const xdoc::SNode &jsonContent, HttpAuthentication *authentication, const WSNameSpace &requestNameSpace)
~WSNameSpace() noexcept=default
xdoc::SNode findSoapBody(const xdoc::SNode &soapEnvelope, const WSNameSpace &soapNamespace)

Fri Oct 14 2022 09:58:32: SPTK 5.4.1