KD SOAP API Documentation  2.2
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"
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 
52 KDSoapMessage &KDSoapMessage::operator=(const KDSoapValue &other) // cppcheck-suppress duplInheritedMember
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  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) {
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 {
169  addArgument(QString::fromLatin1("faultcode"), faultCode);
170  addArgument(QString::fromLatin1("faultstring"), faultText);
171  }
172 }
173 
175 {
176  return d->messageAddressingProperties;
177 }
178 
180 {
181  d->messageAddressingProperties = map;
182  d->hasMessageAddressingProperties = true;
183 }
184 
186 {
187  return d->hasMessageAddressingProperties;
188 }
189 
191 {
192  return d->use;
193 }
194 
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 }
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)
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-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