KD SOAP API Documentation  2.2
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 ****************************************************************************/
12 #include "KDSoapServerSocket_p.h"
13 #include <QDebug>
14 #include <QPointer>
15 
16 class KDSoapServerObjectInterface::Private
17 {
18 public:
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 
38  : m_value(value)
39  , m_name(name)
40 {
41 }
42 
44 {
45 }
46 
48  : d(new Private)
49 {
50 }
51 
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 
86 {
87  return HttpResponseHeaderItems();
88 }
89 
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 
119 void 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 
136 {
137  return !d->m_faultCode.isEmpty();
138 }
139 
141 {
142  return d->m_serverSocket;
143 }
144 
146 {
147  return d->m_requestHeaders;
148 }
149 
150 void 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 
160 {
161  d->m_responseHeaders = headers;
162 }
163 
164 KDSoapHeaders KDSoapServerObjectInterface::responseHeaders() const
165 {
166  return d->m_responseHeaders;
167 }
168 
170 {
171  return d->m_soapAction;
172 }
173 
175 {
176  return KDSoapDelayedResponseHandle(d->m_serverSocket);
177 }
178 
179 void KDSoapServerObjectInterface::setServerSocket(KDSoapServerSocket *serverSocket)
180 {
181  d->m_serverSocket = serverSocket;
182 }
183 
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 
205 {
206  d->m_responseNamespace = ns;
207 }
208 
209 QString KDSoapServerObjectInterface::responseNamespace() const
210 {
211  return d->m_responseNamespace;
212 }
void createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
virtual HttpResponseHeaderItems additionalHttpResponseHeaderItems() const
QVector< HttpResponseHeaderItem > HttpResponseHeaderItems
void setResponseHeaders(const KDSoapHeaders &headers)
KDSoapDelayedResponseHandle prepareDelayedResponse()
void doneProcessingRequestWithPath(const KDSoapServerObjectInterface &otherInterface)
void setFault(const QString &faultCode, const QString &faultString, const QString &faultActor=QString(), const QString &detail=QString())
virtual void processRequestWithPath(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction, const QString &path)
void writeXML(const QByteArray &reply, bool isFault=false)
void setResponseNamespace(const QString &ns)
void sendDelayedResponse(const KDSoapDelayedResponseHandle &responseHandle, const KDSoapMessage &response)
void writeHTTP(const QByteArray &httpReply)
virtual void processRequest(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction)
virtual QIODevice * processFileRequest(const QString &path, QByteArray &contentType)
void sendDelayedReply(KDSoapServerObjectInterface *serverObjectInterface, const KDSoapMessage &replyMsg)
QString name() const
Definition: KDSoapValue.cpp:94
@ SOAP1_1
Definition: KDSoapValue.h:42

© 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 by doxygen 1.9.1