public void testPngIntegration() throws Exception { String layerId = getLayerId(MockData.BASIC_POLYGONS); MockHttpServletResponse sr = getAsServletResponse("gwc/service/wmts?request=GetTile&layer=" + layerId + "&format=image/png&tilematrixset=EPSG:4326&tilematrix=EPSG:4326:0&tilerow=0&tilecol=0"); assertEquals(200, sr.getErrorCode()); assertEquals("image/png", sr.getContentType()); }
/** * If direct WMS integration is enabled, a GetMap requests that hits the regular WMS but matches * a gwc tile should return with the proper {@code geowebcache-tile-index} HTTP response header. */ public void testDirectWMSIntegration() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); String request; MockHttpServletResponse response; request = buildGetMap(true, layerName, "EPSG:4326", null); response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertNull(response.getHeader("geowebcache-tile-index")); request = request + "&tiled=true"; response = getAsServletResponse(request); assertEquals(200, response.getErrorCode()); assertEquals("image/png", response.getContentType()); }
public void testDirectWMSIntegrationWithVirtualServicesHiddenLayer() throws Exception { /* * Nothing special needs to be done at the GWC integration level for this to work. The hard * work should already be done by WMSWorkspaceQualifier so that when the request hits GWC * the layer name is already qualified */ final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final String localName = BASIC_POLYGONS.getLocalPart(); final TileLayer tileLayer = gwc.getTileLayerByName(qualifiedName); assertNotNull(tileLayer); boolean directWMSIntegrationEndpoint = true; String request = MockData.CDF_PREFIX // asking /geoserver/cdf/wms? for cite:BasicPolygons + "/" + buildGetMap(directWMSIntegrationEndpoint, localName, "EPSG:4326", null, tileLayer) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertTrue(response.getContentType(), response.getContentType().startsWith("application/vnd.ogc.se_xml")); assertTrue(response.getOutputStreamContent(), response.getOutputStreamContent() .contains("Could not find layer cdf:BasicPolygons")); }
public void testDirectWMSIntegrationResponseHeaders() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); String request = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertEquals(layerName, response.getHeader("geowebcache-layer")); assertEquals("[0, 0, 0]", response.getHeader("geowebcache-tile-index")); assertEquals("-180.0,-90.0,0.0,90.0", response.getHeader("geowebcache-tile-bounds")); assertEquals("EPSG:4326", response.getHeader("geowebcache-gridset")); assertEquals("EPSG:4326", response.getHeader("geowebcache-crs")); }
public void testDirectWMSIntegrationMaxAge() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final GeoServerTileLayer tileLayer = (GeoServerTileLayer) gwc.getTileLayerByName(qualifiedName); tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", "true"); tileLayer.getLayerInfo().getResource().getMetadata().put("cacheAgeMax", 3456); MockHttpServletResponse response = getAsServletResponse(path); String cacheControl = response.getHeader("Cache-Control"); assertEquals("max-age=3456", cacheControl); assertNotNull(response.getHeader("Last-Modified")); tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", "false"); response = getAsServletResponse(path); cacheControl = response.getHeader("Cache-Control"); assertEquals("no-cache", cacheControl); // make sure a boolean is handled, too - see comment in CachingWebMapService tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", Boolean.FALSE); response = getAsServletResponse(path); cacheControl = response.getHeader("Cache-Control"); assertEquals("no-cache", cacheControl); }
public void testDirectWMSIntegrationWithVirtualServices() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final String localName = BASIC_POLYGONS.getLocalPart(); final TileLayer tileLayer = gwc.getTileLayerByName(qualifiedName); assertNotNull(tileLayer); boolean directWMSIntegrationEndpoint = true; String request = MockData.CITE_PREFIX + "/" + buildGetMap(directWMSIntegrationEndpoint, localName, "EPSG:4326", null, tileLayer) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertEquals(qualifiedName, response.getHeader("geowebcache-layer")); }
public void testDirectWMSIntegrationIfModifiedSinceSupport() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(path); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); String lastModifiedHeader = response.getHeader("Last-Modified"); assertNotNull(lastModifiedHeader); Date lastModified = DateUtil.parseDate(lastModifiedHeader); MockHttpServletRequest httpReq = createRequest(path); httpReq.setMethod("GET"); httpReq.setBodyContent(new byte[] {}); httpReq.setHeader("If-Modified-Since", lastModifiedHeader); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); // set the If-Modified-Since header to some point in the past of the last modified value Date past = new Date(lastModified.getTime() - 5000); String ifModifiedSince = DateUtil.formatDate(past); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); Date future = new Date(lastModified.getTime() + 5000); ifModifiedSince = DateUtil.formatDate(future); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); }