Skip to content

Commit

Permalink
Merge pull request #4700 from sbrunner/service-onlineressource
Browse files Browse the repository at this point in the history
[Server] WMS Fix the mandatory OnlineResource
  • Loading branch information
rldhont committed Jun 9, 2017
2 parents f80a1f5 + 9d9e94e commit 0489839
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -195,7 +195,7 @@ namespace QgsWms
doc.appendChild( wmsCapabilitiesElement );

//INSERT Service
wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version ) );
wmsCapabilitiesElement.appendChild( getServiceElement( doc, project, version, request ) );

//wms:Capability element
QDomElement capabilityElement = getCapabilityElement( doc, project, version, request, projectSettings );
Expand All @@ -222,7 +222,8 @@ namespace QgsWms
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 );

Expand Down Expand Up @@ -283,14 +284,15 @@ namespace QgsWms
}

QString onlineResource = QgsServerProjectUtils::owsServiceOnlineResource( *project );
if ( !onlineResource.isEmpty() )
if ( onlineResource.isEmpty() )
{
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 );
onlineResource = serviceUrl( request, project ).toString();
}
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 contactOrganization = QgsServerProjectUtils::owsServiceContactOrganization( *project );
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wms/qgswmsgetcapabilities.h
Expand Up @@ -61,7 +61,8 @@ namespace QgsWms
/**
* 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
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsserver.py
Expand Up @@ -66,7 +66,7 @@ def assertXMLEqual(self, response, expected, msg=''):
response_lines = response.splitlines()
expected_lines = expected.splitlines()
line_no = 1
self.assertEqual(len(expected_lines), len(response_lines), "Expected and response have different number of lines!")
self.assertEqual(len(expected_lines), len(response_lines), "Expected and response have different number of lines!\n{}".format(msg))
for expected_line in expected_lines:
expected_line = expected_line.strip()
response_line = response_lines[line_no - 1].strip()
Expand Down
7 changes: 3 additions & 4 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -62,7 +62,7 @@ def wms_request_compare(self, request, extra=None, reference_file=None):
response = re.sub(RE_STRIP_UNCHECKABLE, b'*****', response)
expected = re.sub(RE_STRIP_UNCHECKABLE, b'*****', expected)

self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected.decode('utf-8'), response.decode('utf-8')))
self.assertXMLEqual(response, expected, msg="request %s failed.\nQuery: %s\nExpected file: %s\nResponse:\n%s" % (query_string, request, reference_path, response.decode('utf-8')))

def test_project_wms(self):
"""Test some WMS request"""
Expand Down Expand Up @@ -151,7 +151,7 @@ def wms_inspire_request_compare(self, request):
f.close()
response = re.sub(RE_STRIP_UNCHECKABLE, b'', response)
expected = re.sub(RE_STRIP_UNCHECKABLE, b'', expected)
self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected.decode('utf-8'), response.decode('utf-8')))
self.assertXMLEqual(response, expected, msg="request %s failed.\nQuery: %s\nExpected file: %s\nResponse:\n%s" % (query_string, request, reference_path, response.decode('utf-8')))

def test_project_wms_inspire(self):
"""Test some WMS request"""
Expand Down Expand Up @@ -572,8 +572,7 @@ def test_wms_getcapabilities_url(self):

item_found = False
for item in str(r).split("\\n"):
if "OnlineResource" in item:
self.assertEqual("xlink:href=\"my_wms_advertised_url?" in item, True)
if "OnlineResource" in item and "xlink:href=\"my_wms_advertised_url?" in item:
item_found = True
self.assertTrue(item_found)

Expand Down
1 change: 1 addition & 0 deletions tests/testdata/qgis_server/getcapabilities.txt
Expand Up @@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</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>
<ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson>
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/qgis_server/getcapabilities_inspire.txt
Expand Up @@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</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>
<ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson>
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/qgis_server/getprojectsettings.txt
Expand Up @@ -10,6 +10,7 @@ Content-Type: text/xml; charset=utf-8
<KeywordList>
<Keyword vocabulary="ISO">infoMapAccessService</Keyword>
</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>
<ContactPersonPrimary>
<ContactPerson>Alessandro Pasotti</ContactPerson>
Expand Down

0 comments on commit 0489839

Please sign in to comment.