private synchronized void loadConfig() throws IOException { File configFile = findConfigFile(); checkNotNull(configFile, "gwc config file does not exist: ", GWC_CONFIG_FILE); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); try { InputStream in = new FileInputStream(configFile); try { this.config = xmlPersister.load(in, GWCConfig.class); } finally { in.close(); } LOGGER.fine("GWC GeoServer specific configuration loaded from " + GWC_CONFIG_FILE); } catch (Exception e) { LOGGER.log( Level.WARNING, "Error loading GWC GeoServer specific " + "configuration from " + configFile.getAbsolutePath() + ". Applying defaults.", e); this.config = new GWCConfig(); } }
private synchronized void loadConfig() throws IOException { Resource configFile = findConfigFile(); checkNotNull(configFile, "gwc config file does not exist: ", GWC_CONFIG_FILE); XStreamPersister xmlPersister = this.persisterFactory.createXMLPersister(); configureXstream(xmlPersister.getXStream()); try { try (InputStream in = configFile.in()) { this.config = xmlPersister.load(in, GWCConfig.class); } LOGGER.fine("GWC GeoServer specific configuration loaded from " + GWC_CONFIG_FILE); } catch (Exception e) { LOGGER.log( Level.WARNING, "Error loading GWC GeoServer specific " + "configuration from " + configFile.path() + ". Applying defaults.", e); this.config = new GWCConfig(); } }
public void testInitializeLayersToOldDefaults() throws Exception { // no gwc-gs.xml exists when(configPersister.findConfigFile()).thenReturn(null); // ignore the upgrade of the direct wms integration flag on this test when(geoServer.getService(eq(WMSInfo.class))).thenReturn(null); // let the catalog have something to initialize LayerInfo layer = mockLayer("testLayer", new String[]{}, LayerInfo.Type.RASTER); LayerGroupInfo group = mockGroup("testGroup", layer); when(rawCatalog.getLayers()).thenReturn(Lists.newArrayList(layer)); when(rawCatalog.getLayerGroups()).thenReturn(Lists.newArrayList(group)); // run layer initialization initializer.initialize(geoServer); // make sure default tile layers were created GWCConfig oldDefaults = GWCConfig.getOldDefaults(); GeoServerTileLayerInfo tileLayer = TileLayerInfoUtil.loadOrCreate(layer, oldDefaults); GeoServerTileLayerInfo tileLayerGroup = TileLayerInfoUtil.loadOrCreate(group, oldDefaults); verify(tileLayerCatalog, times(1)).save(eq(tileLayer)); verify(tileLayerCatalog, times(1)).save(eq(tileLayerGroup)); }
public void testUpgradeDirectWMSIntegrationFlag() throws Exception { // no gwc-gs.xml exists, so that initialization runs when(configPersister.findConfigFile()).thenReturn(null); // no catalog layers for this test List<LayerInfo> layers = ImmutableList.of(); List<LayerGroupInfo> groups = ImmutableList.of(); when(rawCatalog.getLayers()).thenReturn(layers); when(rawCatalog.getLayerGroups()).thenReturn(groups); WMSInfoImpl wmsInfo = new WMSInfoImpl(); // initialize wmsInfo with a value for the old direct wms integration flag wmsInfo.getMetadata().put(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY, Boolean.TRUE); // make sure WMSInfo exists when(geoServer.getService(eq(WMSInfo.class))).thenReturn(wmsInfo); ArgumentCaptor<GWCConfig> captor = ArgumentCaptor.forClass(GWCConfig.class); // run layer initialization initializer.initialize(geoServer); verify(configPersister, times(2)).save(captor.capture()); assertTrue(captor.getAllValues().get(0).isDirectWMSIntegrationEnabled()); assertFalse(wmsInfo.getMetadata().containsKey(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY)); verify(geoServer).save(same(wmsInfo)); }
public void testUpgradeFromTileLayerInfosToTileLayerCatalog() throws Exception { when(configPersister.findConfigFile()).thenReturn(fakeConfig);
/** * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer) */ public void initialize(final GeoServer geoServer) throws Exception { LOGGER.info("Initializing GeoServer specific GWC configuration from " + GWCConfigPersister.GWC_CONFIG_FILE); final Version currentVersion = new Version("1.0.0"); final File configFile = configPersister.findConfigFile(); if (configFile == null) { LOGGER.fine("GWC's GeoServer specific configuration not found, creating with old defaults"); GWCConfig oldDefaults = GWCConfig.getOldDefaults(); oldDefaults.setVersion(currentVersion.toString()); upgradeWMSIntegrationConfig(geoServer, oldDefaults); createDefaultTileLayerInfos(oldDefaults); configPersister.save(oldDefaults); } final GWCConfig config = configPersister.getConfig(); final Version version = new Version(config.getVersion()); if (currentVersion.compareTo(version) > 0) { // got the global config file, so old defaults are already in place if need be. Now // check whether we need to migrate the configuration from the Layer/GroupInfo metadata // maps to the tile layer catalog store moveTileLayerInfosToTileLayerCatalog(); config.setVersion(currentVersion.toString()); configPersister.save(config); } final GWCConfig gwcConfig = configPersister.getConfig(); checkNotNull(gwcConfig); }
final Resource configFile = configPersister.findConfigFile(); if (configFile == null || configFile.getType() != Type.RESOURCE) { LOGGER.fine(