QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsrequesthandler.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  qgsrequesthandler.h
4  abstraction for reading from/ writing to a request datasource
5  -------------------
6  begin : May 16, 2006
7  copyright : (C) 2006 by Marco Hugentobler
8  (C) 2014 by Alessandro Pasotti
9  email : marco dot hugentobler at karto dot baug dot ethz dot ch
10  a dot pasotti at itopen dot it
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef QGSREQUESTHANDLER_H
23 #define QGSREQUESTHANDLER_H
24 
25 //Needed for HAVE_SERVER_PYTHON_PLUGINS
26 #include "qgsconfig.h"
27 
28 #include <QMap>
29 #include <QString>
30 #include <QStringList>
31 #include <QPair>
32 
33 #ifdef HAVE_SERVER_PYTHON_PLUGINS
34 #include "qgsserverfilter.h"
35 #endif
36 
37 class QDomDocument;
38 class QImage;
40 
49 {
50 
51  public:
52 
54  : mHeadersSent( false )
55  , mException( nullptr )
56  {}
57  virtual ~QgsRequestHandler() {}
61  virtual void parseInput() = 0;
65  virtual void setGetMapResponse( const QString& service, QImage* img, int imageQuality ) = 0;
67  virtual void setGetCapabilitiesResponse( const QDomDocument& doc ) = 0;
69  virtual void setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) = 0;
71  virtual void setServiceException( QgsMapServiceException ex ) = 0;
73  virtual void setXmlResponse( const QDomDocument& doc ) = 0;
75  virtual void setXmlResponse( const QDomDocument& doc, const QString& mimeType ) = 0;
77  virtual void setGetPrintResponse( QByteArray* b ) = 0;
79  virtual bool startGetFeatureResponse( QByteArray* ba, const QString& infoFormat ) = 0;
81  virtual void setGetFeatureResponse( QByteArray* ba ) = 0;
82 
84  virtual void endGetFeatureResponse( QByteArray* ba ) = 0;
86  virtual void setGetCoverageResponse( QByteArray* ba ) = 0;
87  virtual void setDefaultHeaders() {}
89  virtual void setHeader( const QString &name, const QString &value ) = 0;
91  virtual int removeHeader( const QString &name ) = 0;
93  virtual void clearHeaders() = 0;
95  virtual void appendBody( const QByteArray &body ) = 0;
97  virtual void clearBody() = 0;
99  virtual QByteArray body() { return mBody; }
101  virtual void setInfoFormat( const QString &format ) = 0;
103  virtual bool responseReady() const = 0;
105  virtual void sendResponse() = 0;
107  virtual bool exceptionRaised() const = 0;
114  virtual void setParameter( const QString &key, const QString &value ) = 0;
116  virtual int removeParameter( const QString &key ) = 0;
118  virtual QString parameter( const QString &key ) const = 0;
120  QString format() const { return mFormat; }
122  QString infoFormat() const { return mInfoFormat; }
124  bool headersSent() { return mHeadersSent; }
125 #ifdef HAVE_SERVER_PYTHON_PLUGINS
126 
129  virtual void setPluginFilters( QgsServerFiltersMap pluginFilters ) = 0;
130 #endif
131 
134 
135  protected:
137  virtual void sendHeaders() = 0;
138 
140  virtual void sendBody() = 0;
141 #ifdef HAVE_SERVER_PYTHON_PLUGINS
142  QgsServerFiltersMap mPluginFilters;
143 #endif
144  QByteArray mBody; // The response payload
147  QString mFormatString; //format string as it is passed in the request (with base)
151  QgsMapServiceException* mException; // Stores the exception
156  // TODO: if HAVE_SERVER_PYTHON
159  // QByteArray mResponseHeader;
160  // QByteArray mResponseBody;
161 };
162 
163 #endif
QString format() const
Return the requested format string.
virtual void setGetCapabilitiesResponse(const QDomDocument &doc)=0
virtual QByteArray body()
Return the response body.
virtual void setServiceException(QgsMapServiceException ex)=0
Allow plugins to return a QgsMapServiceException.
virtual bool responseReady() const =0
Check whether there is any header set or the body is not empty.
virtual int removeParameter(const QString &key)=0
Remove a request parameter.
virtual void setGetCoverageResponse(QByteArray *ba)=0
virtual void sendHeaders()=0
virtual void setXmlResponse(const QDomDocument &doc)=0
bool headersSent()
Return true if the HTTP headers were already sent to the client.
virtual void clearBody()=0
Clears the response body.
virtual void endGetFeatureResponse(QByteArray *ba)=0
virtual bool exceptionRaised() const =0
Pointer to last raised exception.
QString infoFormat() const
Return the mime type for the response.
virtual void setHeader(const QString &name, const QString &value)=0
Set an HTTP header.
virtual ~QgsRequestHandler()
virtual void setGetMapResponse(const QString &service, QImage *img, int imageQuality)=0
Sends the map image back to the client.
QMap< QString, QString > mParameterMap
virtual void setGetFeatureResponse(QByteArray *ba)=0
QMap< QString, QString > mHeaders
Response headers.
virtual void parseInput()=0
Parses the input and creates a request neutral Parameter/Value map.
virtual void setGetFeatureInfoResponse(const QDomDocument &infoDoc, const QString &infoFormat)=0
virtual void clearHeaders()=0
Delete all HTTP headers.
This class is an interface hiding the details of reading input and writing output from/to a wms reque...
QgsMapServiceException * mException
virtual void setParameter(const QString &key, const QString &value)=0
Set a request parameter.
QMap< QString, QString > parameterMap()
Return a copy of the parsed parameters as a key-value pair, to modify a parameter setParameter( const...
virtual void appendBody(const QByteArray &body)=0
Append the bytestream to response body.
QString mFormat
This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g.
virtual void setInfoFormat(const QString &format)=0
Set the info format string such as "text/xml".
virtual QPair< QByteArray, QByteArray > getResponse()=0
virtual QString parameter(const QString &key) const =0
Return a request parameter.
virtual int removeHeader(const QString &name)=0
Remove an HTTP header.
virtual void sendBody()=0
virtual void setGetPrintResponse(QByteArray *b)=0
virtual void sendResponse()=0
Send out HTTP headers and flush output buffer.
Exception class for WMS service exceptions.
virtual void setDefaultHeaders()
virtual bool startGetFeatureResponse(QByteArray *ba, const QString &infoFormat)=0