mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-12 17:50:41 +02:00
WIP: adding SoapRequests
This commit is contained in:
parent
42d2fd58d1
commit
7ebe6bb0ea
@ -39,6 +39,16 @@ void Request::appendData(const QByteArray &array)
|
|||||||
mResponseData += array;
|
mResponseData += array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Request::url() const
|
||||||
|
{
|
||||||
|
return mUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Request::setUrl(const QString &url)
|
||||||
|
{
|
||||||
|
mUrl = url;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray Request::responseData() const
|
QByteArray Request::responseData() const
|
||||||
{
|
{
|
||||||
return mResponseData;
|
return mResponseData;
|
||||||
|
|||||||
@ -13,13 +13,18 @@ public:
|
|||||||
Request() = default;
|
Request() = default;
|
||||||
~Request() override;
|
~Request() override;
|
||||||
Request(QString type, QString url, QByteArray responseData = QByteArray());
|
Request(QString type, QString url, QByteArray responseData = QByteArray());
|
||||||
QNetworkRequest networkRequest() const;
|
virtual QNetworkRequest networkRequest() const;
|
||||||
|
|
||||||
// Data handling data
|
// Data handling data
|
||||||
QByteArray requestData() const;
|
QByteArray requestData() const;
|
||||||
void setRequestData(const QByteArray &requestData);
|
void setRequestData(const QByteArray &requestData);
|
||||||
QByteArray responseData() const;
|
QByteArray responseData() const;
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
QString url() const;
|
||||||
|
void setUrl(const QString &url);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Authorization
|
// Authorization
|
||||||
QString userName() const;
|
QString userName() const;
|
||||||
@ -33,6 +38,7 @@ public:
|
|||||||
QString basicAuthorization() const;
|
QString basicAuthorization() const;
|
||||||
QString bearerAuthorization() const;
|
QString bearerAuthorization() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Data handling
|
// Data handling
|
||||||
void appendData(const QByteArray &array);
|
void appendData(const QByteArray &array);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ SOURCES += \
|
|||||||
$$PWD/loggermessage.cpp \
|
$$PWD/loggermessage.cpp \
|
||||||
$$PWD/requestmanager.cpp \
|
$$PWD/requestmanager.cpp \
|
||||||
$$PWD/request.cpp \
|
$$PWD/request.cpp \
|
||||||
|
$$PWD/soaprequest.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/core.h \
|
$$PWD/core.h \
|
||||||
@ -16,6 +17,7 @@ HEADERS += \
|
|||||||
$$PWD/loggermessage.h \
|
$$PWD/loggermessage.h \
|
||||||
$$PWD/requestmanager.h \
|
$$PWD/requestmanager.h \
|
||||||
$$PWD/request.h \
|
$$PWD/request.h \
|
||||||
|
$$PWD/soaprequest.h
|
||||||
|
|
||||||
# TODO: implement zlib compression
|
# TODO: implement zlib compression
|
||||||
# include (zlib.pri)
|
# include (zlib.pri)
|
||||||
|
|||||||
63
src/serversdk/soaprequest.cpp
Normal file
63
src/serversdk/soaprequest.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include "soaprequest.h"
|
||||||
|
|
||||||
|
namespace serversdk {
|
||||||
|
|
||||||
|
SoapRequest::SoapRequest(QString action, QString endpoint, QByteArray data)
|
||||||
|
: mSoapAction(action)
|
||||||
|
{
|
||||||
|
setUrl(endpoint);
|
||||||
|
setRequestData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkRequest SoapRequest::networkRequest() const
|
||||||
|
{
|
||||||
|
Q_ASSERT(!this->url().isEmpty());
|
||||||
|
QNetworkRequest request(QUrl(this->url()));
|
||||||
|
|
||||||
|
// Have to set header
|
||||||
|
QString header;
|
||||||
|
|
||||||
|
if (isSoapVersion12()) {
|
||||||
|
// qCDebug(soap) << "SOAP version: 1.2";
|
||||||
|
header = QString("application/soap+xml;charset=UTF-8;action=%2").arg(soapAction());
|
||||||
|
request.setRawHeader("Content-Type", header.toUtf8());
|
||||||
|
} else {
|
||||||
|
// qCDebug(soap) << "SOAP version: 1.1";
|
||||||
|
request.setRawHeader("Content-Type", "text/xml");
|
||||||
|
request.setRawHeader("SoapAction", soapAction().toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !userName().isEmpty() && !password().isEmpty() )
|
||||||
|
request.setRawHeader("Authorization", this->basicAuthorization().toUtf8());
|
||||||
|
// Enabled compression
|
||||||
|
request.setRawHeader("Accept-Encoding", "gzip, deflate");
|
||||||
|
|
||||||
|
// Enabling HTTP/2 ( not supported on Ubuntu 16.04 )
|
||||||
|
// request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true);
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SoapRequest::soapAction() const
|
||||||
|
{
|
||||||
|
return mSoapAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoapRequest::setSoapAction(const QString &soapAction)
|
||||||
|
{
|
||||||
|
mSoapAction = soapAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoapRequest::isSoapVersion12() const
|
||||||
|
{
|
||||||
|
return mSoapVersion12;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoapRequest::setSoapVersion12(bool soapVersion12)
|
||||||
|
{
|
||||||
|
mSoapVersion12 = soapVersion12;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace serversdk
|
||||||
24
src/serversdk/soaprequest.h
Normal file
24
src/serversdk/soaprequest.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "request.h"
|
||||||
|
|
||||||
|
namespace serversdk {
|
||||||
|
|
||||||
|
class SoapRequest : public Request
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SoapRequest(QString action, QString endpoint, QByteArray data);
|
||||||
|
QNetworkRequest networkRequest() const override;
|
||||||
|
|
||||||
|
QString soapAction() const;
|
||||||
|
void setSoapAction(const QString &soapAction);
|
||||||
|
bool isSoapVersion12() const;
|
||||||
|
void setSoapVersion12(bool isSoapVersion12);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString mSoapAction;
|
||||||
|
bool mSoapVersion12 = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace serversdk
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user