Skip to content

Commit dc211f8

Browse files
committed
WMS run as a module service !
1 parent c793e66 commit dc211f8

File tree

11 files changed

+92
-47
lines changed

11 files changed

+92
-47
lines changed

src/server/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SET ( qgis_mapserv_SRCS
2525
qgsconfigcache.cpp
2626
qgsrequesthandler.cpp
2727
qgsowsserver.cpp
28-
qgswmsserver.cpp
28+
# qgswmsserver.cpp
2929
qgswfsserver.cpp
3030
qgswcsserver.cpp
3131
qgsmapserviceexception.cpp

src/server/qgsfcgiserverresponse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class QgsFcgiServerRequest: public QgsServerRequest
8585
virtual QByteArray data() const override;
8686

8787
/**
88-
* Return true if an error occured during initialization
88+
* Return true if an error occurred during initialization
8989
*/
9090
bool hasError() const { return mHasError; }
9191

src/server/qgsserver.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "qgsproject.h"
3131
#include "qgsproviderregistry.h"
3232
#include "qgslogger.h"
33-
#include "qgswmsserver.h"
33+
//#include "qgswmsserver.h"
3434
#include "qgswfsserver.h"
3535
#include "qgswcsserver.h"
3636
#include "qgsmapserviceexception.h"
@@ -41,6 +41,7 @@
4141
#include "qgsserverrequest.h"
4242
#include "qgsbufferserverresponse.h"
4343
#include "qgsfilterresponsedecorator.h"
44+
#include "qgsservice.h"
4445

4546
#include <QDomDocument>
4647
#include <QNetworkDiskCache>
@@ -387,7 +388,7 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
387388
// Call requestReady() method (if enabled)
388389
theResponse.start();
389390

390-
QMap<QString, QString> parameterMap = theRequestHandler.parameterMap();
391+
QMap<QString, QString> parameterMap = request.parameters();
391392
printRequestParameters( parameterMap, logLevel );
392393

393394
const QgsAccessControl* accessControl = sServerInterface->accessControls();
@@ -401,20 +402,22 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
401402
#endif
402403

403404
//Service parameter
404-
QString serviceString = theRequestHandler.parameter( QStringLiteral( "SERVICE" ) );
405+
QString serviceString = parameterMap.value( QStringLiteral( "SERVICE" ) );
405406

406407
if ( serviceString.isEmpty() )
407408
{
408409
// SERVICE not mandatory for WMS 1.3.0 GetMap & GetFeatureInfo
409-
QString requestString = theRequestHandler.parameter( QStringLiteral( "REQUEST" ) );
410+
QString requestString = parameterMap.value( QStringLiteral( "REQUEST" ) );
410411
if ( requestString == QLatin1String( "GetMap" ) || requestString == QLatin1String( "GetFeatureInfo" ) )
411412
{
412413
serviceString = QStringLiteral( "WMS" );
413414
}
414415
}
415416

417+
QString versionString = parameterMap.value( QStringLiteral( "VERSION" ) );
418+
416419
//possibility for client to suggest a download filename
417-
QString outputFileName = theRequestHandler.parameter( QStringLiteral( "FILE_NAME" ) );
420+
QString outputFileName = parameterMap.value( QStringLiteral( "FILE_NAME" ) );
418421
if ( !outputFileName.isEmpty() )
419422
{
420423
theRequestHandler.setHeader( QStringLiteral( "Content-Disposition" ), "attachment; filename=\"" + outputFileName + "\"" );
@@ -423,7 +426,14 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
423426
// Enter core services main switch
424427
if ( !theRequestHandler.exceptionRaised() )
425428
{
426-
if ( serviceString == QLatin1String( "WCS" ) )
429+
// Lookup for service
430+
431+
QgsService* service = sServiceRegistry.getService( serviceString, versionString );
432+
if ( service )
433+
{
434+
service->executeRequest( request, theResponse );
435+
}
436+
else if ( serviceString == QLatin1String( "WCS" ) )
427437
{
428438
QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration(
429439
configFilePath
@@ -467,6 +477,7 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
467477
wfsServer.executeRequest();
468478
}
469479
}
480+
/*
470481
else if ( serviceString == QLatin1String( "WMS" ) )
471482
{
472483
QgsWmsConfigParser* p = QgsConfigCache::instance()->wmsConfiguration(
@@ -490,6 +501,7 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
490501
wmsServer.executeRequest();
491502
}
492503
}
504+
*/
493505
else
494506
{
495507
theRequestHandler.setServiceException( QgsMapServiceException( QStringLiteral( "Service configuration error" ), QStringLiteral( "Service unknown or unsupported" ) ) );

src/server/qgsserver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class SERVER_EXPORT QgsServer
130130
#endif
131131
//! Initialization must run once for all servers
132132
static bool sInitialised;
133-
static bool sCaptureOutput;
134133

135134
//! service registry
136135
static QgsServiceRegistry sServiceRegistry;

src/server/qgsservicenativeloader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ QgsServiceModule* QgsServiceNativeLoader::loadNativeModule( const QString& locat
9898
qDebug() << QString( "Loading native module %1" ).arg( location );
9999
if ( !lib.load() )
100100
{
101-
qDebug() << QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString() );
102101
QgsMessageLog::logMessage( QString( "Failed to load library %1: %2" ).arg( lib.fileName(), lib.errorString() ) );
103102
return nullptr;
104103
}

src/server/qgsserviceregistry.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ namespace
7575
return false;
7676
}
7777

78+
// Check that two versions are c
79+
80+
7881
} // namespace
7982

8083
QgsServiceRegistry::QgsServiceRegistry()
@@ -104,7 +107,9 @@ QgsService* QgsServiceRegistry::getService( const QString& name, const QString&
104107
}
105108
else
106109
{
107-
QgsMessageLog::logMessage( QString( "Service %1 %2 not found" ).arg( name, version ) );
110+
// Return the dofault version
111+
QgsMessageLog::logMessage( QString( "Service %1 %2 not found, returning default" ).arg( name, version ) );
112+
service = mServices[v->second].get();
108113
}
109114
}
110115
else
@@ -131,8 +136,17 @@ void QgsServiceRegistry::registerService( QgsService* service )
131136
mServices.insert( key, std::shared_ptr<QgsService>( service ) );
132137

133138
// Check the default version
134-
// and replace with te new one if it has a higher version
139+
// The first inserted service of a given name
140+
// is the default one.
141+
// this will ensure that native services are always
142+
// the defaults.
135143
VersionTable::const_iterator v = mVersions.constFind( name );
144+
if ( v == mVersions.constEnd() )
145+
{
146+
// Insert the service as the default one
147+
mVersions.insert( name, VersionTable::mapped_type( version, key ) );
148+
}
149+
/*
136150
if ( v != mVersions.constEnd() )
137151
{
138152
if ( isVersionGreater( version, v->first ) )
@@ -145,7 +159,8 @@ void QgsServiceRegistry::registerService( QgsService* service )
145159
{
146160
// Insert the service as the default one
147161
mVersions.insert( name, VersionTable::mapped_type( version, key ) );
148-
}
162+
}*/
163+
149164
}
150165

