Skip to content
Permalink
Browse files

Merge pull request #7915 from rldhont/server-cache-manager-extension

[Server][Cache] Finalizing the cache manager
  • Loading branch information
rldhont committed Oct 7, 2018
2 parents b247c7c + 3bb64a7 commit 2b71c9cc970c1a396d60bbb59a2f6cf05a6ad644
@@ -36,10 +36,34 @@ namespace QgsWcs
void writeDescribeCoverage( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QDomDocument doc = createDescribeCoverageDocument( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *describeDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
}
else //describe feature xml not in cache. Create a new one
{
doc = createDescribeCoverageDocument( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
describeDocument = &doc;
}

response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( doc.toByteArray() );
response.write( describeDocument->toByteArray() );
}


@@ -37,12 +37,17 @@ namespace QgsWcs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
@@ -42,10 +42,34 @@ namespace QgsWfs
void writeDescribeFeatureType( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QDomDocument doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *describeDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
describeDocument = &doc;
}
else //describe feature xml not in cache. Create a new one
{
doc = createDescribeFeatureTypeDocument( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
describeDocument = &doc;
}

response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
response.write( doc.toByteArray() );
response.write( describeDocument->toByteArray() );
}


@@ -41,12 +41,17 @@ namespace QgsWfs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
@@ -43,12 +43,17 @@ namespace QgsWfs
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
@@ -94,7 +94,10 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response, bool projectSettings )
{
QgsAccessControl *accessControl = serverIface->accessControls();
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif

QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;
@@ -110,7 +113,10 @@ namespace QgsWms
cache = accessControl->fillCacheKey( cacheKeyList );
QString cacheKey = cacheKeyList.join( '-' );

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
@@ -55,10 +55,35 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response )
{
QDomDocument doc = getContext( serverIface, project, version, request );
QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif

QDomDocument doc;
const QDomDocument *contextDocument = nullptr;

QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
contextDocument = &doc;
}
else //context xml not in cache. Create a new one
{
doc = getContext( serverIface, project, version, request );

if ( cacheManager )
{
cacheManager->setCachedDocument( &doc, project, request, accessControl );
}
contextDocument = &doc;
}

response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
response.write( doc.toByteArray() );
response.write( contextDocument->toByteArray() );
}


@@ -34,16 +34,64 @@ namespace QgsWms
Q_UNUSED( version );

QgsServerRequest::Parameters params = request.parameters();
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );

// Get cached image
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager )
{
ImageOutputFormat outputFormat = parseImageFormat( format );
QString saveFormat;
QString contentType;
switch ( outputFormat )
{
case PNG:
case PNG8:
case PNG16:
case PNG1:
contentType = "image/png";
saveFormat = "PNG";
break;
case JPEG:
contentType = "image/jpeg";
saveFormat = "JPEG";
break;
default:
throw QgsServiceException( "InvalidFormat",
QString( "Output format '%1' is not supported in the GetLegendGraphic request" ).arg( format ) );
break;
}

QImage image;
QByteArray content = cacheManager->getCachedImage( project, request, accessControl );
if ( !content.isEmpty() && image.loadFromData( content ) )
{
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
image.save( response.io(), qPrintable( saveFormat ) );
return;
}
}

QgsRenderer renderer( serverIface, project, wmsParameters );

std::unique_ptr<QImage> result( renderer.getLegendGraphics() );

if ( result )
{
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.getImageQuality() );
if ( cacheManager )
{
QByteArray content = response.data();
if ( !content.isEmpty() )
cacheManager->setCachedImage( &content, project, request, accessControl );
}
}
else
{
@@ -46,12 +46,17 @@ namespace QgsWmts
void writeGetCapabilities( QgsServerInterface *serverIface, const QgsProject *project, const QString &version,
const QgsServerRequest &request, QgsServerResponse &response )
{
QgsAccessControl *accessControl = serverIface->accessControls();

QgsAccessControl *accessControl = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
#endif
QDomDocument doc;
const QDomDocument *capabilitiesDocument = nullptr;

QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager && cacheManager->getCachedDocument( &doc, project, request, accessControl ) )
{
capabilitiesDocument = &doc;
@@ -34,8 +34,12 @@ namespace QgsWmts
QUrlQuery query = translateWmtsParamToWmsQueryItem( QStringLiteral( "GetMap" ), params, project, serverIface );

// Get cached image
QgsAccessControl *accessControl = serverIface->accessControls();
QgsServerCacheManager *cacheManager = serverIface->cacheManager();
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
accessControl = serverIface->accessControls();
cacheManager = serverIface->cacheManager();
#endif
if ( cacheManager )
{
QgsWmtsParameters::Format f = params.format();

0 comments on commit 2b71c9c

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