mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Renamed plugin hook responseReady to responseComplete
added sendResponse hook and passed pluginFilters to request handler
This commit is contained in:
parent
8bd78b3386
commit
329b9d7ece
@ -48,8 +48,17 @@ public:
|
|||||||
* parameters, just before entering the main switch for core services.*/
|
* parameters, just before entering the main switch for core services.*/
|
||||||
virtual void requestReady();
|
virtual void requestReady();
|
||||||
/** Method called when the QgsRequestHandler processing has done and
|
/** Method called when the QgsRequestHandler processing has done and
|
||||||
* the response is ready, just after the main switch for core services.
|
* the response is ready, just after the main switch for core services
|
||||||
|
* and before final sending response to FCGI stdout.
|
||||||
*/
|
*/
|
||||||
virtual void responseReady();
|
virtual void responseComplete();
|
||||||
|
/** Method called when the QgsRequestHandler sends its data to FCGI stdout.
|
||||||
|
* This normally occours at the end of core services processing just after
|
||||||
|
* the responseComplete() plugin hook. For streaming services (like WFS on
|
||||||
|
* getFeature requests, sendResponse() might have been called several times
|
||||||
|
* before the response is complete: in this particular case, sendResponse()
|
||||||
|
* is called once for each feature before hitting responseComplete()
|
||||||
|
*/
|
||||||
|
virtual void sendResponse();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -370,6 +370,14 @@ int main( int argc, char * argv[] )
|
|||||||
{
|
{
|
||||||
filtersIterator.value()->requestReady();
|
filtersIterator.value()->requestReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Pass the filters to the requestHandler, this is needed for the following reasons:
|
||||||
|
// 1. allow core services to access plugin filters and implement thir own plugin hooks
|
||||||
|
// 2. allow requestHandler to call Response
|
||||||
|
|
||||||
|
//TODO: implement this in the requestHandler ctor (far easier if we will get rid of
|
||||||
|
// MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
theRequestHandler->setPluginFilters( pluginFilters );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Copy the parameters map
|
// Copy the parameters map
|
||||||
@ -431,15 +439,12 @@ int main( int argc, char * argv[] )
|
|||||||
} // end if not exception raised
|
} // end if not exception raised
|
||||||
|
|
||||||
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
// Call responseReady plugin filters in reverse order
|
// Iterate filters and call their responseComplete() method
|
||||||
filtersIterator = pluginFilters.constEnd();
|
for ( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator )
|
||||||
while ( filtersIterator != pluginFilters.constBegin() )
|
|
||||||
{
|
{
|
||||||
--filtersIterator;
|
filtersIterator.value()->responseComplete();
|
||||||
filtersIterator.value()->responseReady();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
theRequestHandler->sendResponse();
|
theRequestHandler->sendResponse();
|
||||||
|
|
||||||
if ( logLevel < 1 )
|
if ( logLevel < 1 )
|
||||||
|
@ -63,7 +63,7 @@ void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &form
|
|||||||
|
|
||||||
bool QgsHttpRequestHandler::responseReady() const
|
bool QgsHttpRequestHandler::responseReady() const
|
||||||
{
|
{
|
||||||
return mHeaders.count() || ( mBody.size() && mInfoFormat.length() );
|
return mHeaders.count() || mBody.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsHttpRequestHandler::exceptionRaised() const
|
bool QgsHttpRequestHandler::exceptionRaised() const
|
||||||
@ -132,6 +132,7 @@ void QgsHttpRequestHandler::sendHeaders()
|
|||||||
printf( "\n" );
|
printf( "\n" );
|
||||||
}
|
}
|
||||||
printf( "\n" );
|
printf( "\n" );
|
||||||
|
mHeaders.clear();
|
||||||
mHeadersSent = TRUE;
|
mHeadersSent = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,21 +140,37 @@ void QgsHttpRequestHandler::sendBody() const
|
|||||||
{
|
{
|
||||||
size_t result = fwrite( (void*)mBody.data(), mBody.size(), 1, FCGI_stdout );
|
size_t result = fwrite( (void*)mBody.data(), mBody.size(), 1, FCGI_stdout );
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result, mBody.size() ) );
|
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
|
||||||
#else
|
#else
|
||||||
Q_UNUSED( result );
|
Q_UNUSED( result );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
void QgsHttpRequestHandler::setPluginFilters( QgsServerFiltersMap pluginFilters )
|
||||||
|
{
|
||||||
|
mPluginFilters = pluginFilters;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void QgsHttpRequestHandler::sendResponse()
|
void QgsHttpRequestHandler::sendResponse()
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString( "Sending HTTP response" ) );
|
QgsDebugMsg( QString( "Sending HTTP response" ) );
|
||||||
if ( ! responseReady() )
|
if ( ! responseReady() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString( "Trying to send out an empty reponse" ) );
|
QgsDebugMsg( QString( "Trying to send out an invalid response" ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( ! mHeadersSent )
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
// Plugin hook
|
||||||
|
// Iterate filters and call their sendResponse() method
|
||||||
|
QgsServerFiltersMap::const_iterator filtersIterator;
|
||||||
|
for ( filtersIterator = mPluginFilters.constBegin(); filtersIterator != mPluginFilters.constEnd(); ++filtersIterator )
|
||||||
|
{
|
||||||
|
filtersIterator.value()->sendResponse();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (! headersSent() )
|
||||||
{
|
{
|
||||||
sendHeaders();
|
sendHeaders();
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,12 @@ class QgsHttpRequestHandler: public QgsRequestHandler
|
|||||||
virtual void setInfoFormat( const QString &format );
|
virtual void setInfoFormat( const QString &format );
|
||||||
virtual bool responseReady() const;
|
virtual bool responseReady() const;
|
||||||
virtual bool exceptionRaised() const;
|
virtual bool exceptionRaised() const;
|
||||||
virtual void setParameter( const QString &key, const QString &value );
|
virtual void setParameter(const QString &key, const QString &value);
|
||||||
virtual QString parameter( const QString &key ) const;
|
virtual QString parameter(const QString &key) const;
|
||||||
virtual int removeParameter( const QString &key );
|
virtual int removeParameter(const QString &key);
|
||||||
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
virtual void setPluginFilters( QgsServerFiltersMap pluginFilters );
|
||||||
|
#endif
|
||||||
protected:
|
protected:
|
||||||
virtual void sendHeaders( );
|
virtual void sendHeaders( );
|
||||||
virtual void sendBody( ) const;
|
virtual void sendBody( ) const;
|
||||||
|
@ -22,10 +22,17 @@
|
|||||||
#ifndef QGSREQUESTHANDLER_H
|
#ifndef QGSREQUESTHANDLER_H
|
||||||
#define QGSREQUESTHANDLER_H
|
#define QGSREQUESTHANDLER_H
|
||||||
|
|
||||||
|
//Needed for MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
#include "qgsconfig.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
#include "qgsserverfilter.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class QDomDocument;
|
class QDomDocument;
|
||||||
class QImage;
|
class QImage;
|
||||||
class QgsMapServiceException;
|
class QgsMapServiceException;
|
||||||
@ -64,6 +71,8 @@ class QgsRequestHandler
|
|||||||
virtual void clearBody( ) = 0;
|
virtual void clearBody( ) = 0;
|
||||||
virtual QByteArray* body( ) { return &mBody; }
|
virtual QByteArray* body( ) { return &mBody; }
|
||||||
virtual void setInfoFormat( const QString &format ) = 0;
|
virtual void setInfoFormat( const QString &format ) = 0;
|
||||||
|
/**Check if the response headers or the response body are not empty*/
|
||||||
|
virtual bool responseReady() const = 0;
|
||||||
/**Send out HTTP headers and flush output buffer*/
|
/**Send out HTTP headers and flush output buffer*/
|
||||||
virtual void sendResponse( ) = 0;
|
virtual void sendResponse( ) = 0;
|
||||||
/**Pointer to last raised exception*/
|
/**Pointer to last raised exception*/
|
||||||
@ -76,22 +85,24 @@ class QgsRequestHandler
|
|||||||
/**Return a request parameter*/
|
/**Return a request parameter*/
|
||||||
virtual QString parameter( const QString &key ) const = 0;
|
virtual QString parameter( const QString &key ) const = 0;
|
||||||
/**Return the response body*/
|
/**Return the response body*/
|
||||||
virtual QByteArray* body( ) { return &mBody; }
|
|
||||||
/**Return the requested format string*/
|
/**Return the requested format string*/
|
||||||
QString format() const { return mFormat; }
|
QString format() const { return mFormat; }
|
||||||
/**Return the mime type for the response*/
|
/**Return the mime type for the response*/
|
||||||
QString infoFormat() const { return mInfoFormat; }
|
QString infoFormat() const { return mInfoFormat; }
|
||||||
/**Return true if the HTTP headers were already sent to the client*/
|
/**Return true if the HTTP headers were already sent to the client*/
|
||||||
bool headersSent() { return mHeadersSent; }
|
bool headersSent() { return mHeadersSent; }
|
||||||
QString infoFormat() const { return mInfoFormat; }
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
/**Allow core services to call plugin hooks through sendResponse() */
|
||||||
protected:
|
virtual void setPluginFilters( QgsServerFiltersMap pluginFilters ) = 0;
|
||||||
|
#endif
|
||||||
|
protected:
|
||||||
virtual void sendHeaders( ) = 0;
|
virtual void sendHeaders( ) = 0;
|
||||||
virtual void sendBody( ) const = 0;
|
virtual void sendBody( ) const = 0;
|
||||||
|
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
|
||||||
|
QgsServerFiltersMap mPluginFilters;
|
||||||
|
#endif
|
||||||
QByteArray mBody; // The response payload
|
QByteArray mBody; // The response payload
|
||||||
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
|
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
|
||||||
QByteArray mBody; // The response payload
|
|
||||||
QString mFormat;
|
QString mFormat;
|
||||||
QString mFormatString; //format string as it is passed in the request (with base)
|
QString mFormatString; //format string as it is passed in the request (with base)
|
||||||
bool mHeadersSent;
|
bool mHeadersSent;
|
||||||
|
@ -42,8 +42,13 @@ void QgsServerFilter::requestReady()
|
|||||||
QgsDebugMsg( "QgsServerFilter plugin default requestReady called");
|
QgsDebugMsg( "QgsServerFilter plugin default requestReady called");
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsServerFilter::responseReady()
|
void QgsServerFilter::responseComplete()
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "QgsServerFilter plugin default responseReady called");
|
QgsDebugMsg( "QgsServerFilter plugin default responseComplete called");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QgsServerFilter::sendResponse()
|
||||||
|
{
|
||||||
|
QgsDebugMsg( "QgsServerFilter plugin default sendResponse called");
|
||||||
|
}
|
||||||
|
@ -41,7 +41,8 @@ public:
|
|||||||
virtual ~QgsServerFilter();
|
virtual ~QgsServerFilter();
|
||||||
QgsServerInterface* serverInterface( ) { return mServerInterface; }
|
QgsServerInterface* serverInterface( ) { return mServerInterface; }
|
||||||
virtual void requestReady();
|
virtual void requestReady();
|
||||||
virtual void responseReady();
|
virtual void responseComplete();
|
||||||
|
virtual void sendResponse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user