Skip to content

Commit

Permalink
fixup! TEMP add more log
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia committed Jan 23, 2025
1 parent 0710215 commit 814bb6c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 39 deletions.
100 changes: 62 additions & 38 deletions src/server/qgsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,55 +396,74 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res

try
{
// TODO: split parse input into plain parse and processing from specific services
requestHandler.parseInput();
}
catch ( QgsMapServiceException &e )
{
QgsMessageLog::logMessage( "Parse input exception: " + e.message(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
requestHandler.setServiceException( e );
}
if ( response.feedback() && response.feedback()->isCanceled() )
{
throw QgsServerException( QStringLiteral( "Remote socket has been closed!" ) );
}

QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
try
{
// TODO: split parse input into plain parse and processing from specific services
requestHandler.parseInput();
}
catch ( QgsMapServiceException &e )
{
QgsMessageLog::logMessage( "Parse input exception: " + e.message(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
requestHandler.setServiceException( e );
}

// Set the request handler into the interface for plugins to manipulate it
sServerInterface->setRequestHandler( &requestHandler );
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );

// Set the request handler into the interface for plugins to manipulate it
sServerInterface->setRequestHandler( &requestHandler );
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );

// Initialize configfilepath so that is is available
// before calling plugin methods
// Note that plugins may still change that value using
// setConfigFilePath() interface method
if ( !project )
{
const QString configFilePath = configPath( *sConfigFilePath, request.serverParameters().map() );
sServerInterface->setConfigFilePath( configFilePath );
}
else
{
sServerInterface->setConfigFilePath( project->fileName() );
}

// Call requestReady() method (if enabled)
// This may also throw exceptions if there are errors in python plugins code
try
{
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
// Initialize configfilepath so that is is available
// before calling plugin methods
// Note that plugins may still change that value using
// setConfigFilePath() interface method
if ( !project )
{
const QString configFilePath = configPath( *sConfigFilePath, request.serverParameters().map() );
sServerInterface->setConfigFilePath( configFilePath );
}
else
{
sServerInterface->setConfigFilePath( project->fileName() );
}

responseDecorator.start();
if ( response.feedback() && response.feedback()->isCanceled() )
{
throw QgsServerException( QStringLiteral( "Remote socket has been closed!" ) );
}
// Call requestReady() method (if enabled)
// This may also throw exceptions if there are errors in python plugins code
try
{
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );

responseDecorator.start();
}
catch ( QgsException &ex )
{
// Internal server error
response.sendError( 500, QStringLiteral( "Internal Server Error" ) );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
}

QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
}
catch ( QgsException &ex )
catch ( QgsServerException &ex ) // thrown by "Remote socket has been closed!"
{
// Internal server error
response.sendError( 500, QStringLiteral( "Internal Server Error" ) );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
}
QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );

QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
QString format;
QgsMessageLog::logMessage( ex.formatResponse( format ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
}

// Plugins may have set exceptions
if ( !requestHandler.exceptionRaised() )
if ( !requestHandler.exceptionRaised() && ( !response.feedback() || !response.feedback()->isCanceled() ) )
{
try
{
Expand Down Expand Up @@ -498,6 +517,11 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res

QgsDebugMsgLevel( QStringLiteral( "============== %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );

if ( response.feedback() && response.feedback()->isCanceled() )
{
throw QgsServerException( QStringLiteral( "Remote socket has been closed!" ) );
}

if ( params.service().isEmpty() && ( api = sServiceRegistry->apiForRequest( request ) ) )
{
const QgsServerApiContext context { api->rootPath(), &request, &responseDecorator, project, sServerInterface };
Expand Down
7 changes: 6 additions & 1 deletion src/server/services/wms/qgswmsgetmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ namespace QgsWms
QgsRenderer renderer( context );
std::unique_ptr<QImage> result( renderer.getMap() );

if ( result && ( !response.feedback() || !response.feedback()->isCanceled() ) )
if ( response.feedback() && response.feedback()->isCanceled() )
{
throw QgsServerException( QStringLiteral( "Remote socket has been closed!" ) );
}

if ( result )
{
QgsDebugMsgLevel( QStringLiteral( "============== will write image %1:%2." ).arg( __FILE__ ).arg( __LINE__ ), 2 );
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
Expand Down

0 comments on commit 814bb6c

Please sign in to comment.