KD SOAP API Documentation  2.1
KDSoapMessageAddressingProperties.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 ****************************************************************************/
11 
12 #include "KDSoapNamespaceManager.h"
14 
15 #include <QDebug>
16 #include <QLatin1String>
17 #include <QString>
18 #include <QXmlStreamWriter>
19 
20 class KDSoapMessageAddressingPropertiesData : public QSharedData
21 {
22 public:
23  QString destination; // Provides the address of the intended receiver of this message
24  QString action; // Identifies the semantics implied by this message
25  KDSoapEndpointReference sourceEndpoint; // Message origin, could be included to facilitate longer running message exchanges.
26  KDSoapEndpointReference replyEndpoint; // Intended receiver for replies to this message, could be included to facilitate longer running message
27  // exchanges.
28  KDSoapEndpointReference faultEndpoint; // Intended receiver for faults related to this message, could be included to facilitate longer running
29  // message exchanges.
30  QString messageID; // Unique identifier for this message, may be included to facilitate longer running message exchanges.
31  QVector<KDSoapMessageRelationship::Relationship> relationships; // Indicates relationships to prior messages, could be included to facilitate
32  // longer running message exchanges.
33  KDSoapValueList referenceParameters; // Equivalent of the reference parameters object from the endpoint reference within WSDL file
34  KDSoapValueList metadata; // Holding metadata information
36 };
37 
39  : d(new KDSoapMessageAddressingPropertiesData)
40 {
41 }
42 
44  : d(other.d)
45 {
46 }
47 
49 {
50  d = other.d;
51  return *this;
52 }
53 
55 {
56  return d->destination;
57 }
58 
59 void KDSoapMessageAddressingProperties::setDestination(const QString &destination)
60 {
61  d->destination = destination;
62 }
63 
65 {
66  return d->action;
67 }
68 
70 {
71  d->action = action;
72 }
73 
75 {
76  return d->sourceEndpoint;
77 }
78 
80 {
81  return d->sourceEndpoint.address();
82 }
83 
85 {
86  d->sourceEndpoint = sourceEndpoint;
87 }
88 
90 {
91  d->sourceEndpoint.setAddress(sourceEndpoint);
92 }
93 
95 {
96  return d->replyEndpoint;
97 }
98 
100 {
101  return d->replyEndpoint.address();
102 }
103 
105 {
106  d->replyEndpoint = replyEndpoint;
107 }
108 
110 {
111  d->replyEndpoint.setAddress(replyEndpoint);
112 }
113 
115 {
116  return d->faultEndpoint;
117 }
118 
120 {
121  return d->faultEndpoint.address();
122 }
123 
125 {
126  d->faultEndpoint = faultEndpoint;
127 }
128 
130 {
131  d->faultEndpoint.setAddress(faultEndpoint);
132 }
133 
135 {
136  return d->messageID;
137 }
138 
140 {
141  d->messageID = id;
142 }
143 
144 QVector<KDSoapMessageRelationship::Relationship> KDSoapMessageAddressingProperties::relationships() const
145 {
146  return d->relationships;
147 }
148 
149 void KDSoapMessageAddressingProperties::setRelationships(const QVector<KDSoapMessageRelationship::Relationship> &relationships)
150 {
151  d->relationships = relationships;
152 }
153 
155 {
156  d->relationships.append(relationship);
157 }
158 
160 {
161  return d->referenceParameters;
162 }
163 
165 {
166  d->referenceParameters = values;
167 }
168 
170 {
171  if (!oneReferenceParameter.isNull()) {
172  d->referenceParameters.append(oneReferenceParameter);
173  }
174 }
175 
177 {
178  return d->metadata;
179 }
180 
182 {
183  d->metadata = metadataList;
184 }
185 
187 {
188  if (!metadata.isNull()) {
189  d->metadata.append(metadata);
190  }
191 }
192 
194 {
195  return d->addressingNamespace;
196 }
197 
199 {
200  d->addressingNamespace = addressingNamespace;
201 }
202 
204 {
205 }
206 
208  KDSoapAddressingNamespace addressingNamespace)
209 {
211  switch (addressingNamespace) {
212  case Addressing200303:
213  case Addressing200403:
214  case Addressing200408: {
215  switch (address) {
216  case Anonymous:
217  prefix += QLatin1String("/role");
218  break;
219  case Unspecified:
220  prefix += QLatin1String("/id");
221  break;
222  default:
223  qWarning("Anything but Anonymous or Unspecified has no meaning in ws-addressing 2004/08 and earlier");
224  return QString();
225  }
226  break;
227  }
228  default:
229  break;
230  }
231 
232  switch (address) {
233  case Anonymous:
234  return prefix + QLatin1String("/anonymous");
235  case None:
236  return prefix + QLatin1String("/none");
237  case Reply:
238  return prefix + QLatin1String("/reply");
239  case Unspecified:
240  return prefix + QLatin1String("/unspecified");
241  }
242 
243  Q_ASSERT(false); // should never happen
244  return QString();
245 }
246 
248 {
252 }
253 
255 {
256  switch (addressingNamespace) {
257  case Addressing200303:
259  case Addressing200403:
261  case Addressing200408:
263  case Addressing200508:
265  default:
266  Q_ASSERT(false); // should never happen
267  return QString();
268  }
269 }
270 
271 static void writeAddressField(QXmlStreamWriter &writer, const QString &addressingNS, const QString &address)
272 {
273  writer.writeStartElement(addressingNS, QLatin1String("Address"));
274  writer.writeCharacters(address);
275  writer.writeEndElement();
276 }
277 
278 static void writeKDSoapValueVariant(QXmlStreamWriter &writer, const KDSoapValue &value)
279 {
280  const QVariant valueToWrite = value.value();
281  if (valueToWrite.canConvert(QVariant::String)) {
282  writer.writeCharacters(valueToWrite.toString());
283  } else {
284  qWarning("Warning: KDSoapMessageAddressingProperties call to writeKDSoapValueVariant could not write the given KDSoapValue "
285  "value because it could not be converted into a QString");
286  }
287 }
288 
289 static void writeKDSoapValueListHierarchy(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, const QString &addressingNS,
290  const KDSoapValueList &values)
291 {
292  for (const KDSoapValue &value : qAsConst(values)) {
293  const QString topLevelName = value.name();
294  writer.writeStartElement(addressingNS, topLevelName);
295 
296  if (value.childValues().isEmpty()) {
297  writeKDSoapValueVariant(writer, value);
298  } else {
299  writeKDSoapValueListHierarchy(namespacePrefixes, writer, addressingNS, value.childValues());
300  }
301 
302  writer.writeEndElement();
303  }
304 }
305 
306 void KDSoapMessageAddressingProperties::writeMessageAddressingProperties(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer,
307  const QString &messageNamespace, bool forceQualified) const
308 {
309  Q_UNUSED(messageNamespace);
310  Q_UNUSED(forceQualified);
311 
312  bool supportsNoneAddressing = false;
313  switch (d->addressingNamespace) {
314  case Addressing200303:
315  case Addressing200403:
316  case Addressing200408:
317  supportsNoneAddressing = false;
318  break;
319  case Addressing200508:
320  supportsNoneAddressing = true;
321  break;
322  }
323 
324  if (supportsNoneAddressing && d->destination == predefinedAddressToString(None, d->addressingNamespace)) {
325  return;
326  }
327 
328  if (d->action.isEmpty()) {
329  return;
330  }
331 
332  const QString addressingNS = addressingNamespaceToString(d->addressingNamespace);
333 
334  if (!d->destination.isEmpty()) {
335  writer.writeStartElement(addressingNS, QLatin1String("To"));
336  writer.writeCharacters(d->destination);
337  writer.writeEndElement();
338  }
339 
340  if (!d->sourceEndpoint.isEmpty()) {
341  writer.writeStartElement(addressingNS, QLatin1String("From"));
342  writeAddressField(writer, addressingNS, d->sourceEndpoint.address());
343  writer.writeEndElement();
344  }
345 
346  if (!d->replyEndpoint.isEmpty()) {
347  writer.writeStartElement(addressingNS, QLatin1String("ReplyTo"));
348  writeAddressField(writer, addressingNS, d->replyEndpoint.address());
349  writer.writeEndElement();
350  }
351 
352  if (!d->faultEndpoint.isEmpty()) {
353  writer.writeStartElement(addressingNS, QLatin1String("FaultTo"));
354  writeAddressField(writer, addressingNS, d->faultEndpoint.address());
355  writer.writeEndElement();
356  }
357 
358  if (!d->action.isEmpty()) {
359  writer.writeStartElement(addressingNS, QLatin1String("Action"));
360  writer.writeCharacters(d->action);
361  writer.writeEndElement();
362  }
363 
364  if (!d->messageID.isEmpty()) {
365  writer.writeStartElement(addressingNS, QLatin1String("MessageID"));
366  writer.writeCharacters(d->messageID);
367  writer.writeEndElement();
368  }
369 
370  for (const KDSoapMessageRelationship::Relationship &relationship : qAsConst(d->relationships)) {
371  if (relationship.uri.isEmpty()) {
372  continue;
373  }
374 
375  writer.writeStartElement(addressingNS, QLatin1String("RelatesTo"));
376 
377  if (!relationship.relationshipType.isEmpty()) {
378  writer.writeAttribute(QLatin1String("RelationshipType"), relationship.relationshipType);
379  }
380 
381  writer.writeCharacters(relationship.uri);
382  writer.writeEndElement();
383  }
384 
385  if (!d->referenceParameters.isEmpty()) {
386  writer.writeStartElement(addressingNS, QLatin1String("ReferenceParameters"));
387  writeKDSoapValueListHierarchy(namespacePrefixes, writer, addressingNS, d->referenceParameters);
388  writer.writeEndElement();
389  }
390 
391  if (!d->metadata.isEmpty()) {
392  writer.writeStartElement(addressingNS, QLatin1String("Metadata"));
393  writeKDSoapValueListHierarchy(namespacePrefixes, writer, addressingNS, d->metadata);
394  writer.writeEndElement();
395  }
396 }
397 
398 void KDSoapMessageAddressingProperties::readMessageAddressingProperty(const KDSoapValue &value)
399 {
400  const QString addressingNS = addressingNamespaceToString(d->addressingNamespace);
401 
402  if (value.name() == QLatin1String("Action")) {
403  d->action = value.value().toString();
404  } else if (value.name() == QLatin1String("MessageID")) {
405  d->messageID = value.value().toString();
406  } else if (value.name() == QLatin1String("To")) {
407  d->destination = value.value().toString();
408  } else if (value.name() == QLatin1String("From")) {
409  d->sourceEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
410  } else if (value.name() == QLatin1String("ReplyTo")) {
411  d->replyEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
412  } else if (value.name() == QLatin1String("RelatesTo")) {
414  relationship.uri = (value.value().toString());
415  relationship.relationshipType = addressingNS + QLatin1String("/reply");
416  const auto &childAttributes = value.childValues().attributes();
417  for (const KDSoapValue &attr : childAttributes) {
418  if (attr.name() == QLatin1String("RelationshipType")) {
419  relationship.relationshipType = attr.value().toString();
420  }
421  }
422  d->relationships.append(relationship);
423  } else if (value.name() == QLatin1String("FaultTo")) {
424  d->faultEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
425  } else if (value.name() == QLatin1String("ReferenceParameters")) {
426  d->referenceParameters = value.childValues();
427  } else if (value.name() == QLatin1String("Metadata")) {
428  d->metadata = value.childValues();
429  }
430 }
431 
432 QDebug operator<<(QDebug dbg, const KDSoapMessageAddressingProperties &msg)
433 {
434  dbg << msg.action() << msg.destination() << msg.sourceEndpoint().address() << msg.replyEndpoint().address() << msg.faultEndpoint().address()
435  << msg.messageID();
436 
437  return dbg;
438 }
static void writeKDSoapValueVariant(QXmlStreamWriter &writer, const KDSoapValue &value)
static void writeKDSoapValueListHierarchy(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, const QString &addressingNS, const KDSoapValueList &values)
QDebug operator<<(QDebug dbg, const KDSoapMessageAddressingProperties &msg)
static void writeAddressField(QXmlStreamWriter &writer, const QString &addressingNS, const QString &address)
void addReferenceParameter(const KDSoapValue &oneReferenceParameter)
void addRelationship(const KDSoapMessageRelationship::Relationship &relationship)
QVector< KDSoapMessageRelationship::Relationship > relationships() const
void setSourceEndpoint(const KDSoapEndpointReference &sourceEndpoint)
void setReplyEndpoint(const KDSoapEndpointReference &replyEndpoint)
void setReplyEndpointAddress(const QString &replyEndpoint)
void setAddressingNamespace(KDSoapAddressingNamespace addressingNamespace)
KDSoapMessageAddressingProperties & operator=(const KDSoapMessageAddressingProperties &other)
KDSoapAddressingNamespace addressingNamespace() const
void setFaultEndpoint(const KDSoapEndpointReference &faultEndpoint)
void setSourceEndpointAddress(const QString &sourceEndpoint)
void setMetadata(const KDSoapValueList &metadataList)
void setReferenceParameters(const KDSoapValueList &values)
void setFaultEndpointAddress(const QString &faultEndpoint)
static QString predefinedAddressToString(KDSoapAddressingPredefinedAddress address, KDSoapAddressingNamespace addressingNamespace=Addressing200508)
static bool isWSAddressingNamespace(const QString &namespaceUri)
static QString addressingNamespaceToString(KDSoapAddressingNamespace addressingNamespace)
void setRelationships(const QVector< KDSoapMessageRelationship::Relationship > &relationships)
static QString soapMessageAddressing200303()
static QString soapMessageAddressing200408()
static QString soapMessageAddressing()
static QString soapMessageAddressing200403()
QList< KDSoapValue > & attributes()
Definition: KDSoapValue.h:375
KDSoapValue child(const QString &name) const
KDSoapValueList & childValues() const
QVariant value() const
QString name() const
Definition: KDSoapValue.cpp:94
bool isNull() const
Definition: KDSoapValue.cpp:79

© 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