private void layerDimensions(XMLBuilder xml, TileLayer layer, List<ParameterFilter> filters) throws IOException { List<ParameterFilter> layerDimensions = WMTSUtils.getLayerDimensions(filters); for (ParameterFilter dimension : layerDimensions) { dimensionDescription(xml, dimension, dimension.getLegalValues()); } }
private void operationsMetadata(XMLBuilder xml) throws IOException { xml.indentElement("ows:OperationsMetadata"); operation(xml, "GetCapabilities", baseUrl); operation(xml, "GetTile", baseUrl); operation(xml, "GetFeatureInfo", baseUrl); // allow extension to inject their own metadata for (WMTSExtension extension : extensions) { List<WMTSExtension.OperationMetadata> operationsMetaData = extension.getExtraOperationsMetadata(); if (operationsMetaData != null) { for (WMTSExtension.OperationMetadata operationMetadata : operationsMetaData) { operation( xml, operationMetadata.getName(), operationMetadata.getBaseUrl() == null ? baseUrl : operationMetadata.getBaseUrl()); } } extension.encodedOperationsMetadata(xml); } xml.endElement("ows:OperationsMetadata"); }
private void layerFormats(XMLBuilder xml, TileLayer layer) throws IOException { List<String> mimeFormats = WMTSUtils.getLayerFormats(layer); for (String format : mimeFormats) { xml.simpleElement("Format", format, true); } }
if (extension.handleRequest(conv)) { if (tile.getHint().equals(GET_CAPABILITIES)) { WMTSGetCapabilities wmsGC = new WMTSGetCapabilities( tld, gsb, urlMangler, extensions); wmsGC.writeResponse(tile.servletResp, stats); getSecurityDispatcher().checkSecurity(tile); ConveyorTile convTile = (ConveyorTile) conv; WMTSGetFeatureInfo wmsGFI = new WMTSGetFeatureInfo(convTile); wmsGFI.writeResponse(stats);
@Before public void setupMockService() throws Exception { this.storageBroker = mock(StorageBroker.class); this.tileLayerDispatcher = tileLayerDispatcher(); this.runtimeStats = mock(RuntimeStats.class); this.wmtsService = new WMTSService(storageBroker, tileLayerDispatcher, broker, runtimeStats); this.securityDispatcher = securityDispatcher(); wmtsService.setSecurityDispatcher(securityDispatcher); }
public MockHttpServletResponse dispatch(MockHttpServletRequest req) throws Exception { MockHttpServletResponse resp = new MockHttpServletResponse(); try { final Conveyor conveyor = wmtsService.getConveyor(req, resp); if (conveyor.reqHandler == Conveyor.RequestHandler.SERVICE) { wmtsService.handleRequest(conveyor); } else { ResponseUtils.writeTile( securityDispatcher(), conveyor, conveyor.getLayerId(), tileLayerDispatcher(), null, runtimeStats); } } catch (OWSException e) { ResponseUtils.writeFixedResponse( resp, e.getResponseCode(), e.getContentType(), e.getResponse(), Conveyor.CacheResult.OTHER, runtimeStats); } return resp; }
@Test public void testGetInfoWithCiteValidation() throws Exception { testCiteValidationIsSuccessful( () -> { testGetInfoWithStyle(); testGetInfoWithoutStyle(); }); }
@Test public void testGetTileWithCiteValidation() throws Exception { testCiteValidationIsSuccessful( () -> { testGetTileWithStyle(); testGetTileWithoutStyle(); }); }
public Conveyor getRestConveyor(HttpServletRequest request, HttpServletResponse response) throws GeoWebCacheException, OWSException { final String path = request.getPathInfo(); // special simpler case for GetCapabilities if (path.endsWith("/service/wmts/rest/WMTSCapabilities.xml")) { ConveyorTile tile = new ConveyorTile(sb, null, request, response); tile.setHint(GET_CAPABILITIES); tile.setRequestHandler(ConveyorTile.RequestHandler.SERVICE); return tile; } // all other paths are handled via the RestRequest enumeration, matching patterns and // extracting variables for (RestRequest restRequest : RestRequest.values()) { Map<String, String> values = restRequest.toKVP(request); if (values != null) { return getKvpConveyor(request, response, values); } } // we implement all WMTS supported request, this means that the provided request name is // invalid throw new HttpErrorCodeException(404, "Unknown resource " + request.getPathInfo()); }
/** Helper method that just executes the provided test with CITE validation activated. */ private void testCiteValidationIsSuccessful(TestToExecute request) throws Exception { // mock server configuration to activate CITE compliance checks ServerConfiguration configuration = mock(ServerConfiguration.class); when(configuration.isWmtsCiteCompliant()).thenReturn(true); ServerConfiguration previousConfiguration = wmtsService.getMainConfiguration(); wmtsService.setMainConfiguration(configuration); try { // the following test should be successful request.execute(); } finally { // set whatever was the previous server configuration used by WMTS service wmtsService.setMainConfiguration(previousConfiguration); } }
/** Composes service information using information provided by extensions. */ private ServiceInformation getServiceInformation() { ServiceInformation servInfo = tld.getServiceInformation(); for (WMTSExtension extension : extensions) { ServiceInformation serviceInformation = extension.getServiceInformation(); if (serviceInformation != null) { if (servInfo == null) { servInfo = new ServiceInformation(); } mergeServiceInformation(servInfo, serviceInformation); } } return servInfo; }
@Test public void testGetTileWithoutStyle() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setPathInfo("geowebcache/service/wmts/rest/mockLayer/EPSG:4326/EPSG:4326:0/0/0"); req.addParameter("format", "image/png"); final MockHttpServletResponse resp = dispatch(req); assertEquals(200, resp.getStatus()); }
@Override public List<OperationMetadata> getExtraOperationsMetadata() throws IOException { return Arrays.asList( new OperationMetadata("ExtraOperation1"), new OperationMetadata("ExtraOperation2", "custom-url")); }
/** * Helper method that checks if WMTS implementation should be CITE strictly compliant. * * @return TRUE if GWC main configuration or at least one of the WMTS extensions forces CITE * compliance */ private boolean isCiteCompliant() { // let's see if main GWC configuration forces WMTS implementation to be CITE compliant if (mainConfiguration != null && mainConfiguration.isWmtsCiteCompliant()) { return true; } // let's see if at least one of the extensions forces CITE compliant mode for (WMTSExtension extension : extensions) { if (extension.getServiceInformation() != null && extension.getServiceInformation().isCiteCompliant()) { return true; } } // we are not in CITE compliant mode return false; }
private void layerInfoFormats(XMLBuilder xml, TileLayer layer) throws IOException { if (layer.isQueryable()) { List<String> infoFormats = WMTSUtils.getInfoFormats(layer); for (String format : infoFormats) { xml.simpleElement("InfoFormat", format, true); } } }
@Test public void testGetCapabilitiesWithCiteValidation() throws Exception { testCiteValidationIsSuccessful(this::testGetCap); }
@Override public ConveyorTile answer(InvocationOnMock invocation) throws Throwable { ConveyorTile sourceTile = (ConveyorTile) invocation.getArguments()[0]; sourceTile.setBlob(getSampleTileContent()); return sourceTile; } });
/** Substitute providerA information with no NULL information from providerB. */ private void mergeProviderInformation(ServiceProvider providerA, ServiceProvider providerB) { if (providerB.getProviderName() != null) { providerA.setProviderName(providerB.getProviderName()); } if (providerB.getProviderSite() != null) { providerA.setProviderSite(providerB.getProviderSite()); } if (providerB.getServiceContact() != null) { if (providerA.getServiceContact() != null) { mergeContactInformation( providerA.getServiceContact(), providerB.getServiceContact()); } else { providerA.setServiceContact(providerB.getServiceContact()); } } }
@Test public void testGetInfoWithoutStyle() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setPathInfo("geowebcache/service/wmts/rest/mockLayer/EPSG:4326/EPSG:4326:0/0/0/0/0"); req.addParameter("format", "text/plain"); final MockHttpServletResponse resp = dispatch(req); assertEquals(200, resp.getStatus()); assertEquals("text/plain", resp.getContentType()); }
@Test public void testGetInfoWithStyle() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setPathInfo( "geowebcache/service/wmts/rest/mockLayer/style-a/EPSG:4326/EPSG:4326:0/0/0/0/0"); req.addParameter("format", "text/plain"); final MockHttpServletResponse resp = dispatch(req); assertEquals(200, resp.getStatus()); assertEquals("text/plain", resp.getContentType()); }