KD SOAP API Documentation: KDSoapServerObjectInterface.cpp Source File

| KD SOAP API Documentation 2.2

Loading...
Searching...
No Matches
KDSoapServerObjectInterface.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Soap project.
4**
5** SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10#include "KDSoapServerObjectInterface.h"
11#include "KDSoapClient/KDSoapValue.h"
12#include "KDSoapServerSocket_p.h"
13#include <QDebug>
14#include <QPointer>
15
16class KDSoapServerObjectInterface::Private
17{
18public:
19 Private()
20 : m_serverSocket(nullptr)
21 {
22 }
23
24 KDSoapHeaders m_requestHeaders;
25 KDSoapHeaders m_responseHeaders;
26 QString m_faultCode;
27 QString m_faultString;
28 QString m_faultActor;
29 QString m_detail;
30 KDSoapValue m_detailValue;
31 QString m_responseNamespace;
32 QByteArray m_soapAction;
33 // QPointer in case the client disconnects during a delayed response
34 QPointer<KDSoapServerSocket> m_serverSocket;
35};
36
37 KDSoapServerObjectInterface::HttpResponseHeaderItem::HttpResponseHeaderItem(const QByteArray &name, const QByteArray &value)
38 : m_value(value)
39 , m_name(name)
40{
41}
42
43KDSoapServerObjectInterface::HttpResponseHeaderItem::HttpResponseHeaderItem()
44{
45}
46
47KDSoapServerObjectInterface::KDSoapServerObjectInterface()
48 : d(new Private)
49{
50}
51
52KDSoapServerObjectInterface::~KDSoapServerObjectInterface()
53{
54 delete d;
55}
56
57 void KDSoapServerObjectInterface::processRequest(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction)
58{
59 const QString method = request.name();
60 qDebug() << "Slot not found:" << method << "[soapAction =" << soapAction << "]" /* << "in" << metaObject()->className()*/;
61 const KDSoap::SoapVersion soapVersion = KDSoap::SOAP1_1; // TODO version selection on the server side
62 response.createFaultMessage(QString::fromLatin1("Server.MethodNotFound"), QString::fromLatin1("%1 not found").arg(method), soapVersion);
63}
64
65 QIODevice *KDSoapServerObjectInterface::processFileRequest(const QString &path, QByteArray &contentType)
66{
67 Q_UNUSED(path);
68 Q_UNUSED(contentType);
69 return nullptr;
70}
71
72 void KDSoapServerObjectInterface::processRequestWithPath(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction,
73 const QString &path)
74{
75 Q_UNUSED(soapAction);
76 const QString method = request.name();
77 qWarning("Invalid path: \"%s\"", qPrintable(path));
78 // qWarning() << "Invalid path:" << path << "[method =" << method << "; soapAction =" << soapAction << "]" /* << "in" <<
79 // metaObject()->className();
80 const KDSoap::SoapVersion soapVersion = KDSoap::SOAP1_1; // TODO version selection on the server side
81 response.createFaultMessage(QString::fromLatin1("Client.Data"), QString::fromLatin1("Method %1 not found in path %2").arg(method, path),
82 soapVersion);
83}
84
85 KDSoapServerObjectInterface::HttpResponseHeaderItems KDSoapServerObjectInterface::additionalHttpResponseHeaderItems() const
86{
87 return HttpResponseHeaderItems();
88}
89
90 void KDSoapServerObjectInterface::doneProcessingRequestWithPath(const KDSoapServerObjectInterface &otherInterface)
91{
92 d->m_faultCode = otherInterface.d->m_faultCode;
93 d->m_faultString = otherInterface.d->m_faultString;
94 d->m_faultActor = otherInterface.d->m_faultActor;
95 d->m_detail = otherInterface.d->m_detail;
96 d->m_detailValue = otherInterface.d->m_detailValue;
97 d->m_responseHeaders = otherInterface.d->m_responseHeaders;
98 d->m_responseNamespace = otherInterface.d->m_responseNamespace;
99}
100
101 void KDSoapServerObjectInterface::setFault(const QString &faultCode, const QString &faultString, const QString &faultActor, const QString &detail)
102{
103 Q_ASSERT(!faultCode.isEmpty());
104 d->m_faultCode = faultCode;
105 d->m_faultString = faultString;
106 d->m_faultActor = faultActor;
107 d->m_detail = detail;
108}
109
110 void KDSoapServerObjectInterface::setFault(const QString &faultCode, const QString &faultString, const QString &faultActor, const KDSoapValue &detail)
111{
112 Q_ASSERT(!faultCode.isEmpty());
113 d->m_faultCode = faultCode;
114 d->m_faultString = faultString;
115 d->m_faultActor = faultActor;
116 d->m_detailValue = detail;
117}
118
119void KDSoapServerObjectInterface::storeFaultAttributes(KDSoapMessage &message) const
120{
121 // SOAP 1.1 <faultcode>, <faultstring>, <faultfactor>, <detail>
122 message.addArgument(QString::fromLatin1("faultcode"), d->m_faultCode);
123 message.addArgument(QString::fromLatin1("faultstring"), d->m_faultString);
124 message.addArgument(QString::fromLatin1("faultactor"), d->m_faultActor);
125 if (d->m_detailValue.isNil() || d->m_detailValue.isNull()) {
126 message.addArgument(QString::fromLatin1("detail"), d->m_detail);
127 } else {
128 KDSoapValueList detailAsList;
129 detailAsList.append(d->m_detailValue);
130 message.addArgument(QString::fromLatin1("detail"), detailAsList);
131 }
132 // TODO : Answer SOAP 1.2 <Code> , <Reason> , <Node> , <Role> , <Detail>
133}
134
135 bool KDSoapServerObjectInterface::hasFault() const
136{
137 return !d->m_faultCode.isEmpty();
138}
139
140 QAbstractSocket *KDSoapServerObjectInterface::serverSocket() const
141{
142 return d->m_serverSocket;
143}
144
145 KDSoapHeaders KDSoapServerObjectInterface::requestHeaders() const
146{
147 return d->m_requestHeaders;
148}
149
150void KDSoapServerObjectInterface::setRequestHeaders(const KDSoapHeaders &headers, const QByteArray &soapAction)
151{
152 d->m_requestHeaders = headers;
153 d->m_soapAction = soapAction;
154 // Prepare for a new request to be handled
155 d->m_faultCode.clear();
156 d->m_responseHeaders.clear();
157}
158
159 void KDSoapServerObjectInterface::setResponseHeaders(const KDSoapHeaders &headers)
160{
161 d->m_responseHeaders = headers;
162}
163
164 KDSoapHeaders KDSoapServerObjectInterface::responseHeaders() const
165{
166 return d->m_responseHeaders;
167}
168
169 QByteArray KDSoapServerObjectInterface::soapAction() const
170{
171 return d->m_soapAction;
172}
173
174 KDSoapDelayedResponseHandle KDSoapServerObjectInterface::prepareDelayedResponse()
175{
176 return KDSoapDelayedResponseHandle(d->m_serverSocket);
177}
178
179void KDSoapServerObjectInterface::setServerSocket(KDSoapServerSocket *serverSocket)
180{
181 d->m_serverSocket = serverSocket;
182}
183
184 void KDSoapServerObjectInterface::sendDelayedResponse(const KDSoapDelayedResponseHandle &responseHandle, const KDSoapMessage &response)
185{
186 KDSoapServerSocket *socket = responseHandle.serverSocket();
187 if (socket) {
188 socket->sendDelayedReply(this, response);
189 }
190}
191
192 void KDSoapServerObjectInterface::writeHTTP(const QByteArray &httpReply)
193{
194 const qint64 written = d->m_serverSocket->write(httpReply);
195 Q_ASSERT(written == httpReply.size()); // Please report a bug if you hit this.
196 Q_UNUSED(written);
197}
198
199 void KDSoapServerObjectInterface::writeXML(const QByteArray &reply, bool isFault)
200{
201 d->m_serverSocket->writeXML(reply, isFault);
202}
203
204 void KDSoapServerObjectInterface::setResponseNamespace(const QString &ns)
205{
206 d->m_responseNamespace = ns;
207}
208
209 QString KDSoapServerObjectInterface::responseNamespace() const
210{
211 return d->m_responseNamespace;
212}
KDSoapServerObjectInterface.h
KDSoapServerSocket_p.h
KDSoapValue.h
KDSoapDelayedResponseHandle
Definition KDSoapDelayedResponseHandle.h:27
KDSoapHeaders
Definition KDSoapMessage.h:185
KDSoapMessage
Definition KDSoapMessage.h:29
KDSoapMessage::createFaultMessage
void createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
Definition KDSoapMessage.cpp:154
KDSoapMessage::addArgument
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
Definition KDSoapMessage.cpp:72
KDSoapServerObjectInterface
Definition KDSoapServerObjectInterface.h:60
KDSoapServerObjectInterface::additionalHttpResponseHeaderItems
virtual HttpResponseHeaderItems additionalHttpResponseHeaderItems() const
Definition KDSoapServerObjectInterface.cpp:85
KDSoapServerObjectInterface::HttpResponseHeaderItems
QVector< HttpResponseHeaderItem > HttpResponseHeaderItems
Definition KDSoapServerObjectInterface.h:131
KDSoapServerObjectInterface::KDSoapServerObjectInterface
KDSoapServerObjectInterface()
Definition KDSoapServerObjectInterface.cpp:47
KDSoapServerObjectInterface::setResponseHeaders
void setResponseHeaders(const KDSoapHeaders &headers)
Definition KDSoapServerObjectInterface.cpp:159
KDSoapServerObjectInterface::~KDSoapServerObjectInterface
virtual ~KDSoapServerObjectInterface()
Definition KDSoapServerObjectInterface.cpp:52
KDSoapServerObjectInterface::prepareDelayedResponse
KDSoapDelayedResponseHandle prepareDelayedResponse()
Definition KDSoapServerObjectInterface.cpp:174
KDSoapServerObjectInterface::doneProcessingRequestWithPath
void doneProcessingRequestWithPath(const KDSoapServerObjectInterface &otherInterface)
Definition KDSoapServerObjectInterface.cpp:90
KDSoapServerObjectInterface::setFault
void setFault(const QString &faultCode, const QString &faultString, const QString &faultActor=QString(), const QString &detail=QString())
Definition KDSoapServerObjectInterface.cpp:101
KDSoapServerObjectInterface::processRequestWithPath
virtual void processRequestWithPath(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction, const QString &path)
Definition KDSoapServerObjectInterface.cpp:72
KDSoapServerObjectInterface::hasFault
bool hasFault() const
Definition KDSoapServerObjectInterface.cpp:135
KDSoapServerObjectInterface::writeXML
void writeXML(const QByteArray &reply, bool isFault=false)
Definition KDSoapServerObjectInterface.cpp:199
KDSoapServerObjectInterface::requestHeaders
KDSoapHeaders requestHeaders() const
Definition KDSoapServerObjectInterface.cpp:145
KDSoapServerObjectInterface::soapAction
QByteArray soapAction() const
Definition KDSoapServerObjectInterface.cpp:169
KDSoapServerObjectInterface::setResponseNamespace
void setResponseNamespace(const QString &ns)
Definition KDSoapServerObjectInterface.cpp:204
KDSoapServerObjectInterface::serverSocket
QAbstractSocket * serverSocket() const
Definition KDSoapServerObjectInterface.cpp:140
KDSoapServerObjectInterface::sendDelayedResponse
void sendDelayedResponse(const KDSoapDelayedResponseHandle &responseHandle, const KDSoapMessage &response)
Definition KDSoapServerObjectInterface.cpp:184
KDSoapServerObjectInterface::writeHTTP
void writeHTTP(const QByteArray &httpReply)
Definition KDSoapServerObjectInterface.cpp:192
KDSoapServerObjectInterface::processRequest
virtual void processRequest(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction)
Definition KDSoapServerObjectInterface.cpp:57
KDSoapServerObjectInterface::processFileRequest
virtual QIODevice * processFileRequest(const QString &path, QByteArray &contentType)
Definition KDSoapServerObjectInterface.cpp:65
KDSoapServerSocket
Definition KDSoapServerSocket_p.h:35
KDSoapServerSocket::sendDelayedReply
void sendDelayedReply(KDSoapServerObjectInterface *serverObjectInterface, const KDSoapMessage &replyMsg)
Definition KDSoapServerSocket.cpp:515
KDSoapValueList
Definition KDSoapValue.h:321
KDSoapValue
Definition KDSoapValue.h:60
KDSoapValue::name
QString name() const
Definition KDSoapValue.cpp:94
KDSoap::SoapVersion
SoapVersion
Definition KDSoapValue.h:40
KDSoap::SOAP1_1
@ SOAP1_1
Definition KDSoapValue.h:42
QAbstractSocket
QByteArray
QByteArray::size
int size() const const
QIODevice
QList::append
void append(const T &value)
QPointer
QString
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::isEmpty
bool isEmpty() const const
QVector
KDSoapServerObjectInterface::HttpResponseHeaderItem::HttpResponseHeaderItem
HttpResponseHeaderItem()
Definition KDSoapServerObjectInterface.cpp:43

© 2010-2024 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-soap/
Generated on Sun Jan 7 2024 11:47:36 for KD SOAP API Documentation by doxygen 1.9.8