KD SOAP API Documentation: KDSoapMessage.cpp Source File

| KD SOAP API Documentation 2.2

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 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"
12#include "KDSoapNamespaceManager.h"
13#include "KDSoapNamespacePrefixes_p.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
28 KDSoapMessage::Use use;
29 bool isFault;
30 bool hasMessageAddressingProperties;
31 KDSoapMessageAddressingProperties messageAddressingProperties;
32};
33
34KDSoapMessage::KDSoapMessage()
35 : d(new KDSoapMessageData)
36{
37}
38
39 KDSoapMessage::KDSoapMessage(const KDSoapMessage &other)
40 : KDSoapValue(other)
41 , d(other.d)
42{
43}
44
45 KDSoapMessage &KDSoapMessage::operator=(const KDSoapMessage &other)
46{
47 KDSoapValue::operator=(other);
48 d = other.d;
49 return *this;
50}
51
52 KDSoapMessage &KDSoapMessage::operator=(const KDSoapValue &other) // cppcheck-suppress duplInheritedMember
53{
54 KDSoapValue::operator=(other);
55 return *this;
56}
57
58 bool KDSoapMessage::operator==(const KDSoapMessage &other) const
59{
60 return KDSoapValue::operator==(other) && d->use == other.d->use && d->isFault == other.d->isFault;
61}
62
63 bool KDSoapMessage::operator!=(const KDSoapMessage &other) const
64{
65 return !(*this == other);
66}
67
68KDSoapMessage::~KDSoapMessage()
69{
70}
71
72 void 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
81 void 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
95 KDSoapValueList &KDSoapMessage::arguments()
96{
97 return childValues();
98}
99
100 const KDSoapValueList &KDSoapMessage::arguments() const
101{
102 return childValues();
103}
104
105 QDebug operator<<(QDebug dbg, const KDSoapMessage &msg)
106{
107 return dbg << KDSoapValue(msg);
108}
109
110 bool KDSoapMessage::isFault() const
111{
112 return d->isFault;
113}
114
115 QString KDSoapMessage::faultAsString() const
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 const QString faultText =
128 childValues().child(QLatin1String("Reason")).childValues().child(QLatin1String("Text")).value().toString();
129 return QObject::tr("Fault %1: %2")
130 .arg(faultCodeStr, faultText);
131 } else {
132 // This better be on a single line, since it's used by server-side logging too
133 const QString actor = childValues().child(QLatin1String("faultactor")).value().toString();
134 QString ret = QObject::tr("Fault code %1: %2%3")
135 .arg(childValues().child(QLatin1String("faultcode")).value().toString(),
136 childValues().child(QLatin1String("faultstring")).value().toString(),
137 actor.isEmpty() ? QString() : QString::fromLatin1(" (%1)").arg(actor));
138 const QString detail = childValues().child(QLatin1String("detail")).value().toString();
139 if (!detail.isEmpty()) {
140 if (!ret.endsWith(QLatin1Char('.'))) {
141 ret += QLatin1Char('.');
142 }
143 ret += QLatin1String(" Error detail: ") + detail;
144 }
145 return ret;
146 }
147}
148
149 void KDSoapMessage::setFault(bool fault)
150{
151 d->isFault = fault;
152}
153
154 void KDSoapMessage::createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
155{
156 *this = KDSoapMessage();
157 setName(QString::fromLatin1("Fault"));
158 d->isFault = true;
159 if (soapVersion == KDSoap::SOAP1_2) {
160 setNamespaceUri(KDSoapNamespaceManager::soapEnvelope200305());
161 KDSoapValueList codeValueList;
162 codeValueList.addArgument(QString::fromLatin1("Value"), faultCode);
163 addArgument(QString::fromLatin1("Code"), codeValueList);
164 KDSoapValueList reasonValueList;
165 reasonValueList.addArgument(QString::fromLatin1("Text"), faultText);
166 addArgument(QString::fromLatin1("Reason"), reasonValueList);
167 } else {
168 setNamespaceUri(KDSoapNamespaceManager::soapEnvelope());
169 addArgument(QString::fromLatin1("faultcode"), faultCode);
170 addArgument(QString::fromLatin1("faultstring"), faultText);
171 }
172}
173
174 KDSoapMessageAddressingProperties KDSoapMessage::messageAddressingProperties() const
175{
176 return d->messageAddressingProperties;
177}
178
179 void KDSoapMessage::setMessageAddressingProperties(const KDSoapMessageAddressingProperties &map)
180{
181 d->messageAddressingProperties = map;
182 d->hasMessageAddressingProperties = true;
183}
184
185 bool KDSoapMessage::hasMessageAddressingProperties() const
186{
187 return d->hasMessageAddressingProperties;
188}
189
190 KDSoapMessage::Use KDSoapMessage::use() const
191{
192 return d->use;
193}
194
195 void KDSoapMessage::setUse(Use use)
196{
197 d->use = use;
198}
199
200 KDSoapMessage KDSoapHeaders::header(const QString &name) const
201{
202 for (const KDSoapMessage &header : qAsConst(*this)) {
203 if (header.name() == name) {
204 return header;
205 }
206 }
207 return KDSoapMessage();
208}
209
210 KDSoapMessage KDSoapHeaders::header(const QString &name, const QString &namespaceUri) const
211{
212 for (const KDSoapMessage &header : qAsConst(*this)) {
213 // qDebug() << "header(" << name << "," << namespaceUri << "): Looking at" << header.name() << "," << header.namespaceUri();
214 if (header.name() == name && (namespaceUri.isEmpty() || header.namespaceUri() == namespaceUri)) {
215 return header;
216 }
217 }
218 return KDSoapMessage();
219}
KDDateTime.h
operator<<
QDebug operator<<(QDebug dbg, const KDSoapMessage &msg)
Definition KDSoapMessage.cpp:105
KDSoapMessage.h
KDSoapNamespaceManager.h
KDSoapNamespacePrefixes_p.h
KDSoapHeaders::header
KDSoapMessage header(const QString &name) const
Definition KDSoapMessage.cpp:200
KDSoapMessageAddressingProperties
Definition KDSoapMessageAddressingProperties.h:76
KDSoapMessage
Definition KDSoapMessage.h:29
KDSoapMessage::setMessageAddressingProperties
void setMessageAddressingProperties(const KDSoapMessageAddressingProperties &map)
Definition KDSoapMessage.cpp:179
KDSoapMessage::operator==
bool operator==(const KDSoapMessage &other) const
Definition KDSoapMessage.cpp:58
KDSoapMessage::createFaultMessage
void createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
Definition KDSoapMessage.cpp:154
KDSoapMessage::setUse
void setUse(Use use)
Definition KDSoapMessage.cpp:195
KDSoapMessage::addArgument
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
Definition KDSoapMessage.cpp:72
KDSoapMessage::use
Use use() const
Definition KDSoapMessage.cpp:190
KDSoapMessage::setFault
void setFault(bool fault)
Definition KDSoapMessage.cpp:149
KDSoapMessage::~KDSoapMessage
~KDSoapMessage()
Definition KDSoapMessage.cpp:68
KDSoapMessage::isFault
bool isFault() const
Definition KDSoapMessage.cpp:110
KDSoapMessage::faultAsString
QString faultAsString() const
Definition KDSoapMessage.cpp:115
KDSoapMessage::operator=
KDSoapMessage & operator=(const KDSoapMessage &other)
Definition KDSoapMessage.cpp:45
KDSoapMessage::operator!=
bool operator!=(const KDSoapMessage &other) const
Definition KDSoapMessage.cpp:63
KDSoapMessage::hasMessageAddressingProperties
bool hasMessageAddressingProperties() const
Definition KDSoapMessage.cpp:185
KDSoapMessage::arguments
KDSoapValueList & arguments()
Definition KDSoapMessage.cpp:95
KDSoapMessage::messageAddressingProperties
KDSoapMessageAddressingProperties messageAddressingProperties() const
Definition KDSoapMessage.cpp:174
KDSoapMessage::KDSoapMessage
KDSoapMessage()
Definition KDSoapMessage.cpp:34
KDSoapNamespaceManager::soapEnvelope
static QString soapEnvelope()
Definition KDSoapNamespaceManager.cpp:36
KDSoapNamespaceManager::soapEnvelope200305
static QString soapEnvelope200305()
Definition KDSoapNamespaceManager.cpp:41
KDSoapValueList
Definition KDSoapValue.h:321
KDSoapValueList::child
KDSoapValue child(const QString &name) const
Definition KDSoapValue.cpp:427
KDSoapValueList::addArgument
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
Definition KDSoapValue.cpp:452
KDSoapValue
Definition KDSoapValue.h:60
KDSoapValue::childValues
KDSoapValueList & childValues() const
Definition KDSoapValue.cpp:149
KDSoapValue::Use
Use
Definition KDSoapValue.h:266
KDSoapValue::setNamespaceUri
void setNamespaceUri(const QString &ns)
Definition KDSoapValue.cpp:462
KDSoapValue::setName
void setName(const QString &name)
Definition KDSoapValue.cpp:99
KDSoapValue::namespaceUri
QString namespaceUri() const
Definition KDSoapValue.cpp:457
KDSoapValue::value
QVariant value() const
Definition KDSoapValue.cpp:104
KDSoapValue::operator=
KDSoapValue & operator=(const KDSoapValue &other)
Definition KDSoapValue.h:100
KDSoapValue::name
QString name() const
Definition KDSoapValue.cpp:94
KDSoapValue::operator==
bool operator==(const KDSoapValue &other) const
Definition KDSoapValue.cpp:155
KDSoapValue::isNull
bool isNull() const
Definition KDSoapValue.cpp:79
KDSoapValue::isQualified
bool isQualified() const
Definition KDSoapValue.cpp:114
KDSoapValue::setQualified
void setQualified(bool qualified)
Definition KDSoapValue.cpp:119
KDSoap::SoapVersion
SoapVersion
Definition KDSoapValue.h:40
KDSoap::SOAP1_2
@ SOAP1_2
Definition KDSoapValue.h:44
QDebug
QLatin1Char
QLatin1String
QList::append
void append(const T &value)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QSharedData
QString
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::isEmpty
bool isEmpty() const const
QVariant
QVariant::toString
QString toString() const const

© 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