151166
int QgsServiceRegistry::unregisterService( const QString& name, const QString& version )

src/server/services/wms/qgswms.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,21 @@ namespace QgsWms
6161
{
6262
Q_UNUSED( project );
6363

64-
// Get the request
6564
QgsServerRequest::Parameters params = request.parameters();
65+
QString versionString = params.value( "VERSION" );
66+
if ( versionString.isEmpty() )
67+
{
68+
//WMTVER needs to be supported by WMS 1.1.1 for backwards compatibility with WMS 1.0.0
69+
versionString = params.value( "WMTVER" );
70+
}
71+
72+
// Set the default version
73+
if ( versionString.isEmpty() )
74+
{
75+
versionString = mVersion;
76+
}
77+
78+
// Get the request
6679
QString req = params.value( QStringLiteral( "REQUEST" ) );
6780
if ( req.isEmpty() )
6881
{
@@ -72,66 +85,59 @@ namespace QgsWms
7285
}
7386

7487
if (( QSTR_COMPARE( mVersion, "1.1.1" ) && QSTR_COMPARE( req, "capabilities" ) )
75-
|| QSTR_COMPARE( req, "GetCapabilites" ) )
88+
|| QSTR_COMPARE( req, "GetCapabilities" ) )
7689
{
77-
//TODO GetCapabilities
78-
writeGetCapabilities( mServerIface, mVersion, request, response, false );
90+
writeGetCapabilities( mServerIface, versionString, request, response, false );
7991
}
8092
else if QSTR_COMPARE( req, "GetProjectSettings" )
8193
{
82-
//Ensure that we are supporting 1.3.0
83-
if ( mVersion.compare( "1.3.0" ) != 0 )
84-
{
85-
writeError( response, QStringLiteral( "OperationNotSupported" ),
86-
QStringLiteral( "GetProjectSettings is not supported" ) );
87-
return;
88-
}
89-
writeGetCapabilities( mServerIface, mVersion, request, response, true );
90-
// TODO GetProjectSettings
94+
//getProjectSettings extends WMS 1.3.0 capabilities
95+
versionString = QStringLiteral( "1.3.0" );
96+
writeGetCapabilities( mServerIface, versionString, request, response, true );
9197
}
9298
else if QSTR_COMPARE( req, "GetMap" )
9399
{
94100
QString format = params.value( QStringLiteral( "FORMAT" ) );
95101
if QSTR_COMPARE( format, "application/dxf" )
96102
{
97-
writeAsDxf( mServerIface, mVersion, request, response );
103+
writeAsDxf( mServerIface, versionString, request, response );
98104
}
99105
else
100106
{
101-
writeGetMap( mServerIface, mVersion, request, response );
107+
writeGetMap( mServerIface, versionString, request, response );
102108
}
103109
}
104110
else if QSTR_COMPARE( req, "GetFeatureInfo" )
105111
{
106-
writeGetFeatureInfo( mServerIface, mVersion, request, response );
112+
writeGetFeatureInfo( mServerIface, versionString, request, response );
107113
}
108114
else if QSTR_COMPARE( req, "GetContext" )
109115
{
110-
writeGetContext( mServerIface, mVersion, request, response );
116+
writeGetContext( mServerIface, versionString, request, response );
111117
}
112118
else if QSTR_COMPARE( req, "GetSchemaExtension" )
113119
{
114-
writeGetSchemaExtension( mServerIface, mVersion, request, response );
120+
writeGetSchemaExtension( mServerIface, versionString, request, response );
115121
}
116122
else if QSTR_COMPARE( req, "GetStyle" )
117123
{
118-
writeGetStyle( mServerIface, mVersion, request, response );
124+
writeGetStyle( mServerIface, versionString, request, response );
119125
}
120126
else if QSTR_COMPARE( req, "GetStyles" )
121127
{
122-
writeGetStyles( mServerIface, mVersion, request, response );
128+
writeGetStyles( mServerIface, versionString, request, response );
123129
}
124130
else if QSTR_COMPARE( req, "DescribeLayer" )
125131
{
126-
writeDescribeLayer( mServerIface, mVersion, request, response );
132+
writeDescribeLayer( mServerIface, versionString, request, response );
127133
}
128134
else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
129135
{
130-
writeGetLegendGraphics( mServerIface, mVersion, request, response );
136+
writeGetLegendGraphics( mServerIface, versionString, request, response );
131137
}
132138
else if QSTR_COMPARE( req, "GetPrint" )
133139
{
134-
writeDescribeLayer( mServerIface, mVersion, request, response );
140+
writeGetPrint( mServerIface, versionString, request, response );
135141
}
136142
else
137143
{
@@ -159,7 +165,6 @@ class QgsWmsModule: public QgsServiceModule
159165
{
160166
QgsDebugMsg( "WMSModule::registerSelf called" );
161167
registry.registerService( new QgsWms::Service( "1.3.0", serverIface ) );
162-
registry.registerService( new QgsWms::Service( "1.1.1", serverIface ) );
163168
}
164169
};
165170

