@Override public String getLocation() { try { return this.resourceProvider.getLocation(); } catch (IOException e) { log.error("Could not get config location", e); return "Error, see log for details"; } }
/** * Path to template to use when there is no config file. * * @param template */ public void setTemplate(String template) { resourceProvider.setTemplate(template); }
private QuotaStore getJDBCStore( DefaultStorageFinder cacheDirFinder, TilePageCalculator tilePageCalculator) throws ConfigurationException { JDBCConfiguration config = null; ConfigurationResourceProvider resourceProvider = defaultResourceProvider == null ? createResourceProvider(cacheDirFinder) : defaultResourceProvider; try { if (!resourceProvider.hasInput()) { throw new IllegalArgumentException( "Unable to read JDBC configuration file: " + resourceProvider.getLocation()); } config = JDBCConfiguration.load(resourceProvider.in()); } catch (IOException e) { throw new IllegalArgumentException( "Failed to read JDBC configuration file at " + resourceProvider.getId()); } return getJDBCStore(cacheDirFinder, tilePageCalculator, config); }
public DiskQuotaConfig loadConfig() throws IOException, ConfigurationException { DiskQuotaConfig quotaConfig = null; if (resourceProvider.hasInput()) { log.info("Quota config is: " + resourceProvider.getLocation()); try (InputStream configIn = resourceProvider.in()) { quotaConfig = loadConfiguration(configIn); if (null == quotaConfig) { throw new ConfigurationException( "Couldn't parse configuration file " + resourceProvider.getLocation()); } } catch (IOException | RuntimeException e) { log.error( "Error loading DiskQuota configuration from " + resourceProvider.getLocation() + ": " + e.getMessage() + ". Deferring to a default (disabled) configuration", e); } } else { log.info("DiskQuota configuration is not readable: " + resourceProvider.getLocation()); } if (quotaConfig == null) { quotaConfig = new DiskQuotaConfig(); } // set default values quotaConfig.setDefaults(); validateConfig(quotaConfig); return quotaConfig; }
private GeoWebCacheConfiguration loadConfiguration() throws ConfigurationException { Assert.isTrue(resourceProvider.hasInput()); InputStream in; try { in = resourceProvider.in(); try { return loadConfiguration(in); } finally { in.close(); } } catch (IOException e) { throw new ConfigurationException( "Error parsing config file " + resourceProvider.getId(), e); } }
/** * Saves the configuration to the root cache directory * * @param config * @throws IOException * @throws ConfigurationException */ public void saveConfig(DiskQuotaConfig config) throws IOException, ConfigurationException { if (!resourceProvider.hasOutput()) { log.error("Unable to save DiskQuota to resource :" + resourceProvider.getLocation()); return; } XStream xStream = getConfiguredXStream(new GeoWebCacheXStream()); log.debug("Saving disk quota config to " + resourceProvider.getLocation()); try (OutputStream configOut = resourceProvider.out()) { xStream.toXML(config, new OutputStreamWriter(configOut, "UTF-8")); } catch (RuntimeException e) { log.error("Error saving DiskQuota config to file :" + resourceProvider.getLocation()); } }
/** * Method responsible for writing out the entire GeoWebCacheConfiguration object * * <p>throws an exception if it does not succeed */ private void persistToFile() throws IOException { Assert.isTrue(resourceProvider.hasOutput()); // create the XStream for serializing the configuration XStream xs = getConfiguredXStreamWithContext(new GeoWebCacheXStream(), Context.PERSIST); try (OutputStreamWriter writer = new OutputStreamWriter(resourceProvider.out(), "UTF-8")) { // set version to latest String currentSchemaVersion = getCurrentSchemaVersion(); getGwcConfig().setVersion(currentSchemaVersion); writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xs.toXML(getGwcConfig(), writer); } catch (UnsupportedEncodingException uee) { throw new IOException(uee.getMessage(), uee); } catch (FileNotFoundException fnfe) { throw fnfe; } catch (IOException e) { throw (IOException) new IOException( "Error writing to " + resourceProvider.getId() + ": " + e.getMessage()) .initCause(e); } log.info("Wrote configuration to " + resourceProvider.getId()); }
public void afterPropertiesSet() throws GeoWebCacheException { if (gridSetBroker == null) { throw new IllegalStateException("GridSetBroker has not been set"); } if (resourceProvider.hasInput()) { this.setGwcConfig(loadConfiguration()); } log.info("Initializing GridSets from " + getIdentifier()); getGridSetsInternal(); log.info("Initializing layers from " + getIdentifier()); // Loop over the layers and set appropriate values for (TileLayer layer : getGwcConfig().getLayers()) { if (layer == null) { throw new IllegalStateException(getIdentifier() + " contains a null layer"); } initialize(layer); } updateLayers(); }
/** @see BlobStoreConfiguration#canSave(org.geowebcache.config.BlobStoreInfo) */ @Override public boolean canSave(BlobStoreInfo info) { // if the resourceProvider has output, then it should be saveable. NOTE, this does not // guarantee that there are // sufficient write permissions to the underlying resource. return resourceProvider.hasOutput(); }
/** @see TileLayerConfiguration#getIdentifier() */ public String getIdentifier() { return resourceProvider.getId(); }
/** * @return The root path where configuration is stored * @throws ConfigurationException */ public String getConfigLocation() throws ConfigurationException { try { return resourceProvider.getLocation(); } catch (IOException e) { throw new ConfigurationException(e.getMessage(), e); } }
/** * Constructor that will look for {@code geowebcache.xml} at the directory defined by {@code * storageDirFinder} * * @param appCtx use to lookup {@link XMLConfigurationProvider} extenions, may be {@code null} * @param storageDirFinder * @throws ConfigurationException */ public XMLConfiguration( final ApplicationContextProvider appCtx, final DefaultStorageFinder storageDirFinder) throws ConfigurationException { this( appCtx, new XMLFileResourceProvider( DEFAULT_CONFIGURATION_FILE_NAME, appCtx, storageDirFinder)); resourceProvider.setTemplate("/" + DEFAULT_CONFIGURATION_FILE_NAME); }
/** * File System based Constructor * * @param appCtx use to lookup {@link XMLConfigurationProvider} extensions, may be {@code null} * @param configFileDirectory * @param storageDirFinder * @throws ConfigurationException */ public XMLConfiguration( final ApplicationContextProvider appCtx, final String configFileDirectory, final DefaultStorageFinder storageDirFinder) throws ConfigurationException { this( appCtx, new XMLFileResourceProvider( DEFAULT_CONFIGURATION_FILE_NAME, appCtx, configFileDirectory, storageDirFinder)); resourceProvider.setTemplate("/" + DEFAULT_CONFIGURATION_FILE_NAME); }