KD SOAP API Documentation  2.2
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 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  const QString addressingNS = addressingNamespaceToString(d->addressingNamespace);
329 
330  if (!d->destination.isEmpty()) {
331  writer.writeStartElement(addressingNS, QLatin1String("To"));
332  writer.writeCharacters(d->destination);
333  writer.writeEndElement();
334  }
335 
336  if (!d->sourceEndpoint.isEmpty()) {
337  writer.writeStartElement(addressingNS, QLatin1String("From"));
338  writeAddressField(writer, addressingNS, d->sourceEndpoint.address());
339  writer.writeEndElement();
340  }
341 
342  if (!d->replyEndpoint.isEmpty()) {
343  writer.writeStartElement(addressingNS, QLatin1String("ReplyTo"));
344  writeAddressField(writer, addressingNS, d->replyEndpoint.address());
345  writer.writeEndElement();
346  }
347 
348  if (!d->faultEndpoint.isEmpty()) {
349  writer.writeStartElement(addressingNS, QLatin1String("FaultTo"));
350  writeAddressField(writer, addressingNS, d->faultEndpoint.address());
351  writer.writeEndElement();
352  }
353 
354  if (!d->action.isEmpty()) {
355  writer.writeStartElement(addressingNS, QLatin1String("Action"));
356  writer.writeCharacters(d->action);
357  writer.writeEndElement();
358  }
359 
360  if (!d->messageID.isEmpty()) {
361  writer.writeStartElement(addressingNS, QLatin1String("MessageID"));
362  writer.writeCharacters(d->messageID);
363  writer.writeEndElement();
364  }
365 
366  for (const KDSoapMessageRelationship::Relationship &relationship : qAsConst(d->relationships)) {
367  if (relationship.uri.isEmpty()) {
368  continue;
369  }
370 
371  writer.writeStartElement(addressingNS, QLatin1String("RelatesTo"));
372 
373  if (!relationship.relationshipType.isEmpty()) {
374  writer.writeAttribute(QLatin1String("RelationshipType"), relationship.relationshipType);
375  }
376 
377  writer.writeCharacters(relationship.uri);
378  writer.writeEndElement();
379  }
380 
381  if (!d->referenceParameters.isEmpty()) {
382  writer.writeStartElement(addressingNS, QLatin1String("ReferenceParameters"));
383  writeKDSoapValueListHierarchy(namespacePrefixes, writer, addressingNS, d->referenceParameters);
384  writer.writeEndElement();
385  }
386 
387  if (!d->metadata.isEmpty()) {
388  writer.writeStartElement(addressingNS, QLatin1String("Metadata"));
389  writeKDSoapValueListHierarchy(namespacePrefixes, writer, addressingNS, d->metadata);
390  writer.writeEndElement();
391  }
392 }
393 
394 void KDSoapMessageAddressingProperties::readMessageAddressingProperty(const KDSoapValue &value)
395 {
396  const QString addressingNS = addressingNamespaceToString(d->addressingNamespace);
397 
398  if (value.name() == QLatin1String("Action")) {
399  d->action = value.value().toString();
400  } else if (value.name() == QLatin1String("MessageID")) {
401  d->messageID = value.value().toString();
402  } else if (value.name() == QLatin1String("To")) {
403  d->destination = value.value().toString();
404  } else if (value.name() == QLatin1String("From")) {
405  d->sourceEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
406  } else if (value.name() == QLatin1String("ReplyTo")) {
407  d->replyEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
408  } else if (value.name() == QLatin1String("RelatesTo")) {
410  relationship.uri = (value.value().toString());
411  relationship.relationshipType = addressingNS + QLatin1String("/reply");
412  const auto &childAttributes = value.childValues().attributes();
413  for (const KDSoapValue &attr : childAttributes) {
414  if (attr.name() == QLatin1String("RelationshipType")) {
415  relationship.relationshipType = attr.value().toString();
416  }
417  }
418  d->relationships.append(relationship);
419  } else if (value.name() == QLatin1String("FaultTo")) {
420  d->faultEndpoint.setAddress(value.childValues().child(QLatin1String("Address")).value().toString());
421  } else if (value.name() == QLatin1String("ReferenceParameters")) {
422  d->referenceParameters = value.childValues();
423  } else if (value.name() == QLatin1String("Metadata")) {
424  d->metadata = value.childValues();
425  }
426 }
427 
428 QDebug operator<<(QDebug dbg, const KDSoapMessageAddressingProperties &msg)
429 {
430  dbg << msg.action() << msg.destination() << msg.sourceEndpoint().address() << msg.replyEndpoint().address() << msg.faultEndpoint().address()
431  << msg.messageID();
432 
433  return dbg;
434 }
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-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