Fix the mandatory OnlineResource

This commit is contained in:
Stéphane Brunner 2017-06-08 15:19:31 +02:00
parent 2346f59f56
commit 9d9e94e6b9
6 changed files with 16 additions and 11 deletions

View File

@ -195,7 +195,7 @@ namespace QgsWms
doc.appendChild( wmsCapabilitiesElement ); doc.appendChild( wmsCapabilitiesElement );
//INSERT Service //INSERT Service
wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version ) ); wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version, request ) );
//wms:Capability element //wms:Capability element
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings ); QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings );
@ -222,7 +222,8 @@ namespace QgsWms
return doc; return doc;
} }
QDomElement getServiceElement( QDomDocument &doc, const QgsProject *project, const QString &version ) QDomElement getServiceElement( QDomDocument &doc, const QgsProject *project, const QString &version,
const QgsServerRequest &request )
{ {
bool sia2045 = QgsServerProjectUtils::wmsInfoFormatSia2045( *project ); bool sia2045 = QgsServerProjectUtils::wmsInfoFormatSia2045( *project );
@ -283,14 +284,15 @@ namespace QgsWms
} }
QString onlineResource = QgsServerProjectUtils::owsServiceOnlineResource( *project ); QString onlineResource = QgsServerProjectUtils::owsServiceOnlineResource( *project );
if ( !onlineResource.isEmpty() ) if ( onlineResource.isEmpty() )
{ {
QDomElement onlineResourceElem = doc.createElement( QStringLiteral( "OnlineResource" ) ); onlineResource = serviceUrl( request, project ).toString();
onlineResourceElem.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
onlineResourceElem.setAttribute( QStringLiteral( "xlink:type" ), QStringLiteral( "simple" ) );
onlineResourceElem.setAttribute( QStringLiteral( "xlink:href" ), onlineResource );
serviceElem.appendChild( onlineResourceElem );
} }
QDomElement onlineResourceElem = doc.createElement( QStringLiteral( "OnlineResource" ) );
onlineResourceElem.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
onlineResourceElem.setAttribute( QStringLiteral( "xlink:type" ), QStringLiteral( "simple" ) );
onlineResourceElem.setAttribute( QStringLiteral( "xlink:href" ), onlineResource );
serviceElem.appendChild( onlineResourceElem );
QString contactPerson = QgsServerProjectUtils::owsServiceContactPerson( *project ); QString contactPerson = QgsServerProjectUtils::owsServiceContactPerson( *project );
QString contactOrganization = QgsServerProjectUtils::owsServiceContactOrganization( *project ); QString contactOrganization = QgsServerProjectUtils::owsServiceContactOrganization( *project );

View File

@ -61,7 +61,8 @@ namespace QgsWms
/** /**
* Create Service element for get capabilities document * Create Service element for get capabilities document
*/ */
QDomElement getServiceElement( QDomDocument &doc, const QgsProject *project, const QString &version ); QDomElement getServiceElement( QDomDocument &doc, const QgsProject *project, const QString &version,
const QgsServerRequest &request );
/** Output GetCapabilities response /** Output GetCapabilities response
*/ */

View File

@ -572,8 +572,7 @@ class TestQgsServerWMS(QgsServerTestBase):
item_found = False item_found = False
for item in str(r).split("\\n"): for item in str(r).split("\\n"):
if "OnlineResource" in item: if "OnlineResource" in item and "xlink:href=\"my_wms_advertised_url?" in item:
self.assertEqual("xlink:href=\"my_wms_advertised_url?" in item, True)
item_found = True item_found = True
self.assertTrue(item_found) self.assertTrue(item_found)

View File

@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList> <KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword> <Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList> </KeywordList>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?MAP=tests/testdata/qgis_server/test_project.qgs&amp;" xmlns:xlink="http://www.w3.org/1999/xlink"/>
<ContactInformation> <ContactInformation>
<ContactPersonPrimary> <ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson> <ContactPerson>Alessandro Pasotti</ContactPerson>

View File

@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList> <KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword> <Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList> </KeywordList>
<OnlineResource xlink:type="simple" xlink:href="?MAP=tests/testdata/qgis_server/test_project_inspire.qgs&amp;" xmlns:xlink="http://www.w3.org/1999/xlink"/>
<ContactInformation> <ContactInformation>
<ContactPersonPrimary> <ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson> <ContactPerson>Alessandro Pasotti</ContactPerson>

View File

@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList> <KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword> <Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</KeywordList> </KeywordList>
<OnlineResource xlink:type="simple" xlink:href="https://www.qgis.org/?MAP=tests/testdata/qgis_server/test_project.qgs&amp;" xmlns:xlink="http://www.w3.org/1999/xlink"/>
<ContactInformation> <ContactInformation>
<ContactPersonPrimary> <ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson> <ContactPerson>Alessandro Pasotti</ContactPerson>