QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
26 #include <QDomDocument>
31 : mExceptionRaised( false )
33 , mResponse( response )
44 return mExceptionRaised;
64 return mResponse.
header( name );
84 return mRequest.
header( name );
111 return mResponse.
data();
116 return mRequest.
data();
121 return mRequest.
url().toString();
126 return mRequest.
url().path();
148 mExceptionRaised =
true;
149 mResponse.
write( ex );
152 void QgsRequestHandler::setupParameters()
157 const QString infoFormat = parameters.value( QStringLiteral(
"INFO_FORMAT" ) );
158 if ( !infoFormat.isEmpty() )
160 mFormat = infoFormat;
164 mFormatString = parameters.value( QStringLiteral(
"FORMAT" ) );
165 QString formatString = mFormatString;
166 if ( !formatString.isEmpty() )
169 if ( formatString.contains( QLatin1String(
"image/png" ), Qt::CaseInsensitive ) || formatString.compare( QLatin1String(
"png" ), Qt::CaseInsensitive ) == 0 )
171 formatString = QStringLiteral(
"PNG" );
173 else if ( formatString.contains( QLatin1String(
"image/jpeg" ), Qt::CaseInsensitive ) || formatString.contains( QLatin1String(
"image/jpg" ), Qt::CaseInsensitive )
174 || formatString.compare( QLatin1String(
"jpg" ), Qt::CaseInsensitive ) == 0 )
176 formatString = QStringLiteral(
"JPG" );
178 else if ( formatString.compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
180 formatString = QStringLiteral(
"SVG" );
182 else if ( formatString.contains( QLatin1String(
"pdf" ), Qt::CaseInsensitive ) )
184 formatString = QStringLiteral(
"PDF" );
187 mFormat = formatString;
199 if ( mRequest.
header( QStringLiteral(
"Content-Type" ) ).contains( QStringLiteral(
"json" ) ) )
205 QString inputString( mRequest.
data() );
210 if ( !doc.setContent( inputString,
true, &errorMsg, &line, &column ) )
213 QgsMessageLog::logMessage( QStringLiteral(
"Error parsing post data as XML: at line %1, column %2: %3. Assuming urlencoded query string sent in the post body." )
214 .arg( line ).arg( column ).arg( errorMsg ),
215 QStringLiteral(
"Server" ), Qgis::MessageLevel::Warning );
219 typedef QPair<QString, QString> pair_t;
220 const QUrlQuery query( inputString );
221 const QList<pair_t> items = query.queryItems();
222 for (
const pair_t &pair : items )
234 const QDomElement docElem = doc.documentElement();
236 mRequest.
setParameter( QStringLiteral(
"REQUEST" ), docElem.tagName() );
239 const QDomNamedNodeMap map = docElem.attributes();
240 for (
int i = 0 ; i < map.length() ; ++i )
242 if ( map.item( i ).isNull() )
245 const QDomNode attrNode = map.item( i );
246 const QDomAttr attr = attrNode.toAttr();
250 const QString attrName = attr.name();
251 if ( attrName.startsWith(
"xmlns" ) || attrName.startsWith(
"xsi:" ) )
254 mRequest.
setParameter( attrName.toUpper(), attr.value() );
256 mRequest.
setParameter( QStringLiteral(
"REQUEST_BODY" ), inputString.replace(
'+', QLatin1String(
"%2B" ) ) );
268 if ( !( key.isEmpty() || value.isEmpty() ) )
272 if ( key.compare( QLatin1String(
"MAP" ), Qt::CaseInsensitive ) == 0 )
274 QgsMessageLog::logMessage( QStringLiteral(
"Changing the 'MAP' parameter will have no effect on config path: use QgsSerververInterface::setConfigFilePath instead" ),
275 QStringLiteral(
"Server" ), Qgis::MessageLevel::Warning );
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
void removeRequestHeader(const QString &name)
Remove an HTTP request header.
void setHeader(const QString &name, const QString &value)
Set an header.
bool headersSent() const
Returns true if the HTTP headers were already sent to the client.
void clear()
Clears the response body and headers.
QByteArray body() const
Returns the response body data.
virtual void flush() SIP_THROW(QgsServerException)
Flushes the current output buffer to the network.
QString url() const
Returns the request url.
virtual void truncate()=0
Truncate data.
virtual void clear()=0
Reset all headers and content for this response.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
void clearBody()
Clear response buffer.
void removeHeader(const QString &name)
Remove an header.
virtual int statusCode() const =0
Returns the http status code.
QMap< QString, QString > Parameters
virtual void removeParameter(const QString &key)
Remove a parameter.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
QString path() const
Returns the path component of the request URL.
QString responseHeader(const QString &name) const
Retrieve response header value.
virtual void setParameter(const QString &key, const QString &value)
Set a parameter.
QMap< QString, QString > requestHeaders() const
Returns the the Request headers.
QgsServerRequest::Method method() const
void appendBody(const QByteArray &body)
Sets the info format string such as "text/xml".
virtual QString header(const QString &key) const =0
Returns the header value.
virtual void setStatusCode(int code)=0
Set the http status code.
virtual void removeHeader(const QString &key)=0
Clear header Undo a previous 'setHeader' call.
void parseInput()
Parses the input and creates a request neutral Parameter/Value map.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void setRequestHeader(const QString &name, const QString &value)
Sets an HTTP request header.
virtual QString header(const QString &name) const
Returns the header value.
void sendResponse()
Send out HTTP headers and flush output buffer.
void setStatusCode(int code)
Sets response http status code.
virtual QByteArray data() const =0
Gets the data written so far.
void setResponseHeader(const QString &name, const QString &value)
Sets an HTTP response header.
bool exceptionRaised() const
Pointer to last raised exception.
QMap< QString, QString > parameterMap() const
Returns the parsed parameters as a key-value pair, to modify a parameter setParameter( const QString ...
virtual QByteArray data() const
Returns post/put data Check for QByteArray::isNull() to check if data is available.
virtual bool headersSent() const =0
Returns true if the headers have already been sent.
void setServiceException(const QgsServerException &ex)
Allow plugins to return a QgsMapServiceException.
Exception base class for server exceptions.
QString parameter(const QString &key, const QString &defaultValue=QString()) const
Gets a parameter value.
int statusCode() const
Returns the response http status code.
QString requestHeader(const QString &name) const
Retrieve request header value.
void removeResponseHeader(const QString &name)
Remove an HTTP response header.
QgsRequestHandler(QgsServerRequest &request, QgsServerResponse &response)
Constructor.
QByteArray data() const
Returns the request POST data (can be null)
void setParameter(const QString &key, const QString &value)
Sets a request parameter.
void removeParameter(const QString &key)
Remove a request parameter.
virtual QMap< QString, QString > headers() const =0
Returns the header value.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QString parameter(const QString &key) const
Returns a request parameter.
QMap< QString, QString > responseHeaders() const
Returns the response headers.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
QMap< QString, QString > headers() const
Returns the header map.