QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
qgsserverexception.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsservervexception.h
3 -------------------
4 begin : January 11, 2017
5 copyright : (C) 2017 David Marteau
6 email : david dot marteau at 3liz dot com
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#include "qgsserverexception.h"
19
20#include <QDomDocument>
21
22// QgsServerException
23QgsServerException::QgsServerException( const QString &message, int responseCode )
24 : QgsException( message )
25 , mResponseCode( responseCode )
26{
27
28}
29
30QByteArray QgsServerException::formatResponse( QString &responseFormat ) const
31{
32 QDomDocument doc;
33 const QDomNode header = doc.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
34 doc.appendChild( header );
35
36 QDomElement root = doc.createElement( QStringLiteral( "ServerException" ) );
37 doc.appendChild( root );
38 root.appendChild( doc.createTextNode( what() ) );
39
40 responseFormat = QStringLiteral( "text/xml; charset=utf-8" );
41 return doc.toByteArray();
42}
43
44
45// QgsOgcServiceException
46QgsOgcServiceException:: QgsOgcServiceException( const QString &code, const QString &message, const QString &locator,
47 int responseCode, const QString &version )
48 : QgsServerException( message, responseCode )
49 , mCode( code )
50 , mMessage( message )
51 , mLocator( locator )
52 , mVersion( version )
53{
54}
55
56QByteArray QgsOgcServiceException::formatResponse( QString &responseFormat ) const
57{
58 QDomDocument doc;
59 const QDomNode header = doc.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
60 doc.appendChild( header );
61
62 QDomElement root = doc.createElement( QStringLiteral( "ServiceExceptionReport" ) );
63 root.setAttribute( QStringLiteral( "version" ), mVersion );
64 root.setAttribute( QStringLiteral( "xmlns" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
65 doc.appendChild( root );
66
67 QDomElement elem = doc.createElement( QStringLiteral( "ServiceException" ) );
68 elem.setAttribute( QStringLiteral( "code" ), mCode );
69 elem.appendChild( doc.createTextNode( mMessage ) );
70 root.appendChild( elem );
71
72 if ( ! mLocator.isEmpty() )
73 {
74 elem.setAttribute( QStringLiteral( "locator" ), mLocator );
75 }
76
77 responseFormat = QStringLiteral( "text/xml; charset=utf-8" );
78 return doc.toByteArray();
79}
80
81
82
Defines a QGIS exception class.
QString what() const
QgsOgcServiceException(const QString &code, const QString &message, const QString &locator=QString(), int responseCode=200, const QString &version=QStringLiteral("1.3.0"))
Construction.
QByteArray formatResponse(QString &responseFormat) const override
Formats the exception for sending to client.
Exception base class for server exceptions.
virtual QByteArray formatResponse(QString &responseFormat) const
Formats the exception for sending to client.
QgsServerException(const QString &message, int responseCode=500)
Constructor.