Skip to content
Permalink
Browse files

Merge pull request #3985 from dmarteau/revisit_server_exceptions

Server: revisit server exceptions
  • Loading branch information
rldhont committed Jan 16, 2017
2 parents b340d7b + 8b0526d commit 474252a6f3297c7dd80c56cbbe9661e600b80734
Showing with 552 additions and 528 deletions.
  1. +3 −42 python/server/qgsrequesthandler.sip
  2. +56 −0 python/server/qgsserverexception.sip
  3. +5 −0 python/server/qgsserverresponse.sip
  4. +1 −0 python/server/server.sip
  5. +1 −2 src/server/CMakeLists.txt
  6. +5 −5 src/server/qgsfcgiserverresponse.cpp
  7. +4 −4 src/server/qgsfcgiserverresponse.h
  8. +0 −84 src/server/qgsmapserverutils.cpp
  9. +0 −32 src/server/qgsmapserverutils.h
  10. +8 −9 src/server/qgsmapserviceexception.h
  11. +6 −24 src/server/qgsrequesthandler.cpp
  12. +3 −3 src/server/qgsrequesthandler.h
  13. +89 −76 src/server/qgsserver.cpp
  14. +77 −0 src/server/qgsserverexception.cpp
  15. +84 −0 src/server/qgsserverexception.h
  16. +0 −1 src/server/qgsserverplugins.cpp
  17. +19 −1 src/server/qgsserverresponse.cpp
  18. +7 −0 src/server/qgsserverresponse.h
  19. +4 −6 src/server/services/wms/qgswms.cpp
  20. +9 −15 src/server/services/wms/qgswmsdescribelayer.cpp
  21. +8 −14 src/server/services/wms/qgswmsgetcapabilities.cpp
  22. +11 −16 src/server/services/wms/qgswmsgetcontext.cpp
  23. +5 −13 src/server/services/wms/qgswmsgetfeatureinfo.cpp
  24. +13 −16 src/server/services/wms/qgswmsgetlegendgraphics.cpp
  25. +8 −14 src/server/services/wms/qgswmsgetmap.cpp
  26. +34 −39 src/server/services/wms/qgswmsgetprint.cpp
  27. +9 −15 src/server/services/wms/qgswmsgetschemaextension.cpp
  28. +10 −16 src/server/services/wms/qgswmsgetstyle.cpp
  29. +4 −10 src/server/services/wms/qgswmsgetstyles.cpp
  30. +33 −33 src/server/services/wms/qgswmsservertransitional.cpp
  31. +32 −7 src/server/{qgsmapserviceexception.cpp → services/wms/qgswmsserviceexception.h}
  32. +3 −26 src/server/services/wms/qgswmsutils.cpp
  33. +1 −5 src/server/services/wms/qgswmsutils.h
@@ -20,45 +20,14 @@
class QgsRequestHandler /Abstract/
{
%TypeHeaderCode
#include "qgsmapserviceexception.h"
#include "qgsserverexception.h"
#include "qgsrequesthandler.h"
%End

public:

/** Parses the input and creates a request neutral Parameter/Value map
* @note not available in Python bindings
*/
// virtual void parseInput() = 0;

/** Sends the map image back to the client
* @note not available in Python bindings
*/
// virtual void setGetMapResponse( const QString& service, QImage* img, int imageQuality ) = 0;

//! @note not available in Python bindings
// virtual void setGetCapabilitiesResponse( const QDomDocument& doc ) = 0;

//! @note not available in Python bindings
// virtual void setGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) = 0;

/** Allow plugins to return a QgsMapServiceException*/
void setServiceException( const QgsMapServiceException& ex /Transfer/ );

//! @note not available in Python bindings
// virtual void setXmlResponse( const QDomDocument& doc ) = 0;

//! @note not available in Python bindings
// virtual void setXmlResponse( const QDomDocument& doc, const QString& mimeType ) = 0;

//! @note not available in Python bindings
// virtual void setGetPrintResponse( QByteArray* b ) = 0;

//! @note not available in Python bindings
// virtual bool startGetFeatureResponse( QByteArray* ba, const QString& infoFormat ) = 0;

//! @note not available in Python bindings
// virtual void setGetFeatureResponse( QByteArray* ba ) = 0;
/** Allow plugins to return a QgsServerException*/
void setServiceException( const QgsServerException& ex );

//! @note not available in Python bindings
void endGetFeatureResponse( QByteArray* ba );
@@ -116,12 +85,4 @@ class QgsRequestHandler /Abstract/

/** Return true if the HTTP headers were already sent to the client*/
bool headersSent() const;


//! @note not available in Python bindings
// virtual QPair<QByteArray, QByteArray> getResponse() = 0;

private:
/** Parses the input and creates a request neutral Parameter/Value map*/
void parseInput();
};
@@ -0,0 +1,56 @@
/***************************************************************************
qgsserverexception.sip
------------------------
begin : January 11 2017
copyright : (C) 2017 by David Marteau
email : david dot marteau at 3liz dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


/** \ingroup server
* \class QgsServerException
* \brief server Exception base class.
*/

