QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgswmsserviceexception.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserviceexception.h
3  ------------------------
4  begin : June 13, 2006
5  copyright : (C) 2006 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSWMSSERVICEEXCEPTION_H
19 #define QGSWMSSERVICEEXCEPTION_H
20 
21 #include <QString>
22 #include <QMetaEnum>
23 
24 #include "qgsserverexception.h"
25 #include "qgswmsparameters.h"
26 
27 namespace QgsWms
28 {
29 
36  class QgsServiceException : public QgsOgcServiceException
37  {
38  Q_GADGET
39 
40  public:
41 
47  enum ExceptionCode
48  {
58  OGC_InvalidPoint, // new in WMS 1.3.0
59  OGC_InvalidCRS, // new in WMS 1.3.0
60  OGC_OperationNotSupported, // new in WMS 1.3.0
63  };
64  Q_ENUM( ExceptionCode )
65 
66 
73  QgsServiceException( const QString &code, const QString &message, const QString &locator = QString(),
74  int responseCode = 200 )
75  : QgsOgcServiceException( code, message, locator, responseCode, QStringLiteral( "1.3.0" ) )
76  {}
77 
84  QgsServiceException( const QString &code, const QString &message, int responseCode )
85  : QgsOgcServiceException( code, message, QString(), responseCode, QStringLiteral( "1.3.0" ) )
86  {}
87 
96  : QgsServiceException( formatCode( code ), message, QString(), responseCode )
97  {}
98 
107  : QgsServiceException( formatCode( code ), formatMessage( code, parameter ), QString(), responseCode )
108  {}
109 
110  private:
111  static QString formatMessage( ExceptionCode code, const QgsWmsParameter &parameter )
112  {
113  const QString name = parameter.name();
114  QString message;
115 
116  switch ( code )
117  {
119  {
120  message = QStringLiteral( "The %1 parameter is missing." ).arg( name );
121  break;
122  }
124  {
125  message = QStringLiteral( "The %1 parameter is invalid." ).arg( name );
126  break;
127  }
128  case OGC_InvalidFormat:
129  {
130  message = QStringLiteral( "The format '%1' from %2 is not supported." ).arg( parameter.toString(), name );
131  break;
132  }
133  case OGC_InvalidSRS:
134  {
135  message = QStringLiteral( "The SRS is not valid." );
136  break;
137  }
138  case OGC_InvalidCRS:
139  {
140  message = QStringLiteral( "The CRS is not valid." );
141  break;
142  }
143  case OGC_LayerNotDefined:
144  {
145  message = QStringLiteral( "The layer '%1' does not exist." ).arg( parameter.toString() );
146  break;
147  }
149  {
150  message = QStringLiteral( "The layer '%1' is not queryable." ).arg( parameter.toString() );
151  break;
152  }
153  case OGC_InvalidPoint:
154  {
155  message = QStringLiteral( "The point '%1' from '%2' is invalid." ).arg( parameter.toString(), name );
156  break;
157  }
158  case OGC_StyleNotDefined:
164  {
165  break;
166  }
167  }
168 
169  return message;
170  }
171 
172  static QString formatCode( ExceptionCode code )
173  {
174  // get key as a string from enum
175  const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServiceException::ExceptionCode>() );
176  QString key = metaEnum.valueToKey( code );
177 
178  // remove prefix
179  key.replace( QStringLiteral( "OGC_" ), QString() );
180  key.replace( QStringLiteral( "QGIS_" ), QString() );
181 
182  return key;
183  }
184  };
185 
192  class QgsSecurityException: public QgsServiceException
193  {
194  public:
195 
202  QgsSecurityException( const QString &message, const QString &locator = QString() )
203  : QgsServiceException( QStringLiteral( "Security" ), message, locator, 403 )
204  {}
205  };
206 
214  {
215  public:
216 
224  : QgsServiceException( code, message, 400 )
225  {}
226 
234  : QgsServiceException( code, parameter, 400 )
235  {}
236  };
237 } // namespace QgsWms
238 
239 #endif
QgsWms::QgsServiceException::QGIS_InvalidParameterValue
@ QGIS_InvalidParameterValue
Definition: qgswmsserviceexception.h:75
QgsWms::QgsBadRequestException::QgsBadRequestException
QgsBadRequestException(ExceptionCode code, const QString &message)
Constructor for QgsBadRequestException (HTTP error code 400).
Definition: qgswmsserviceexception.h:236
QgsWms::QgsWmsParameter::name
QString name() const
Returns the name of the parameter.
Definition: qgswmsparameters.cpp:194
QgsWms::QgsServiceException
Exception class for WMS service exceptions.
Definition: qgswmsserviceexception.h:49
QgsWms::QgsServiceException::OGC_LayerNotQueryable
@ OGC_LayerNotQueryable
Definition: qgswmsserviceexception.h:66
QgsOgcServiceException::locator
QString locator() const
Returns the locator.
Definition: qgsserverexception.h:100
QgsWms::QgsServiceException::OGC_InvalidCRS
@ OGC_InvalidCRS
Definition: qgswmsserviceexception.h:72
QgsOgcServiceException::code
QString code() const
Returns the exception code.
Definition: qgsserverexception.h:97
QgsWms::QgsServiceException::OGC_CurrentUpdateSequence
@ OGC_CurrentUpdateSequence
Definition: qgswmsserviceexception.h:67
QgsWms::QgsServiceException::OGC_InvalidFormat
@ OGC_InvalidFormat
Definition: qgswmsserviceexception.h:62
QgsWms::QgsSecurityException::QgsSecurityException
QgsSecurityException(const QString &message, const QString &locator=QString())
Constructor for QgsSecurityException (HTTP error code 403 with Security code name).
Definition: qgswmsserviceexception.h:215
QgsWms::QgsServiceException::OGC_InvalidDimensionValue
@ OGC_InvalidDimensionValue
Definition: qgswmsserviceexception.h:70
QgsServerException::responseCode
int responseCode() const
Definition: qgsserverexception.h:55
QgsWms::QgsServiceException::OGC_MissingDimensionValue
@ OGC_MissingDimensionValue
Definition: qgswmsserviceexception.h:69
QgsWms::QgsServiceException::OGC_LayerNotDefined
@ OGC_LayerNotDefined
Definition: qgswmsserviceexception.h:64
QgsWms::QgsServiceException::OGC_InvalidPoint
@ OGC_InvalidPoint
Definition: qgswmsserviceexception.h:71
QgsServerParameterDefinition::toString
QString toString(bool defaultValue=false) const
Converts the parameter into a string.
Definition: qgsserverparameters.cpp:65
QgsWms::QgsServiceException::QGIS_MissingParameterValue
@ QGIS_MissingParameterValue
Definition: qgswmsserviceexception.h:74
QgsWms::QgsServiceException::OGC_StyleNotDefined
@ OGC_StyleNotDefined
Definition: qgswmsserviceexception.h:65
QgsWms::QgsServiceException::ExceptionCode
ExceptionCode
Exception codes as defined in OGC scpecifications for WMS 1.1.1 and WMS 1.3.0.
Definition: qgswmsserviceexception.h:60
QgsOgcServiceException
Exception base class for service exceptions.
Definition: qgsserverexception.h:82
qgswmsparameters.h
QgsWms::QgsServiceException::OGC_InvalidSRS
@ OGC_InvalidSRS
Definition: qgswmsserviceexception.h:63
QgsWms::QgsServiceException::QgsServiceException
QgsServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200)
Constructor for QgsServiceException.
Definition: qgswmsserviceexception.h:86
QgsWms
WMS implementation.
Definition: qgsdxfwriter.cpp:22
QgsWms::QgsBadRequestException
Exception thrown in case of malformed request.
Definition: qgswmsserviceexception.h:226
QgsOgcServiceException::message
QString message() const
Returns the exception message.
Definition: qgsserverexception.h:94
QgsWms::QgsServiceException::OGC_OperationNotSupported
@ OGC_OperationNotSupported
Definition: qgswmsserviceexception.h:73
QgsWms::QgsServiceException::OGC_InvalidUpdateSequence
@ OGC_InvalidUpdateSequence
Definition: qgswmsserviceexception.h:68
QgsWms::QgsWmsParameter
WMS parameter received from the client.
Definition: qgswmsparameters.h:111
qgsserverexception.h