Skip to content

Commit

Permalink
Update MapMLBaseProxyTest.java to check the cascaded request against the
Browse files Browse the repository at this point in the history
request URL from the capabilities document OR if that is null, use the
URL OF the capabilities document as the base.

Update assertCascading in MapMLWMTSProxyTest.java to compare against 
resource request URL from capabilities document OR if that is null,
use the URL OF the capabilities document as the base.
  • Loading branch information
prushforth committed Oct 15, 2024
1 parent dddab5c commit 5290d51
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,24 @@ private String generateURL(String path, HashMap<String, String> params, LayerInf
if (cascadeToRemote) {
// if we reach this point, we can finally cascade.
// Let's update all the params for the cascading
baseUrl =
getResourceURL.getProtocol()
+ "://"
+ getResourceURL.getHost()
+ (getResourceURL.getPort() == -1
? ""
: ":" + getResourceURL.getPort())
+ "/";

path = getResourceURL.getPath();
// getResourceURL may be null if the capabilities doc is misconfigured;
if (getResourceURL != null) {
baseUrl =
getResourceURL.getProtocol()
+ "://"
+ getResourceURL.getHost()
+ (getResourceURL.getPort() == -1
? ""
: ":" + getResourceURL.getPort())
+ "/";

path = getResourceURL.getPath();
} else {
// if misconfigured capabilites, use cap document URL as base
String[] baseUrlAndPath = getBaseUrlAndPath(capabilitiesURL);
baseUrl = baseUrlAndPath[0];
path = baseUrlAndPath[1];
}
urlType = URLMangler.URLType.EXTERNAL;
updateRequestParams(
params, layerName, version, requestedCRS, tileMatrixSet, infoFormats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
import java.io.ByteArrayInputStream;
import java.net.URL;
import java.util.Map;
import java.util.regex.Pattern;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.XpathEngine;
import org.geotools.ows.wms.WMSCapabilities;
import org.geotools.ows.wms.WebMapServer;
import org.geotools.ows.wmts.WebMapTileServer;
import org.geotools.ows.wmts.model.WMTSCapabilities;
import org.junit.AfterClass;
import org.junit.Before;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -114,27 +113,24 @@ protected void assertCascading(boolean shouldCascade, String url) throws Excepti

if (shouldCascade) {
URL getResourceURL = null;
boolean cascadingWMS = getCapabilitiesURL().matches(".*SERVICE=WMS.*");
if (cascadingWMS) {
WebMapServer wms = new WebMapServer(new URL(getCapabilitiesURL()));
WMSCapabilities capabilities = wms.getCapabilities();
getResourceURL = capabilities.getRequest().getGetMap().getGet();
} else {
WebMapTileServer wmts = new WebMapTileServer(new URL(getCapabilitiesURL()));
WMTSCapabilities capabilities = wmts.getCapabilities();
getResourceURL = capabilities.getRequest().getGetTile().getGet();
}
Pattern serviceTypeRE = Pattern.compile(".*SERVICE=WMS.*", Pattern.CASE_INSENSITIVE);
boolean cascadingWMS = serviceTypeRE.matcher(getCapabilitiesURL()).find();
assertTrue(cascadingWMS);
WebMapServer wms = new WebMapServer(new URL(getCapabilitiesURL()));
WMSCapabilities capabilities = wms.getCapabilities();
getResourceURL = capabilities.getRequest().getGetMap().getGet();
URL baseResourceURL =
getResourceURL != null ? getResourceURL : new URL(getCapabilitiesURL());
URL base =
new URL(
getResourceURL.getProtocol()
baseResourceURL.getProtocol()
+ "://"
+ getResourceURL.getHost()
+ (getResourceURL.getPort() == -1
+ baseResourceURL.getHost()
+ (baseResourceURL.getPort() == -1
? ""
: ":" + getResourceURL.getPort())
: ":" + baseResourceURL.getPort())
+ "/");
String path = getResourceURL.getPath();

String path = baseResourceURL.getPath();
assertTrue(url.startsWith((new URL(base, path)).toString()));
assertTrue(url.contains("layers=topp:states"));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
*/
package org.geoserver.mapml;

import static org.geoserver.mapml.MapMLBaseProxyTest.getCapabilitiesURL;
import static org.geowebcache.grid.GridSubsetFactory.createGridSubSet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URL;
import java.util.regex.Pattern;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.ResourceInfo;
Expand All @@ -19,6 +22,8 @@
import org.geoserver.gwc.config.GWCConfig;
import org.geoserver.gwc.layer.GeoServerTileLayer;
import org.geoserver.mapml.gwc.gridset.MapMLGridsets;
import org.geotools.ows.wmts.WebMapTileServer;
import org.geotools.ows.wmts.model.WMTSCapabilities;
import org.geowebcache.grid.GridSubset;
import org.geowebcache.mime.TextMime;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -118,15 +123,31 @@ public void testRemoteVsNotRemote() throws Exception {
}

@Override
protected void assertCascading(boolean shouldCascade, String url) {
assertTrue(url.contains("service=WMTS"));
protected void assertCascading(boolean shouldCascade, String url) throws Exception {
URL getResourceURL = null;
Pattern serviceTypeRE = Pattern.compile(".*SERVICE=WMTS.*", Pattern.CASE_INSENSITIVE);
boolean isWMTSService = serviceTypeRE.matcher(getCapabilitiesURL()).find();
assertTrue(isWMTSService);
if (shouldCascade) {
WebMapTileServer wmts = new WebMapTileServer(new URL(getCapabilitiesURL()));
WMTSCapabilities capabilities = wmts.getCapabilities();
getResourceURL = capabilities.getRequest().getGetTile().getGet();
URL baseResourceURL =
getResourceURL != null ? getResourceURL : new URL(getCapabilitiesURL());
URL base =
new URL(
baseResourceURL.getProtocol()
+ "://"
+ baseResourceURL.getHost()
+ (baseResourceURL.getPort() == -1
? ""
: ":" + baseResourceURL.getPort())
+ "/");
String path = baseResourceURL.getPath();
assertTrue(url.startsWith((new URL(base, path)).toString()));
// The remote capabilities defines a custom GridSet that matches
// the OSMTILE with a different name: MATCHING_OSMTILE
// Identifiers are also not simple numbers but contain a common prefix.
assertTrue(
url.startsWith(
"http://localhost:" + mockService.port() + MOCK_SERVER + CONTEXT));
assertTrue(url.contains("layer=topp:states"));
assertTrue(url.contains("tilematrixset=MATCHING_OSMTILE"));
// Common prefix has been pre-pended to the tilematrix z input
Expand Down

0 comments on commit 5290d51

Please sign in to comment.