QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgswms.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswms.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6  (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
7  (C) 2016 by David Marteau
8  email : marco dot hugentobler at karto dot baug dot ethz dot ch
9  a dot pasotti at itopen dot it
10  david dot marteau at 3liz dot com
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 #include "qgsmodule.h"
23 #include "qgsdxfwriter.h"
24 #include "qgswmsserviceexception.h"
25 #include "qgswmsgetcapabilities.h"
26 #include "qgswmsgetmap.h"
27 #include "qgswmsgetstyles.h"
28 #include "qgswmsgetcontext.h"
30 #include "qgswmsgetprint.h"
31 #include "qgswmsgetfeatureinfo.h"
32 #include "qgswmsdescribelayer.h"
34 #include "qgswmsparameters.h"
35 
36 #define QSTR_COMPARE( str, lit )\
37  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
38 
39 namespace QgsWms
40 {
41 
48  class Service: public QgsService
49  {
50  public:
51 
57  Service( const QString &version, QgsServerInterface *serverIface )
58  : mVersion( version )
59  , mServerIface( serverIface )
60  {}
61 
62  QString name() const override { return QStringLiteral( "WMS" ); }
63  QString version() const override { return mVersion; }
64 
65  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
66  const QgsProject *project ) override
67  {
68  const QgsWmsParameters parameters( QUrlQuery( request.url() ) );
69 
70  QString version = parameters.version();
71  if ( version.isEmpty() )
72  {
73  // WMTVER needs to be supported by WMS 1.1.1 for backwards
74  // compatibility with WMS 1.0.0
75  version = parameters.wmtver();
76  }
77 
78  // Set the default version
79  if ( version.isEmpty() || !parameters.versionIsValid( version ) )
80  {
81  version = mVersion;
82  }
83 
84  // Get the request
85  const QString req = parameters.request();
86  if ( req.isEmpty() )
87  {
89  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
90  }
91 
92  if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
93  && QSTR_COMPARE( req, "capabilities" ) )
94  || QSTR_COMPARE( req, "GetCapabilities" ) )
95  {
96  writeGetCapabilities( mServerIface, project, version, request, response, false );
97  }
98  else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
99  {
100  //getProjectSettings extends WMS 1.3.0 capabilities
101  version = QStringLiteral( "1.3.0" );
102  writeGetCapabilities( mServerIface, project, version, request, response, true );
103  }
104  else if ( QSTR_COMPARE( req, "GetMap" ) )
105  {
106  QString format = parameters.formatAsString();
107  if QSTR_COMPARE( format, "application/dxf" )
108  {
109  writeAsDxf( mServerIface, project, version, request, response );
110  }
111  else
112  {
113  writeGetMap( mServerIface, project, version, request, response );
114  }
115  }
116  else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
117  {
118  writeGetFeatureInfo( mServerIface, project, version, request, response );
119  }
120  else if ( QSTR_COMPARE( req, "GetContext" ) )
121  {
122  writeGetContext( mServerIface, project, version, request, response );
123  }
124  else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
125  {
126  writeGetSchemaExtension( response );
127  }
128  else if ( QSTR_COMPARE( req, "GetStyle" ) )
129  {
130  writeGetStyle( mServerIface, project, version, request, response );
131  }
132  else if ( QSTR_COMPARE( req, "GetStyles" ) )
133  {
134  writeGetStyles( mServerIface, project, version, request, response );
135  }
136  else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
137  {
138  writeDescribeLayer( mServerIface, project, version, request, response );
139  }
140  else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
141  {
142  writeGetLegendGraphics( mServerIface, project, version, request, response );
143  }
144  else if ( QSTR_COMPARE( req, "GetPrint" ) )
145  {
146  writeGetPrint( mServerIface, project, version, request, response );
147  }
148  else
149  {
150  // Operation not supported
152  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
153  }
154  }
155 
156  private:
157  QString mVersion;
158  QgsServerInterface *mServerIface = nullptr;
159  };
160 } // namespace QgsWms
161 
169 {
170  public:
171  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
172  {
173  QgsDebugMsg( QStringLiteral( "WMSModule::registerSelf called" ) );
174  registry.registerService( new QgsWms::Service( "1.3.0", serverIface ) );
175  }
176 };
177 
178 
179 // Entry points
181 {
182  static QgsWmsModule sModule;
183  return &sModule;
184 }
186 {
187  // Nothing to do
188 }
QgsWms::writeGetMap
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsgetmap.cpp:48
QgsServiceModule
Class defining the service module interface for QGIS server services.
Definition: qgsservicemodule.h:41
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:336
QGISEXTERN
#define QGISEXTERN
Definition: qgis.h:770
QgsWms::writeDescribeLayer
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsdescribelayer.cpp:48
QgsWms::QgsServiceException
Exception class for WMS service exceptions.
Definition: qgswmsserviceexception.h:49
QgsWms::writeAsDxf
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgsdxfwriter.cpp:39
QgsWms::QgsWmsParameters::wmtver
QString wmtver() const
Returns WMTVER parameter or an empty string if not defined.
Definition: qgswmsparameters.cpp:1902
QgsServerParameters::request
QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:527
QSTR_COMPARE
#define QSTR_COMPARE(str, lit)
Definition: qgswms.cpp:36
QgsWms::Service::Service
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition: qgswms.cpp:57
QgsService
Definition: qgsservice.h:39
QgsServiceRegistry::registerService
void registerService(QgsService *service)
Register a service by its name and version.
Definition: qgsserviceregistry.cpp:118
qgswmsgetcapabilities.h
QgsServerRequest
Definition: qgsserverrequest.h:38
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsWms::writeGetFeatureInfo
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
Definition: qgswmsgetfeatureinfo.cpp:44
QgsWms::writeGetSchemaExtension
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.
Definition: qgswmsgetschemaextension.cpp:49
QgsProject
Definition: qgsproject.h:92
qgswmsgetfeatureinfo.h
QgsWms::Service::version
QString version() const override
Definition: qgswms.cpp:63
QgsServerParameters::version
QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:477
QgsWms::Service::executeRequest
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswms.cpp:65
qgswmsdescribelayer.h
QgsWms::Service
OGC web service specialized for WMS.
Definition: qgswms.cpp:48
qgswmsgetschemaextension.h
QgsWms::writeGetStyle
void writeGetStyle(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyle response.
Definition: qgswmsgetstyles.cpp:95
QgsWms::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
Definition: qgswmsgetcapabilities.cpp:110
QgsWmsModule::registerSelf
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswms.cpp:171
QGS_ServiceModule_Exit
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswms.cpp:185
QGS_ServiceModule_Init
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswms.cpp:180
QgsWms::Service::name
QString name() const override
Definition: qgswms.cpp:62
qgswmsparameters.h
qgswmsgetlegendgraphics.h
qgswmsgetmap.h
QgsWms::writeGetContext
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetContext response.
Definition: qgswmsgetcontext.cpp:70
QgsWms
WMS implementation.
Definition: qgsdxfwriter.cpp:22
qgswmsgetcontext.h
QgsWms::writeGetLegendGraphics
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
Definition: qgswmsgetlegendgraphics.cpp:56
QgsWms::writeGetPrint
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetPrint response.
Definition: qgswmsgetprint.cpp:45
qgswmsgetstyles.h
QgsServiceRegistry
Definition: qgsserviceregistry.h:49
qgswmsgetprint.h
QgsWms::QgsServiceException::OGC_OperationNotSupported
@ OGC_OperationNotSupported
Definition: qgswmsserviceexception.h:73
QgsServerRequest::url
QUrl url() const
Definition: qgsserverrequest.cpp:65
qgsdxfwriter.h
qgsmodule.h
QgsWms::QgsWmsParameters::formatAsString
QString formatAsString() const
Returns FORMAT parameter as a string.
Definition: qgswmsparameters.cpp:779
QgsWms::writeGetStyles
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyles response.
Definition: qgswmsgetstyles.cpp:61
qgswmsserviceexception.h
QgsWms::QgsWmsParameters::versionIsValid
bool versionIsValid(const QString version) const
Returns true if version is valid, false otherwise.
Definition: qgswmsparameters.cpp:774
QgsServerInterface
Definition: qgsserverinterface.h:60
QgsServerResponse
Definition: qgsserverresponse.h:43
QgsWmsModule
Module specialized for WMS service.
Definition: qgswms.cpp:168