Commit a8f3e9cf authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-9120] Assorted issues when using WMTS restful bindings in virtual workspace services

parent 36db838d
......@@ -16,6 +16,6 @@ public class ResponseUtilsURLMangler implements URLMangler {
String base = StringUtils.strip(baseURL, "/");
String cp = "/" + StringUtils.strip(contextPath, "/");
String rest = cp + "/" + StringUtils.stripStart(path, "/");
return ResponseUtils.buildURL(base, rest, null, URLType.RESOURCE);
return ResponseUtils.buildURL(base, rest, null, URLType.SERVICE);
}
}
......@@ -5,6 +5,7 @@
*/
package org.geoserver.gwc.dispatch;
import com.google.common.base.Strings;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
......@@ -47,6 +48,15 @@ public class GwcServiceDispatcherCallback extends AbstractDispatcherCallback
private static final Pattern GWC_LAYER_VIRTUAL_SERVICE_PATTERN =
Pattern.compile("([^/]+)/([^/]+)/gwc/service.*");
static final String buildRestPattern(int numPathElements) {
return ".*/service/wmts/rest" + Strings.repeat("/([^/]+)", numPathElements);
}
private static final Pattern TILE_1 = Pattern.compile(buildRestPattern(5));
private static final Pattern TILE_2 = Pattern.compile(buildRestPattern(6));
private static final Pattern FEATUREINFO_1 = Pattern.compile(buildRestPattern(7));
private static final Pattern FEATUREINFO_2 = Pattern.compile(buildRestPattern(8));
private final Catalog catalog;
public GwcServiceDispatcherCallback(Catalog catalog) {
......@@ -66,8 +76,23 @@ public class GwcServiceDispatcherCallback extends AbstractDispatcherCallback
return null;
}
// storing the current operation
GWC_OPERATION.set((String) request.getKvp().get("REQUEST"));
// storing the current operation (bridge the RESTful bindings that do not have a
// REQUEST parameter by matching their paths)
String requestName = (String) request.getKvp().get("REQUEST");
final String pathInfo = request.getHttpRequest().getPathInfo();
if (requestName == null
&& pathInfo != null
&& pathInfo.contains("gwc/service/wmts/rest/")) {
if (pathInfo.endsWith("WMTSCapabilities.xml")) {
requestName = "GetCapabilities";
} else if (TILE_1.matcher(pathInfo).matches() || TILE_2.matcher(pathInfo).matches()) {
requestName = "GetTile";
} else if (FEATUREINFO_1.matcher(pathInfo).matches()
|| FEATUREINFO_2.matcher(pathInfo).matches()) {
requestName = "GetFeatureInfo";
}
}
GWC_OPERATION.set(requestName);
Map<String, String> kvp = new HashMap<>();
kvp.put("service", "gwc");
......
......@@ -26,7 +26,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.config.util.SecureXStream;
import org.geoserver.ows.LocalWorkspace;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resource.Type;
......@@ -165,7 +167,7 @@ public class DefaultTileLayerCatalog implements TileLayerCatalog {
@Override
public GeoServerTileLayerInfo getLayerByName(String layerName) {
checkInitialized();
String id = layersByName.get(layerName);
String id = getLayerId(layerName);
if (id == null) {
return null;
}
......@@ -416,6 +418,10 @@ public class DefaultTileLayerCatalog implements TileLayerCatalog {
@Override
public String getLayerId(String layerName) {
checkInitialized();
final WorkspaceInfo ws = LocalWorkspace.get();
if (ws != null && !layerName.startsWith(ws.getName() + ":")) {
layerName = ws.getName() + ":" + layerName;
}
return layersByName.get(layerName);
}
......
......@@ -1826,13 +1826,13 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
doc));
// check tile resources
assertEquals(
"http://localhost:8080/geoserver/cite/gwc/service/wmts/rest/cite:BasicPolygons/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png",
"http://localhost:8080/geoserver/cite/gwc/service/wmts/rest/BasicPolygons/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/png",
WMTS_XPATH_10.evaluate(
"//wmts:Contents/wmts:Layer[ows:Title='BasicPolygons']/wmts:ResourceURL[@format='image/png' and @resourceType='tile']/@template",
doc));
// check featureinfo resource
assertEquals(
"http://localhost:8080/geoserver/cite/gwc/service/wmts/rest/cite:BasicPolygons/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}?format=text/plain",
"http://localhost:8080/geoserver/cite/gwc/service/wmts/rest/BasicPolygons/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}?format=text/plain",
WMTS_XPATH_10.evaluate(
"//wmts:Contents/wmts:Layer[ows:Title='BasicPolygons']/wmts:ResourceURL[@format='text/plain' and @resourceType='FeatureInfo']/@template",
doc));
......@@ -1878,8 +1878,6 @@ public class GWCIntegrationTest extends GeoServerSystemTestSupport {
+ "/gwc"
+ WMTSService.REST_PATH
+ "/"
+ MockData.BASIC_POLYGONS.getPrefix()
+ ":"
+ MockData.BASIC_POLYGONS.getLocalPart()
+ "/EPSG:4326/EPSG:4326:0/0/0?format=image/png");
request.setMethod("GET");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment