Skip to content

Commit

Permalink
Merge pull request #1671 from elpaso/requesthandler-refactoring2
Browse files Browse the repository at this point in the history
Requesthandler refactoring2
  • Loading branch information
mhugent committed Nov 4, 2014
2 parents 1d3f8a7 + a4fb2a1 commit 156a0fa
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 279 deletions.
103 changes: 54 additions & 49 deletions src/mapserver/qgis_map_serv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* *
***************************************************************************/

//for CMAKE_INSTALL_PREFIX
#include "qgsconfig.h"

#include "qgsapplication.h"
#include "qgscapabilitiescache.h"
#include "qgsconfigcache.h"
Expand All @@ -42,9 +45,6 @@
#include <QDateTime>
#include <QScopedPointer>

//for CMAKE_INSTALL_PREFIX
#include "qgsconfig.h"

#include <fcgi_stdio.h>


Expand Down Expand Up @@ -281,6 +281,7 @@ int main( int argc, char * argv[] )
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );

// FIXME: what is this debug line for?
QgsDebugMsg( qgsapp.applicationDirPath() + "/qgis_wms_server.log" );
QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)

Expand Down Expand Up @@ -327,78 +328,82 @@ int main( int argc, char * argv[] )

//Request handler
QScopedPointer<QgsRequestHandler> theRequestHandler( createRequestHandler() );
QMap<QString, QString> parameterMap;

try
{
parameterMap = theRequestHandler->parseInput();
// TODO: split parse input into plain parse and processing from specific services
theRequestHandler->parseInput();
}
catch ( QgsMapServiceException& e )
{
QgsMessageLog::logMessage( "Parse input exception: " + e.message(), "Server", QgsMessageLog::CRITICAL );
theRequestHandler->sendServiceException( e );
continue;
theRequestHandler->setServiceException( e );
}

// Copy the parameters map
QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() );

printRequestParameters( parameterMap, logLevel );
QMap<QString, QString>::const_iterator paramIt;

//Config file path
QString configFilePath = configPath( defaultConfigFilePath, parameterMap );

//Service parameter
QString serviceString;
paramIt = parameterMap.find( "SERVICE" );
if ( paramIt == parameterMap.constEnd() )
{
QgsMessageLog::logMessage( "Exception: SERVICE parameter is missing", "Server", QgsMessageLog::CRITICAL );
theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) );
continue;
}
else
{
serviceString = paramIt.value();
}
QString serviceString = theRequestHandler->parameter( "SERVICE" );

if ( serviceString == "WCS" )
// Enter core services main switch
if ( !theRequestHandler->exceptionRaised() )
{
QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration( configFilePath );
if ( !p )
if ( serviceString == "WCS" )
{
theRequestHandler->sendServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) );
continue;
QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration( configFilePath );
if ( !p )
{
theRequestHandler->setServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) );
}
else
{
QgsWCSServer wcsServer( configFilePath, parameterMap, p, theRequestHandler.data() );
wcsServer.executeRequest();
}
}
QgsWCSServer wcsServer( configFilePath, parameterMap, p, theRequestHandler.take() );
wcsServer.executeRequest();
}
else if ( serviceString == "WFS" )
{
QgsWFSProjectParser* p = QgsConfigCache::instance()->wfsConfiguration( configFilePath );
if ( !p )
else if ( serviceString == "WFS" )
{
theRequestHandler->sendServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) );
continue;
QgsWFSProjectParser* p = QgsConfigCache::instance()->wfsConfiguration( configFilePath );
if ( !p )
{
theRequestHandler->setServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) );
}
else
{
QgsWFSServer wfsServer( configFilePath, parameterMap, p, theRequestHandler.data() );
wfsServer.executeRequest();
}
}
QgsWFSServer wfsServer( configFilePath, parameterMap, p, theRequestHandler.take() );
wfsServer.executeRequest();
}
else //WMS else
{
QgsWMSConfigParser* p = QgsConfigCache::instance()->wmsConfiguration( configFilePath, parameterMap );
if ( !p )
else if ( serviceString == "WMS" )
{
theRequestHandler->sendServiceException( QgsMapServiceException( "WMS configuration error", "There was an error reading the project file or the SLD configuration" ) );
continue;
QgsWMSConfigParser* p = QgsConfigCache::instance()->wmsConfiguration( configFilePath, parameterMap );
if ( !p )
{
theRequestHandler->setServiceException( QgsMapServiceException( "WMS configuration error", "There was an error reading the project file or the SLD configuration" ) );
}
else
{
QgsWMSServer wmsServer( configFilePath, parameterMap, p, theRequestHandler.data() , theMapRenderer.data(), &capabilitiesCache );
wmsServer.executeRequest();
}
}
QgsWMSServer wmsServer( configFilePath, parameterMap, p, theRequestHandler.take(), theMapRenderer.data(), &capabilitiesCache );
wmsServer.executeRequest();
}
else
{
theRequestHandler->setServiceException( QgsMapServiceException( "Service configuration error", "Service unknown or unsupported" ) );
} // end switch
} // end if not exception raised

theRequestHandler->sendResponse();

if ( logLevel < 1 )
{
QgsMessageLog::logMessage( "Request finished in " + QString::number( time.elapsed() ) + " ms", "Server", QgsMessageLog::INFO );
}
}

return 0;
}

8 changes: 3 additions & 5 deletions src/mapserver/qgsgetrequesthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ QgsGetRequestHandler::QgsGetRequestHandler()
{
}

QMap<QString, QString> QgsGetRequestHandler::parseInput()
void QgsGetRequestHandler::parseInput()
{
QString queryString;
QMap<QString, QString> parameters;

const char* qs = getenv( "QUERY_STRING" );
if ( qs )
Expand All @@ -38,9 +37,8 @@ QMap<QString, QString> QgsGetRequestHandler::parseInput()
else
{
QgsDebugMsg( "error, no query string found" );
return parameters; //no query string? something must be wrong...
return; //no query string? something must be wrong...
}

requestStringToParameterMap( queryString, parameters );
return parameters;
requestStringToParameterMap( queryString, mParameterMap );
}
8 changes: 7 additions & 1 deletion src/mapserver/qgsgetrequesthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@

#include "qgshttprequesthandler.h"

#ifndef QGSGETPREQUESTHANDLER_H
#define QGSGETPREQUESTHANDLER_H


class QgsGetRequestHandler: public QgsHttpRequestHandler
{
public:
QgsGetRequestHandler();
QMap<QString, QString> parseInput();
void parseInput();
};

#endif
Loading

0 comments on commit 156a0fa

Please sign in to comment.