Skip to content

Commit

Permalink
WMS server: add more capabilities to GetCapabilities response (includ…
Browse files Browse the repository at this point in the history
…ing GetPrint)

Thanks Marco Lechner for the initial patch.
  • Loading branch information
jef-n committed Dec 8, 2011
1 parent c62ca9f commit 079713d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 74 deletions.
35 changes: 24 additions & 11 deletions src/mapserver/qgis_map_serv.cpp
Expand Up @@ -236,12 +236,20 @@ int main( int argc, char * argv[] )
continue;
}

QMap<QString, QString>::const_iterator paramIt;

//set admin config file to wms server object
if ( !parameterMap.contains( "MAP" ) )
QString configFilePath( defaultConfigFilePath );

paramIt = parameterMap.find( "MAP" );
if ( paramIt == parameterMap.constEnd() )
{
QgsDebugMsg( QString( "Using default configuration file path: %1" ).arg( defaultConfigFilePath ) );
}
QString configFilePath = parameterMap.value( "MAP", defaultConfigFilePath );
else
{
configFilePath = paramIt.value();
}

QgsConfigParser* adminConfigParser = QgsConfigCache::instance()->searchConfiguration( configFilePath );
if ( !adminConfigParser )
Expand All @@ -255,15 +263,22 @@ int main( int argc, char * argv[] )
adminConfigParser->setParameterMap( parameterMap );

//request to WMS?
QString serviceString = parameterMap.value( "SERVICE", "WMS" );
#if 0
if ( !parameterMap.contains( "SERVICE" ) )
QString serviceString;
#ifndef QGISDEBUG
serviceString = parameterMap.value( "SERVICE", "WMS" );
#else
paramIt = parameterMap.find( "SERVICE" );
if ( paramIt == parameterMap.constEnd() )
{
QgsDebugMsg( "unable to find 'SERVICE' parameter, exiting..." );
theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) );
delete theRequestHandler;
continue;
}
else
{
serviceString = paramIt.value();
}
#endif

QgsWMSServer* theServer = 0;
Expand Down Expand Up @@ -386,7 +401,7 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
else if ( request == "GetStyle" )
else if ( request == "GetStyles" || request == "GetStyle" ) // GetStyle for compatibility with earlier QGIS versions
{
try
{
Expand All @@ -402,7 +417,7 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
else if ( request == "GetLegendGraphics" )
else if ( request == "GetLegendGraphic" || request == "GetLegendGraphics" ) // GetLegendGraphics for compatibility with earlier QGIS versions
{
QImage* result = 0;
try
Expand All @@ -416,8 +431,8 @@ int main( int argc, char * argv[] )

if ( result )
{
QgsDebugMsg( "Sending GetLegendGraphics response" );
//sending is the same for GetMap and GetLegendGraphics
QgsDebugMsg( "Sending GetLegendGraphic response" );
//sending is the same for GetMap and GetLegendGraphic
theRequestHandler->sendGetMapResponse( serviceString, result );
}
else
Expand Down Expand Up @@ -465,5 +480,3 @@ int main( int argc, char * argv[] )
QgsDebugMsg( "************* all done ***************" );
return 0;
}


3 changes: 2 additions & 1 deletion src/mapserver/qgsgetrequesthandler.cpp
Expand Up @@ -5,7 +5,8 @@
#include <QUrl>
#include <stdlib.h>

QgsGetRequestHandler::QgsGetRequestHandler(): QgsHttpRequestHandler()
QgsGetRequestHandler::QgsGetRequestHandler()
: QgsHttpRequestHandler()
{
}

Expand Down
5 changes: 3 additions & 2 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -57,9 +57,10 @@ void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName,
}

QPair<QString, QString> urlLayerPair = qMakePair( url, layerName );
if ( mEntries.contains( urlLayerPair ) )
QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlLayerPair );
if ( it != mEntries.end() )
{
delete mEntries[ urlLayerPair ].layerPointer;
delete it.value().layerPointer;
}

QgsMSLayerCacheEntry newEntry;
Expand Down
13 changes: 10 additions & 3 deletions src/mapserver/qgsremoteowsbuilder.cpp
Expand Up @@ -24,12 +24,15 @@
#include <QDomElement>
#include <QTemporaryFile>

QgsRemoteOWSBuilder::QgsRemoteOWSBuilder( const QMap<QString, QString>& parameterMap ): QgsMSLayerBuilder(), mParameterMap( parameterMap )
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder( const QMap<QString, QString>& parameterMap )
: QgsMSLayerBuilder()
, mParameterMap( parameterMap )
{

}

