-
Notifications
You must be signed in to change notification settings - Fork 291
[GEOS-12149] GeoServer WMTS capabilities put query parameters in the wrong place in generated URLs #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fernandor777
wants to merge
1
commit into
GeoWebCache:main
Choose a base branch
from
fernandor777:wmts-cap-param
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[GEOS-12149] GeoServer WMTS capabilities put query parameters in the wrong place in generated URLs #1554
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,7 @@ public class WMTSGetCapabilities { | |
|
|
||
| private GridSetBroker gsb; | ||
|
|
||
| private String baseUrl; | ||
|
|
||
| private String restBaseUrl; | ||
| private final WMTSUrls urls; | ||
|
|
||
| private final Collection<WMTSExtension> extensions; | ||
|
|
||
|
|
@@ -90,21 +88,31 @@ protected WMTSGetCapabilities( | |
| String contextPath, | ||
| URLMangler urlMangler, | ||
| Collection<WMTSExtension> extensions) { | ||
| this(tld, gsb, servReq, buildUrls(servReq, baseUrl, contextPath, urlMangler), extensions); | ||
| } | ||
|
|
||
| protected WMTSGetCapabilities( | ||
| TileLayerDispatcher tld, | ||
| GridSetBroker gsb, | ||
| HttpServletRequest servReq, | ||
| WMTSUrls urls, | ||
| Collection<WMTSExtension> extensions) { | ||
| this.tld = tld; | ||
| this.gsb = gsb; | ||
| this.urls = urls; | ||
| this.extensions = extensions; | ||
| } | ||
|
|
||
| private static WMTSUrls buildUrls( | ||
| HttpServletRequest servReq, String baseUrl, String contextPath, URLMangler urlMangler) { | ||
| String forcedBaseUrl = | ||
| ServletUtils.stringFromMap(servReq.getParameterMap(), servReq.getCharacterEncoding(), "base_url"); | ||
|
|
||
| if (forcedBaseUrl != null) { | ||
| this.baseUrl = forcedBaseUrl; | ||
| } else { | ||
| this.baseUrl = urlMangler.buildURL(baseUrl, contextPath, WMTSService.SERVICE_PATH); | ||
| } | ||
|
|
||
| this.restBaseUrl = urlMangler.buildURL(baseUrl, contextPath, WMTSService.REST_PATH); | ||
|
|
||
| this.extensions = extensions; | ||
| String effectiveBaseUrl = forcedBaseUrl != null ? forcedBaseUrl : baseUrl; | ||
| URLMangler.UrlAndParams service = | ||
| urlMangler.buildURL(effectiveBaseUrl, contextPath, WMTSService.SERVICE_PATH, Collections.emptyMap()); | ||
| URLMangler.UrlAndParams rest = | ||
| urlMangler.buildURL(effectiveBaseUrl, contextPath, WMTSService.REST_PATH, Collections.emptyMap()); | ||
| return new WMTSUrls(service.url(), service.queryParameters(), rest.url(), rest.queryParameters()); | ||
| } | ||
|
|
||
| protected void writeResponse(HttpServletResponse response, RuntimeStats stats) { | ||
|
|
@@ -169,11 +177,18 @@ private String generateGetCapabilities(Charset encoding) { | |
| contents(xml); | ||
|
|
||
| xml.indentElement("ServiceMetadataURL") | ||
| .attribute("xlink:href", WMTSUtils.getKvpServiceMetadataURL(baseUrl)) | ||
| .attribute( | ||
| "xlink:href", | ||
| WMTSUtils.appendQueryParameters( | ||
| WMTSUtils.getKvpServiceMetadataURL(urls.serviceBaseUrl()), | ||
| urls.serviceQueryParameters())) | ||
|
Comment on lines
+182
to
+184
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eugh, this is somewhat painful to read... I think it would read bettter if you had it in WMTSUrls instead, something like: |
||
| .endElement(); | ||
|
|
||
| xml.indentElement("ServiceMetadataURL") | ||
| .attribute("xlink:href", restBaseUrl + "/WMTSCapabilities.xml") | ||
| .attribute( | ||
| "xlink:href", | ||
| WMTSUtils.appendQueryParameters( | ||
| urls.restBaseUrl() + "/WMTSCapabilities.xml", urls.restQueryParameters())) | ||
| .endElement(); | ||
|
|
||
| xml.endElement("Capabilities"); | ||
|
|
@@ -365,9 +380,9 @@ private void serviceProvider(XMLBuilder xml, ServiceInformation servInfo) throws | |
| xml.endElement(); | ||
| } | ||
| } else { | ||
| appendTag(xml, "ows:ProviderName", baseUrl, null); | ||
| appendTag(xml, "ows:ProviderName", urls.serviceBaseUrl(), null); | ||
| xml.indentElement("ows:ProviderSite") | ||
| .attribute("xlink:href", baseUrl) | ||
| .attribute("xlink:href", urls.serviceBaseUrl()) | ||
| .endElement(); | ||
| xml.indentElement("ows:ServiceContact"); | ||
| appendTag(xml, "ows:IndividualName", "GeoWebCache User", null); | ||
|
|
@@ -379,9 +394,9 @@ private void serviceProvider(XMLBuilder xml, ServiceInformation servInfo) throws | |
|
|
||
| private void operationsMetadata(XMLBuilder xml) throws IOException { | ||
| xml.indentElement("ows:OperationsMetadata"); | ||
| operation(xml, "GetCapabilities", baseUrl); | ||
| operation(xml, "GetTile", baseUrl); | ||
| operation(xml, "GetFeatureInfo", baseUrl); | ||
| operation(xml, "GetCapabilities", urls.serviceBaseUrl(), urls.serviceQueryParameters()); | ||
| operation(xml, "GetTile", urls.serviceBaseUrl(), urls.serviceQueryParameters()); | ||
| operation(xml, "GetFeatureInfo", urls.serviceBaseUrl(), urls.serviceQueryParameters()); | ||
| // allow extension to inject their own metadata | ||
| for (WMTSExtension extension : extensions) { | ||
| List<WMTSExtension.OperationMetadata> operationsMetaData = extension.getExtraOperationsMetadata(); | ||
|
|
@@ -390,22 +405,27 @@ private void operationsMetadata(XMLBuilder xml) throws IOException { | |
| operation( | ||
| xml, | ||
| operationMetadata.getName(), | ||
| operationMetadata.getBaseUrl() == null ? baseUrl : operationMetadata.getBaseUrl()); | ||
| operationMetadata.getBaseUrl() == null | ||
| ? urls.serviceBaseUrl() | ||
| : operationMetadata.getBaseUrl(), | ||
| urls.serviceQueryParameters()); | ||
| } | ||
| } | ||
| extension.encodedOperationsMetadata(xml); | ||
| } | ||
| xml.endElement("ows:OperationsMetadata"); | ||
| } | ||
|
|
||
| private void operation(XMLBuilder xml, String operationName, String baseUrl) throws IOException { | ||
| private void operation(XMLBuilder xml, String operationName, String baseUrl, Map<String, String> queryParameters) | ||
| throws IOException { | ||
| xml.indentElement("ows:Operation").attribute("name", operationName); | ||
| xml.indentElement("ows:DCP"); | ||
| xml.indentElement("ows:HTTP"); | ||
| if (baseUrl.contains("?")) { | ||
| xml.indentElement("ows:Get").attribute("xlink:href", baseUrl + "&"); | ||
| String href = WMTSUtils.appendQueryParameters(baseUrl, queryParameters); | ||
| if (href.contains("?")) { | ||
| xml.indentElement("ows:Get").attribute("xlink:href", href + "&"); | ||
| } else { | ||
| xml.indentElement("ows:Get").attribute("xlink:href", baseUrl + "?"); | ||
| xml.indentElement("ows:Get").attribute("xlink:href", href + "?"); | ||
| } | ||
| xml.indentElement("ows:Constraint").attribute("name", "GetEncoding"); | ||
| xml.indentElement("ows:AllowedValues"); | ||
|
|
@@ -426,7 +446,7 @@ private void contents(XMLBuilder xml) throws IOException { | |
| if (!layer.isEnabled() || !layer.isAdvertised()) { | ||
| continue; | ||
| } | ||
| layer(xml, layer, baseUrl, usedGridsets); | ||
| layer(xml, layer, urls.serviceBaseUrl(), usedGridsets); | ||
| } | ||
|
|
||
| // only dump the gridsets actually used, as the OGC TMS spec introduced many default ones | ||
|
|
@@ -488,7 +508,7 @@ private void layer(XMLBuilder xml, TileLayer layer, String baseurl, Set<GridSet> | |
|
|
||
| layerGridSubSets(xml, layer, usedGridsets); | ||
|
|
||
| layerResourceUrls(xml, layer, filters, restBaseUrl); | ||
| layerResourceUrls(xml, layer, filters, urls.restBaseUrl(), urls.restQueryParameters()); | ||
|
|
||
| // allow extensions to contribute extra metadata to this layer | ||
| for (WMTSExtension extension : extensions) { | ||
|
|
@@ -712,7 +732,12 @@ private void layerGridSubSets(XMLBuilder xml, TileLayer layer, Set<GridSet> used | |
| * For each layer discovers the available image formats, feature info formats and dimensions and produce the | ||
| * necessary <ResourceURL> elements. | ||
| */ | ||
| private void layerResourceUrls(XMLBuilder xml, TileLayer layer, List<ParameterFilter> filters, String baseurl) | ||
| private void layerResourceUrls( | ||
| XMLBuilder xml, | ||
| TileLayer layer, | ||
| List<ParameterFilter> filters, | ||
| String baseurl, | ||
| Map<String, String> queryParameters) | ||
| throws IOException { | ||
| String baseTemplate = baseurl + "/" + layer.getName(); | ||
| String commonTemplate = baseTemplate + "/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}"; | ||
|
|
@@ -728,21 +753,25 @@ private void layerResourceUrls(XMLBuilder xml, TileLayer layer, List<ParameterFi | |
| // Extracts image formats | ||
| List<String> mimeFormats = WMTSUtils.getLayerFormats(layer); | ||
| for (String format : mimeFormats) { | ||
| String template = commonTemplate + "?format=" + format + commonDimensions; | ||
| String template = WMTSUtils.appendQueryParameters( | ||
| commonTemplate + "?format=" + format + commonDimensions, queryParameters); | ||
| layerResourceUrlsGen(xml, format, "tile", template); | ||
| } | ||
| // Extracts feature info formats | ||
| List<String> infoFormats = WMTSUtils.getInfoFormats(layer); | ||
| for (String format : infoFormats) { | ||
| String template = commonTemplate + "/{J}/{I}?format=" + format + commonDimensions; | ||
| String template = WMTSUtils.appendQueryParameters( | ||
| commonTemplate + "/{J}/{I}?format=" + format + commonDimensions, queryParameters); | ||
| layerResourceUrlsGen(xml, format, "FeatureInfo", template); | ||
| } | ||
| if (layer instanceof TileJSONProvider provider) { | ||
| List<String> formatExtensions = WMTSUtils.getLayerFormatsExtensions(layer); | ||
| String outputFormat = ApplicationMime.json.getFormat(); | ||
| if (provider.supportsTileJSON()) { | ||
| for (String tileJsonFormat : formatExtensions) { | ||
| String template = baseTemplate + "/{style}/tilejson/" + tileJsonFormat + "?format=" + outputFormat; | ||
| String template = WMTSUtils.appendQueryParameters( | ||
| baseTemplate + "/{style}/tilejson/" + tileJsonFormat + "?format=" + outputFormat, | ||
| queryParameters); | ||
| layerResourceUrlsGen(xml, outputFormat, "TileJSON", template); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep on familiar grounds and expose a method just like the GeoServer one instead:
The kvp is meant to be modified by the callers.