Skip to content

Commit

Permalink
TEMP add more log
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdm-oslandia committed Jan 21, 2025
1 parent a4627f3 commit 9751b37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/server/qgsfcgiserverresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ QgsFcgiServerResponse::~QgsFcgiServerResponse()
// Inform the thread to quit asap
mSocketMonitoringThread->stop();

QgsDebugMsgLevel( QStringLiteral( "FCGIServer::run %1: mSocketMonitoringThread->stop SENT." ), 2 );

// Just to be sure
mThread.join();

QgsDebugMsgLevel( QStringLiteral( "FCGIServer::run %1: mThread.join() DONE." ), 2 );
}

void QgsFcgiServerResponse::removeHeader( const QString &key )
Expand Down
16 changes: 16 additions & 0 deletions src/server/qgsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,10 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
requestHandler.setServiceException( e );
}

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

// Initialize configfilepath so that is is available
// before calling plugin methods
Expand All @@ -426,6 +428,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
// This may also throw exceptions if there are errors in python plugins code
try
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
responseDecorator.start();
}
catch ( QgsException &ex )
Expand All @@ -435,11 +438,13 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
}

QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// Plugins may have set exceptions
if ( !requestHandler.exceptionRaised() )
{
try
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
const QgsServerParameters params = request.serverParameters();
printRequestParameters( params.toMap(), logLevel );

Expand All @@ -456,6 +461,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
}
}

QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// Set the current project instance
QgsProject::setInstance( const_cast<QgsProject *>( project ) );

Expand All @@ -467,10 +473,12 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
{
sServerInterface->setConfigFilePath( QString() );
}
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );

// Call projectReady() method (if enabled)
// This may also throw exceptions if there are errors in python plugins code
responseDecorator.ready();
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );

// Note that at this point we still might not have set a valid project.
// There are APIs that work without a project (e.g. the landing page catalog API that
Expand All @@ -480,6 +488,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
// TODO: QGIS 4 fix the OWS services and treat them as APIs
QgsServerApi *api = nullptr;

QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
if ( params.service().isEmpty() && ( api = sServiceRegistry->apiForRequest( request ) ) )
{
const QgsServerApiContext context { api->rootPath(), &request, &responseDecorator, project, sServerInterface };
Expand All @@ -499,6 +508,7 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
requestHandler.setResponseHeader( QStringLiteral( "Content-Disposition" ), value );
}

QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// Lookup for service
QgsService *service = sServiceRegistry->getService( params.service(), params.version() );
if ( service )
Expand All @@ -513,12 +523,14 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
}
catch ( QgsServerException &ex )
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
responseDecorator.write( ex );
QString format;
QgsMessageLog::logMessage( ex.formatResponse( format ), QStringLiteral( "Server" ), Qgis::MessageLevel::Warning );
}
catch ( QgsException &ex )
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// Internal server error
response.sendError( 500, QStringLiteral( "Internal Server Error" ) );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
Expand All @@ -529,15 +541,19 @@ void QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &res
// This may also throw exceptions if there are errors in python plugins code
try
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
responseDecorator.finish();
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
}
catch ( QgsException &ex )
{
QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// Internal server error
response.sendError( 500, QStringLiteral( "Internal Server Error" ) );
QgsMessageLog::logMessage( ex.what(), QStringLiteral( "Server" ), Qgis::MessageLevel::Critical );
}

QgsDebugMsgLevel( QStringLiteral( "SERVER %1." ).arg( __LINE__ ), 2 );
// We are done using requestHandler in plugins, make sure we don't access
// to a deleted request handler from Python bindings
sServerInterface->clearRequestHandler();
Expand Down

0 comments on commit 9751b37

Please sign in to comment.