QgsRemoteOWSBuilder::QgsRemoteOWSBuilder(): QgsMSLayerBuilder()
QgsRemoteOWSBuilder::QgsRemoteOWSBuilder()
: QgsMSLayerBuilder()
{

}
Expand All @@ -39,7 +42,11 @@ QgsRemoteOWSBuilder::~QgsRemoteOWSBuilder()

}

QgsMapLayer* QgsRemoteOWSBuilder::createMapLayer( const QDomElement& elem, const QString& layerName, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
QgsMapLayer* QgsRemoteOWSBuilder::createMapLayer(
const QDomElement& elem,
const QString& layerName,
QList<QTemporaryFile*>& filesToRemove,
QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
if ( elem.isNull() )
{
Expand Down
117 changes: 60 additions & 57 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -69,6 +69,16 @@ QgsWMSServer::QgsWMSServer()
{
}

void QgsWMSServer::appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats )
{
foreach( QString format, formats )
{
QDomElement formatElem = doc.createElement( "Format"/*wms:Format*/ );
formatElem.appendChild( doc.createTextNode( format ) );
elem.appendChild( formatElem );
}
}

QDomDocument QgsWMSServer::getCapabilities( QString version )
{
QgsDebugMsg( "Entering." );
Expand Down Expand Up @@ -101,25 +111,25 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
//wms:Request element
QDomElement requestElement = doc.createElement( "Request"/*wms:Request*/ );
capabilityElement.appendChild( requestElement );
//wms:GetCapabilities
QDomElement getCapabilitiesElement = doc.createElement( "GetCapabilities"/*wms:GetCapabilities*/ );
requestElement.appendChild( getCapabilitiesElement );
QDomElement capabilitiesFormatElement = doc.createElement( "Format" );/*wms:Format*/
getCapabilitiesElement.appendChild( capabilitiesFormatElement );
QDomText capabilitiesFormatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
capabilitiesFormatElement.appendChild( capabilitiesFormatText );

QDomElement dcpTypeElement = doc.createElement( "DCPType"/*wms:DCPType*/ );
getCapabilitiesElement.appendChild( dcpTypeElement );
QDomElement httpElement = doc.createElement( "HTTP"/*wms:HTTP*/ );
dcpTypeElement.appendChild( httpElement );

QDomElement elem;

//wms:GetCapabilities
elem = doc.createElement( "GetCapabilities"/*wms:GetCapabilities*/ );
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.wms_xml" : "text/xml" ) );
elem.appendChild( dcpTypeElement );
requestElement.appendChild( elem );

//Prepare url
//Some client requests already have http://<SERVER_NAME> in the REQUEST_URI variable
QString hrefString;
QString requestUrl = getenv( "REQUEST_URI" );
QUrl mapUrl( requestUrl );
mapUrl.setHost( QString( getenv( "SERVER_NAME" ) ) );
mapUrl.setHost( getenv( "SERVER_NAME" ) );

//Add non-default ports to url
QString portString = getenv( "SERVER_PORT" );
Expand Down Expand Up @@ -193,60 +203,52 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
olResourceElement.setAttribute( "xlink:href", hrefString );
getElement.appendChild( olResourceElement );

#if 0
// POST already used by SOAP
// QDomElement postElement = doc.createElement("post"/*wms:SOAP*/);
// httpElement.appendChild(postElement);
// QDomElement postResourceElement = doc.createElement("OnlineResource"/*wms:OnlineResource*/);
// postResourceElement.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
// postResourceElement.setAttribute("xlink:type","simple");
// postResourceElement.setAttribute("xlink:href", "http://" + QString(getenv("SERVER_NAME")) + QString(getenv("REQUEST_URI")));
// postElement.appendChild(postResourceElement);
// dcpTypeElement.appendChild(postElement);
QDomElement postElement = doc.createElement( "post"/*wms:SOAP*/ );
httpElement.appendChild( postElement );
QDomElement postResourceElement = doc.createElement( "OnlineResource"/*wms:OnlineResource*/ );
postResourceElement.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
postResourceElement.setAttribute( "xlink:type", "simple" );
postResourceElement.setAttribute( "xlink:href", "http://" + QString( getenv( "SERVER_NAME" ) ) + QString( getenv( "REQUEST_URI" ) ) );
postElement.appendChild( postResourceElement );
dcpTypeElement.appendChild( postElement );
#endif

//wms:GetMap
QDomElement getMapElement = doc.createElement( "GetMap"/*wms:GetMap*/ );
requestElement.appendChild( getMapElement );
QDomElement jpgFormatElement = doc.createElement( "Format"/*wms:Format*/ );
QDomText jpgFormatText = doc.createTextNode( "image/jpeg" );
jpgFormatElement.appendChild( jpgFormatText );
getMapElement.appendChild( jpgFormatElement );
QDomElement pngFormatElement = doc.createElement( "Format"/*wms:Format*/ );
QDomText pngFormatText = doc.createTextNode( "image/png" );
pngFormatElement.appendChild( pngFormatText );
getMapElement.appendChild( pngFormatElement );
QDomElement getMapDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getMapElement.appendChild( getMapDhcTypeElement );
elem = doc.createElement( "GetMap"/*wms:GetMap*/ );
appendFormats( doc, elem, QStringList() << "image/jpeg" << "image/png" );
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
requestElement.appendChild( elem );

//wms:GetFeatureInfo
QDomElement getFeatureInfoElem = doc.createElement( "GetFeatureInfo" );
//text/plain
QDomElement textFormatElem = doc.createElement( "Format" );
QDomText textFormatText = doc.createTextNode( "text/plain" );
textFormatElem.appendChild( textFormatText );
getFeatureInfoElem.appendChild( textFormatElem );
//text/html
QDomElement htmlFormatElem = doc.createElement( "Format" );
QDomText htmlFormatText = doc.createTextNode( "text/html" );
htmlFormatElem.appendChild( htmlFormatText );
getFeatureInfoElem.appendChild( htmlFormatElem );
//text/xml
QDomElement xmlFormatElem = doc.createElement( "Format" );
QDomText xmlFormatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
xmlFormatElem.appendChild( xmlFormatText );
getFeatureInfoElem.appendChild( xmlFormatElem );

//dcpType
QDomElement getFeatureInfoDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getFeatureInfoElem.appendChild( getFeatureInfoDhcTypeElement );
requestElement.appendChild( getFeatureInfoElem );
elem = doc.createElement( "GetFeatureInfo" );
appendFormats( doc, elem, QStringList() << "text/plain" << "text/html" << "text/xml" );
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
requestElement.appendChild( elem );

//wms:GetLegendGraphic
elem = doc.createElement( "GetLegendGraphic"/*wms:GetLegendGraphic*/ );
appendFormats( doc, elem, QStringList() << "jpeg" << "image/jpeg" << "image/png" );
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); // this is the same as for 'GetCapabilities'
requestElement.appendChild( elem );

//wms:GetStyles
elem = doc.createElement( "GetStyles"/*wms:GetStyles*/ );
appendFormats( doc, elem, QStringList() << "text/xml" );
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
requestElement.appendChild( elem );

//wms:GetPrint
elem = doc.createElement( "GetPrint"/*wms:GetPrint*/ );
appendFormats( doc, elem, QStringList() << "svg" << "png" << "pdf" );
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
requestElement.appendChild( elem );

//Exception element is mandatory
QDomElement exceptionElement = doc.createElement( "Exception" );
QDomElement exFormatElement = doc.createElement( "Format" );
QDomText formatText = doc.createTextNode( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" );
exFormatElement.appendChild( formatText );
exceptionElement.appendChild( exFormatElement );
capabilityElement.appendChild( exceptionElement );
elem = doc.createElement( "Exception" );
appendFormats( doc, elem, QStringList() << ( version == "1.1.1" ? "application/vnd.ogc.se_xml" : "text/xml" ) );
capabilityElement.appendChild( elem );

//Insert <ComposerTemplate> elements derived from wms:_ExtendedCapabilities
if ( mConfigParser )
Expand All @@ -271,6 +273,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
doc.save( capabilitiesStream, 4 );
}
#endif

return doc;
}

Expand Down Expand Up @@ -832,7 +835,7 @@ QImage* QgsWMSServer::initializeRendering( QStringList& layersList, QStringList&
}
//pass external GML to the SLD parser.
QString gml = mParameterMap.value( "GML" );
if( !gml.isEmpty() )
if ( !gml.isEmpty() )
{
QDomDocument* gmlDoc = new QDomDocument();
if ( gmlDoc->setContent( gml, true ) )
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -155,6 +155,8 @@ class QgsWMSServer
/**Clear all feature selections in the given layers*/
void clearFeatureSelections( const QStringList& layerIds ) const;

void appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats );

/**Map containing the WMS parameters*/
QMap<QString, QString> mParameterMap;
QgsConfigParser* mConfigParser;
Expand Down

0 comments on commit 079713d

Please sign in to comment.