KD SOAP API Documentation 2.1
Loading...
Searching...
No Matches
KDSoapMessage.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-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10#include "KDSoapMessage.h"
11#include "KDDateTime.h"
14#include <QDebug>
15#include <QVariant>
16#include <QXmlStreamReader>
17
18class KDSoapMessageData : public QSharedData
19{
20public:
21 KDSoapMessageData()
22 : use(KDSoapMessage::LiteralUse)
23 , isFault(false)
24 , hasMessageAddressingProperties(false)
25 {
26 }
27
29 bool isFault;
30 bool hasMessageAddressingProperties;
31 KDSoapMessageAddressingProperties messageAddressingProperties;
32};
33
35 : d(new KDSoapMessageData)
36{
37}
38
40 : KDSoapValue(other)
41 , d(other.d)
42{
43}
44
46{
48 d = other.d;
49 return *this;
50}
51
52KDSoapMessage &KDSoapMessage::operator=(const KDSoapValue &other) // cppcheck-suppress duplInheritedMember
53{
55 return *this;
56}
57
59{
60 return KDSoapValue::operator==(other) && d->use == other.d->use && d->isFault == other.d->isFault;
61}
62
64{
65 return !(*this == other);
66}
67
71
72void KDSoapMessage::addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace, const QString &typeName)
73{
74 KDSoapValue soapValue(argumentName, argumentValue, typeNameSpace, typeName);
75 if (isQualified()) {
76 soapValue.setQualified(true);
77 }
78 childValues().append(soapValue);
79}
80
81void KDSoapMessage::addArgument(const QString &argumentName, const KDSoapValueList &argumentValueList, const QString &typeNameSpace,
82 const QString &typeName)
83{
84 KDSoapValue soapValue(argumentName, argumentValueList, typeNameSpace, typeName);
85 if (isQualified()) {
86 soapValue.setQualified(true);
87 }
88 childValues().append(soapValue);
89}
90
91// I'm leaving the arguments() method even though it's the same as childValues,
92// because it's the documented public API, needed even in the most simple case,
93// while childValues is the "somewhat internal" KDSoapValue stuff.
94
99
101{
102 return childValues();
103}
104
106{
107 return dbg << KDSoapValue(msg);
108}
109
111{
112 return d->isFault;
113}
114
116{
117 if (namespaceUri() == QLatin1String("http://www.w3.org/2003/05/soap-envelope")) {
118 QString faultCodeStr;
119 KDSoapValue faultCode = childValues().child(QLatin1String("Code"));
120 while (!faultCode.isNull()) {
121 if (!faultCodeStr.isEmpty()) {
122 faultCodeStr += QLatin1String(" ");
123 }
124 faultCodeStr += faultCode.childValues().child(QLatin1String("Value")).value().toString();
125 faultCode = faultCode.childValues().child(QLatin1String("Subcode"));
126 }
127 return QObject::tr("Fault %1: %2")
128 .arg(faultCodeStr)
129 .arg(childValues().child(QLatin1String("Reason")).childValues().child(QLatin1String("Text")).value().toString());
130 } else {
131 // This better be on a single line, since it's used by server-side logging too
132 const QString actor = childValues().child(QLatin1String("faultactor")).value().toString();
133 QString ret = QObject::tr("Fault code %1: %2%3")
134 .arg(childValues().child(QLatin1String("faultcode")).value().toString(),
135 childValues().child(QLatin1String("faultstring")).value().toString(),
136 actor.isEmpty() ? QString() : QString::fromLatin1(" (%1)").arg(actor));
137 const QString detail = childValues().child(QLatin1String("detail")).value().toString();
138 if (!detail.isEmpty()) {
139 if (!ret.endsWith(QLatin1Char('.'))) {
140 ret += QLatin1Char('.');
141 }
142 ret += QLatin1String(" Error detail: ") + detail;
143 }
144 return ret;
145 }
146}
147
149{
150 d->isFault = fault;
151}
152
153void KDSoapMessage::createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
154{
155 *this = KDSoapMessage();
157 d->isFault = true;
158 if (soapVersion == KDSoap::SOAP1_2) {
160 KDSoapValueList codeValueList;
161 codeValueList.addArgument(QString::fromLatin1("Value"), faultCode);
162 addArgument(QString::fromLatin1("Code"), codeValueList);
163 KDSoapValueList reasonValueList;
164 reasonValueList.addArgument(QString::fromLatin1("Text"), faultText);
165 addArgument(QString::fromLatin1("Reason"), reasonValueList);
166 } else {
168 addArgument(QString::fromLatin1("faultcode"), faultCode);
169 addArgument(QString::fromLatin1("faultstring"), faultText);
170 }
171}
172
174{
175 return d->messageAddressingProperties;
176}
177
179{
180 d->messageAddressingProperties = map;
181 d->hasMessageAddressingProperties = true;
182}
183
185{
186 return d->hasMessageAddressingProperties;
187}
188
190{
191 return d->use;
192}
193
195{
196 d->use = use;
197}
198
200{
201 for (const KDSoapMessage &header : qAsConst(*this)) {
202 if (header.name() == name) {
203 return header;
204 }
205 }
206 return KDSoapMessage();
207}
208
209KDSoapMessage KDSoapHeaders::header(const QString &name, const QString &namespaceUri) const
210{
211 for (const KDSoapMessage &header : qAsConst(*this)) {
212 // qDebug() << "header(" << name << "," << namespaceUri << "): Looking at" << header.name() << "," << header.namespaceUri();
213 if (header.name() == name && (namespaceUri.isEmpty() || header.namespaceUri() == namespaceUri)) {
214 return header;
215 }
216 }
217 return KDSoapMessage();
218}
QDebug operator<<(QDebug dbg, const KDSoapMessage &msg)
KDSoapMessage header(const QString &name) const
void setMessageAddressingProperties(const KDSoapMessageAddressingProperties &map)
bool operator==(const KDSoapMessage &other) const
void createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
void setUse(Use use)
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
Use use() const
void setFault(bool fault)
bool isFault() const
QString faultAsString() const
KDSoapMessage & operator=(const KDSoapMessage &other)
bool operator!=(const KDSoapMessage &other) const
bool hasMessageAddressingProperties() const
KDSoapValueList & arguments()
KDSoapMessageAddressingProperties messageAddressingProperties() const
KDSoapValue child(const QString &name) const
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
KDSoapValueList & childValues() const
void setNamespaceUri(const QString &ns)
void setName(const QString &name)
QString namespaceUri() const
QVariant value() const
KDSoapValue & operator=(const KDSoapValue &other)
QString name() const
bool operator==(const KDSoapValue &other) const
bool isNull() const
bool isQualified() const
void setQualified(bool qualified)
void append(const T &value)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString fromLatin1(const char *str, int size)
bool isEmpty() const const
QString toString() const const

© 2010-2023 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 Tue Dec 26 2023 00:00:25 for KD SOAP API Documentation by doxygen 1.9.8