KD SOAP API Documentation  2.1
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-2022 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"
14 #include <QDebug>
15 #include <QVariant>
16 #include <QXmlStreamReader>
17 
18 class KDSoapMessageData : public QSharedData
19 {
20 public:
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 
53 {
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 
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 
96 {
97  return childValues();
98 }
99 
101 {
102  return childValues();
103 }
104 
105 QDebug operator<<(QDebug dbg, const KDSoapMessage &msg)
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 
148 void KDSoapMessage::setFault(bool fault)
149 {
150  d->isFault = fault;
151 }
152 
153 void KDSoapMessage::createFaultMessage(const QString &faultCode, const QString &faultText, KDSoap::SoapVersion soapVersion)
154 {
155  *this = KDSoapMessage();
156  setName(QString::fromLatin1("Fault"));
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 
199 KDSoapMessage KDSoapHeaders::header(const QString &name) const
200 {
201  for (const KDSoapMessage &header : qAsConst(*this)) {
202  if (header.name() == name) {
203  return header;
204  }
205  }
206  return KDSoapMessage();
207 }
208 
209 KDSoapMessage 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 }
219 
220 bool KDSoapMessage::isNull() const
221 {
222  return childValues().isEmpty() && childValues().attributes().isEmpty() && value().isNull();
223 }
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
QList< KDSoapValue > & attributes()
Definition: KDSoapValue.h:375
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)
Definition: KDSoapValue.cpp:99
QString namespaceUri() const
QVariant value() const
QString name() const
Definition: KDSoapValue.cpp:94
bool operator==(const KDSoapValue &other) const
bool isNull() const
Definition: KDSoapValue.cpp:79
KDSoapValue & operator=(const KDSoapValue &other)
Definition: KDSoapValue.h:100
bool isQualified() const
void setQualified(bool qualified)
@ SOAP1_2
Definition: KDSoapValue.h:44

© 2010-2022 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 Jun 13 2023 12:18:34 for KD SOAP API Documentation by doxygen 1.9.1