QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgswfs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswfs.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6  (C) 2012 by RenĂ©-Luc D'Hont ( parts from qgswmshandler)
7  (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
8  (C) 2016 by David Marteau
9  email : marco dot hugentobler at karto dot baug dot ethz dot ch
10  a dot pasotti at itopen dot it
11  david dot marteau at 3liz dot com
12  ***************************************************************************/
13 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 #include "qgsmodule.h"
24 #include "qgswfsutils.h"
25 #include "qgswfsgetcapabilities.h"
27 #include "qgswfsgetfeature.h"
29 #include "qgswfstransaction.h"
31 
32 #define QSTR_COMPARE( str, lit )\
33  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
34 
35 namespace QgsWfs
36 {
37 
44  class Service: public QgsService
45  {
46  public:
47 
52  Service( QgsServerInterface *serverIface )
53  : mServerIface( serverIface )
54  {}
55 
56  QString name() const override { return QStringLiteral( "WFS" ); }
57  QString version() const override { return implementationVersion(); }
58 
59  bool allowMethod( QgsServerRequest::Method method ) const override
60  {
61  return method == QgsServerRequest::GetMethod || method == QgsServerRequest::PostMethod;
62  }
63 
64  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
65  const QgsProject *project ) override
66  {
67  const QgsWfsParameters params( QUrlQuery( request.url() ) );
68 
69  // Set the default version
70  QString versionString = params.version();
71  if ( versionString.isEmpty() )
72  {
73  versionString = version(); // defined in qgswfsutils.h
74  }
75 
76  // Get the request
77  const QString req = params.request();
78  if ( req.isEmpty() )
79  {
80  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
81  QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
82  }
83 
84  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
85  {
86  // Supports WFS 1.0.0
87  if ( QSTR_COMPARE( versionString, "1.0.0" ) )
88  {
89  v1_0_0::writeGetCapabilities( mServerIface, project, versionString, request, response );
90  }
91  else
92  {
93  writeGetCapabilities( mServerIface, project, versionString, request, response );
94  }
95  }
96  else if ( QSTR_COMPARE( req, "GetFeature" ) )
97  {
98  writeGetFeature( mServerIface, project, versionString, request, response );
99  }
100  else if ( QSTR_COMPARE( req, "DescribeFeatureType" ) )
101  {
102  writeDescribeFeatureType( mServerIface, project, versionString, request, response );
103  }
104  else if ( QSTR_COMPARE( req, "Transaction" ) )
105  {
106  // Supports WFS 1.0.0
107  if ( QSTR_COMPARE( versionString, "1.0.0" ) )
108  {
109  v1_0_0::writeTransaction( mServerIface, project, versionString, request, response );
110  }
111  else
112  {
113  writeTransaction( mServerIface, project, versionString, request, response );
114  }
115  }
116  else
117  {
118  // Operation not supported
119  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
120  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
121  }
122  }
123 
124  private:
125  QgsServerInterface *mServerIface = nullptr;
126  };
127 
128 
129 } // namespace QgsWfs
130 
138 {
139  public:
140  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
141  {
142  QgsDebugMsg( QStringLiteral( "WFSModule::registerSelf called" ) );
143  registry.registerService( new QgsWfs::Service( serverIface ) );
144  }
145 };
146 
147 
148 // Entry points
150 {
151  static QgsWfsModule module;
152  return &module;
153 }
155 {
156  // Nothing to do
157 }
OGC web service specialized for WFS.
Definition: qgswfs.cpp:44
void writeGetFeature(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetFeature response.
Service(QgsServerInterface *serverIface)
Constructor for WFS service.
Definition: qgswfs.cpp:52
QString name() const override
Definition: qgswfs.cpp:56
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
Class defining the service module interface for QGIS server services.
QString version() const override
Definition: qgswfs.cpp:57
void writeDescribeFeatureType(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
Method
HTTP Method (or equivalent) used for the request.
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswfs.cpp:149
bool allowMethod(QgsServerRequest::Method method) const override
Returns true if the given method is supported for that service.
Definition: qgswfs.cpp:59
QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
WMS implementation.
Definition: qgswfs.cpp:35
Module specialized for WFS service.
Definition: qgswfs.cpp:137
QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
Reads and writes project states.
Definition: qgsproject.h:89
QString implementationVersion()
Returns the highest version supported by this implementation.
Definition: qgswfsutils.cpp:33
#define QSTR_COMPARE(str, lit)
Definition: qgswfs.cpp:32
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswfs.cpp:154
void registerService(QgsService *service)
Register a service by its name and version.
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:39
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
QgsServiceRegistry Class defining the registry manager for QGIS server services.
Exception class for WFS service exceptions.
#define QGISEXTERN
Definition: qgis.h:633
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswfs.cpp:64
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Provides an interface to retrieve and manipulate WFS parameters received from the client...
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswfs.cpp:140