class QgsServerException
{
%TypeHeaderCode
#include <qgsserverexception.h>
%End
public:
QgsServerException( const QString& message, int responseCode = 500 );

int responseCode() const;

virtual QByteArray formatResponse( QString& responseFormat ) const;
};


class QgsOgcServiceException
{
%TypeHeaderCode
#include <qgsserverexception.h>
%End
public:
QgsOgcServiceException( const QString& code, const QString& message, const QString& locator = QString(),
int responseCode = 200, const QString& version = "1.3.0" );

QString message() const;
QString code() const;
QString locator() const;

virtual QByteArray formatResponse( QString& responseFormat / Out / ) const;
};




@@ -92,6 +92,11 @@ class QgsServerResponse
*/
virtual qint64 write( const QByteArray& byteArray );

/**
* Write server exception
*/
virtual void write( const QgsServerException& ex );

/**
* Return the underlying QIODevice
*/
@@ -32,6 +32,7 @@

%Include qgsserverrequest.sip
%Include qgsserverresponse.sip
%Include qgsserverexception.sip
%Include qgsservice.sip
%Include qgsservicemodule.sip
%Include qgsserviceregistry.sip
@@ -28,7 +28,7 @@ SET ( qgis_mapserv_SRCS
qgswfsserver.cpp
qgswcsserver.cpp
qgsserversettings.cpp
qgsmapserviceexception.cpp
qgsserverexception.cpp
qgsmslayercache.cpp
qgsmslayerbuilder.cpp
qgshostedvdsbuilder.cpp
@@ -38,7 +38,6 @@ SET ( qgis_mapserv_SRCS
qgsremotedatasourcebuilder.cpp
qgssentdatasourcebuilder.cpp
qgsserverlogger.cpp
qgsmapserverutils.cpp
qgswcsprojectparser.cpp
qgswfsprojectparser.cpp
qgswmsconfigparser.cpp
@@ -30,16 +30,14 @@
//

QgsFcgiServerResponse::QgsFcgiServerResponse( QgsServerRequest::Method method )
: mMethod( method )
{
mBuffer.open( QIODevice::ReadWrite );
mHeadersSent = false;
mFinished = false;
mMethod = method;
setDefaultHeaders();
}

QgsFcgiServerResponse::~QgsFcgiServerResponse()
{

}

void QgsFcgiServerResponse::clearHeader( const QString& key )
@@ -82,7 +80,6 @@ void QgsFcgiServerResponse::sendError( int code, const QString& message )
}

clear();
setDefaultHeaders();
setReturnCode( code );
setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/html;charset=utf-8" ) );
write( QStringLiteral( "<html><body>%1</body></html>" ).arg( message ) );
@@ -157,6 +154,9 @@ void QgsFcgiServerResponse::clear()
mHeaders.clear();
mBuffer.seek( 0 );
mBuffer.buffer().clear();

// Restore default headers
setDefaultHeaders();
}

void QgsFcgiServerResponse::setDefaultHeaders()
@@ -61,13 +61,13 @@ class QgsFcgiServerResponse: public QgsServerResponse
/**
* Set the default headers
*/
virtual void setDefaultHeaders();
void setDefaultHeaders();

private:
QMap<QString, QString> mHeaders;
QBuffer mBuffer;
bool mFinished;
bool mHeadersSent;
QBuffer mBuffer;
bool mFinished = false;
bool mHeadersSent = false;
QgsServerRequest::Method mMethod;
};

This file was deleted.

This file was deleted.

@@ -20,12 +20,14 @@

#include <QString>

#include "qgsexception.h"
#include "qgsserverexception.h"
#include "qgis_server.h"

/** \ingroup server
* \class QgsMapServiceException
* \brief Exception class for WMS service exceptions.
* \brief Exception class for WMS service exceptions (for compatibility only).
*
* \deprecated Use QsgServerException
*
* The most important codes are:
* * "InvalidFormat"
@@ -34,15 +36,12 @@
* * "OperationNotSupported"
*/

class SERVER_EXPORT QgsMapServiceException : public QgsException
class SERVER_EXPORT QgsMapServiceException : public QgsOgcServiceException
{
public:
QgsMapServiceException( const QString& code, const QString& message );
QString code() const {return mCode;}
QString message() const {return mMessage;}
private:
QString mCode;
QString mMessage;
QgsMapServiceException( const QString& code, const QString& message )
: QgsOgcServiceException( code, message )
{}
};

#endif

0 comments on commit 474252a

Please sign in to comment.
You can’t perform that action at this time.