/** * Constructs a new POJO based on the provided {@link ServerConfiguration} * * @param template Template used to initialize properties */ public ServerConfigurationPOJO(ServerConfiguration template) throws IOException { this.serviceInformation = template.getServiceInformation(); this.runtimeStatsEnabled = template.isRuntimeStatsEnabled(); setLockProvider(template.getLockProvider()); this.fullWMS = template.isFullWMS(); this.wmtsCiteCompliant = template.isWmtsCiteCompliant(); this.backendTimeout = template.getBackendTimeout(); this.cacheBypassAllowed = template.isCacheBypassAllowed(); this.version = template.getVersion(); this.identifier = template.getIdentifier(); this.location = template.getLocation(); }
/** * Applies the values of this POJO to the provided ServerConfiguration Note: Does not set * version, identifier, or location, as those are read-only. * * @param config The configuration to set the values on. */ public void apply(ServerConfiguration config) throws IOException { if (getServiceInformation() != null) { config.setServiceInformation(getServiceInformation()); } if (isRuntimeStatsEnabled() != null) { config.setRuntimeStatsEnabled(isRuntimeStatsEnabled()); } if (getLockProvider() != null) { config.setLockProvider(getLockProvider()); } if (isFullWMS() != null) { config.setFullWMS(isFullWMS()); } if (isWmtsCiteCompliant() != null) { config.setWmtsCiteCompliant(isWmtsCiteCompliant()); } if (getBackendTimeout() != null) { config.setBackendTimeout(getBackendTimeout()); } if (isCacheBypassAllowed() != null) { config.setCacheBypassAllowed(isCacheBypassAllowed()); } }
@RequestMapping(method = RequestMethod.PUT) public void serverPut(@RequestBody ServerConfigurationPOJO serverConfiguration) throws IOException { // Throw an exception if a read-only value is modified if (serverConfiguration.getIdentifier() != null && !this.serverConfiguration .getIdentifier() .equals(serverConfiguration.getIdentifier())) { throw new RestException( "Cannot modify read-only property \"identifier\"", HttpStatus.BAD_REQUEST); } if (serverConfiguration.getLocation() != null && !this.serverConfiguration .getLocation() .equals(serverConfiguration.getLocation())) { throw new RestException( "Cannot modify read-only property \"location\"", HttpStatus.BAD_REQUEST); } if (serverConfiguration.getVersion() != null && !this.serverConfiguration .getVersion() .equals(serverConfiguration.getVersion())) { throw new RestException( "Cannot modify read-only property \"version\"", HttpStatus.BAD_REQUEST); } serverConfiguration.apply(this.serverConfiguration); } }
ServiceInformation serviceInfo = config.getServiceInformation(); assertEquals("GeoWebCache", serviceInfo.getTitle()); assertEquals("John Smith inc.", serviceInfo.getServiceProvider().getProviderName()); ServiceInformation newinfo = new ServiceInformation(); newinfo.setProviderName("John Adams inc."); config.setServiceInformation(newinfo); assertEquals("John Adams inc.", config.getServiceInformation().getProviderName()); Boolean runtimeStats = config.isRuntimeStatsEnabled(); assertTrue(runtimeStats); config.setRuntimeStatsEnabled(false); runtimeStats = config.isRuntimeStatsEnabled(); assertFalse(runtimeStats); LockProvider lockProvider = config.getLockProvider(); assertNotNull(lockProvider); Boolean fullWMS = config.isFullWMS(); assertNull(fullWMS); config.setFullWMS(true); fullWMS = config.isFullWMS(); assertTrue(fullWMS); Boolean wmtsCiteCompliant = config.isWmtsCiteCompliant(); assertFalse(wmtsCiteCompliant); config.setWmtsCiteCompliant(true); wmtsCiteCompliant = config.isWmtsCiteCompliant(); assertTrue(wmtsCiteCompliant);
this.lockProvider = serverConfiguration.getLockProvider(); this.blobStoreConfigs = blobStoreAggregator; StoreSuitabilityCheck oldCheck = storeSuitability.get();
/** * Should be invoked through Spring * * @param tileLayerDispatcher * @param gridSetBroker */ public GeoWebCacheDispatcher( TileLayerDispatcher tileLayerDispatcher, GridSetBroker gridSetBroker, StorageBroker storageBroker, BlobStoreAggregator blobStoreAggregator, ServerConfiguration mainConfiguration, RuntimeStats runtimeStats) { super(); this.tileLayerDispatcher = tileLayerDispatcher; this.gridSetBroker = gridSetBroker; this.runtimeStats = runtimeStats; this.storageBroker = storageBroker; this.blobStoreAggregator = blobStoreAggregator; this.mainConfiguration = mainConfiguration; if (mainConfiguration.isRuntimeStatsEnabled()) { this.runtimeStats.start(); } else { runtimeStats = null; } }
/** * 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 int initialize(BlobStoreConfiguration config) { if (config == null) { throw new IllegalStateException( "BlobStoreConfiguration got a null GWC configuration object"); } String configIdent; try { configIdent = config.getIdentifier(); } catch (Exception gwce) { log.error("Error obtaining identify from BlobStoreConfiguration " + config, gwce); return 0; } if (configIdent == null) { log.warn("Got a GWC configuration with no identity, ignoring it:" + config); return 0; } int blobStoreCount = config.getBlobStoreCount(); if (blobStoreCount <= 0) { log.info( "BlobStoreConfiguration " + config.getIdentifier() + " contained no blob store infos."); } // Check whether there is any general service information if (this.serviceInformation == null && config instanceof ServerConfiguration) { log.debug("Reading service information."); this.serviceInformation = ((ServerConfiguration) config).getServiceInformation(); } return blobStoreCount; }
public void setFullWMS(String trueFalse) { // Selection of the configurations List<TileLayerConfiguration> configs = new ArrayList<TileLayerConfiguration>( GeoWebCacheExtensions.extensions(TileLayerConfiguration.class)); // Selection of the TileLayerConfiguration file associated to geowebcache.xml ServerConfiguration gwcXMLconfig = null; for (BaseConfiguration config : configs) { if (config instanceof XMLConfiguration) { gwcXMLconfig = (ServerConfiguration) config; break; } } // From the configuration file the "fullWMS" parameter is searched Boolean wmsFull = null; if (gwcXMLconfig != null) { wmsFull = gwcXMLconfig.isFullWMS(); } if (wmsFull != null) { this.fullWMS = wmsFull; } else { this.fullWMS = Boolean.parseBoolean(trueFalse); } // Log if fullWMS is enabled if (this.fullWMS) { log.info("Will recombine tiles for non-tiling clients."); } else { log.info("Will NOT recombine tiles for non-tiling clients."); } }
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
SRS srs = SRS.getEPSG3857(); EasyMock.expect(config.isRuntimeStatsEnabled()).andStubReturn(false);
/** 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); } }
public static void setUpTestData(GWCConfigIntegrationTestSupport testSupport) throws Exception { serverConfiguration.getServiceInformation().setTitle("GeoWebCache");
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
SRS srs = SRS.getEPSG3857(); EasyMock.expect(config.isRuntimeStatsEnabled()).andStubReturn(false);
@Test public void testHomePage() throws Exception { IMocksControl stubs = EasyMock.createControl(MockType.NICE); TileLayerDispatcher tld = stubs.createMock("tld", TileLayerDispatcher.class); GridSetBroker gsb = stubs.createMock("gsb", GridSetBroker.class); StorageBroker sb = stubs.createMock("sb", StorageBroker.class); BlobStoreAggregator bsa = stubs.createMock("bsa", BlobStoreAggregator.class); ServerConfiguration config = stubs.createMock("config", ServerConfiguration.class); RuntimeStats rts = stubs.createMock("rts", RuntimeStats.class); DefaultStorageFinder dfs = stubs.createMock("dfs", DefaultStorageFinder.class); SecurityDispatcher secDisp = stubs.createMock("secDisp", SecurityDispatcher.class); EasyMock.expect(config.isRuntimeStatsEnabled()).andStubReturn(false); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/geowebcache/home"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setContextPath("/geowebcache"); stubs.replay(); // Bean init GeoWebCacheDispatcher dispatcher = new GeoWebCacheDispatcher(tld, gsb, sb, bsa, config, rts); dispatcher.setApplicationContext(extensions.getMockContext()); dispatcher.setDefaultStorageFinder(dfs); dispatcher.setSecurityDispatcher(secDisp); // The test dispatcher.handleRequest(request, response); assertThat(response, hasStatus(HttpStatus.OK)); stubs.verify(); }