src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace QgsWms
7676
QgsMessageLog::logMessage( QStringLiteral( "Found capabilities document in cache" ) );
7777
}
7878

79-
response.setHeader( QStringLiteral( "Contente-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
79+
response.setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/xml; charset=utf-8" ) );
8080
response.write( capabilitiesDocument->toByteArray() );
8181
}
8282

src/server/services/wms/qgswmsgetfeatureinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace QgsWms
151151
return;
152152
}
153153

154-
response.setHeader( QStringLiteral( "Content-Type" ), infoFormat );
154+
response.setHeader( QStringLiteral( "Content-Type" ), infoFormat + QStringLiteral( "; charset=utf-8" ) );
155155
response.write( ba );
156156
}
157157

src/server/services/wms/qgswmsutils.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ namespace QgsWms
3838
QgsWmsConfigParser* getConfigParser( QgsServerInterface* serverIface )
3939
{
4040
QString configFilePath = serverIface->configFilePath();
41-
return QgsConfigCache::instance()->wmsConfiguration( configFilePath, serverIface->accessControls() );
41+
42+
QgsWmsConfigParser* parser = QgsConfigCache::instance()->wmsConfiguration( configFilePath, serverIface->accessControls() );
43+
if ( !parser )
44+
{
45+
throw QgsMapServiceException(
46+
QStringLiteral( "WMS configuration error" ),
47+
QStringLiteral( "There was an error reading the project file or the SLD configuration" ) );
48+
49+
}
50+
return parser;
4251
}
4352

4453
// Output a wms standard error

0 commit comments

Comments
 (0)