private static String resolveFromEnv(String str) { if (gwcEnvironment == null) { gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); } if (gwcEnvironment != null && str != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { Object result = gwcEnvironment.resolveValue(str); if (result == null) { return null; } return result.toString(); } return str; }
@Override public String resolvePlaceholder(String placeholderName) { return GeoWebCacheEnvironment.this.resolvePlaceholder(placeholderName); } };
/** * Translates placeholders in the form of Spring Property placemark ${...} into their real * values. * * <p>The method first looks for System variables which take precedence on local ones, then into * internal props injected through the applicationContext. * * @param value * @return */ public Object resolveValue(Object value) { if (value != null) { if (value instanceof String) { return resolveStringValue((String) value); } } return value; } }
public void testSystemProperty() { // check for a property we did set up in the setUp GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment(); assertEquals("ABC", genv.resolveValue("${TEST_SYS_PROPERTY}")); Properties props = new Properties(); props.setProperty("TEST_SYS_PROPERTY", "DEF"); props.setProperty("TEST_PROPERTY", "WWW"); genv.setProps(props); assertEquals("ABC", genv.resolveValue("${TEST_SYS_PROPERTY}")); assertEquals("WWW", genv.resolveValue("${TEST_PROPERTY}")); } }
/** * Synchronizes environment properties between the {@link GeoServerEnvironment} and the {@link * GeoWebCacheEnvironment}. (GeoServer properties will override GeoWebCache properties) * * @throws IllegalArgumentException */ public void syncEnv() throws IllegalArgumentException { if (gsEnvironment != null && gsEnvironment.isStale() && gwcEnvironment != null) { if (GeoServerEnvironment.ALLOW_ENV_PARAMETRIZATION && gsEnvironment.getProps() != null) { Properties gwcProps = gwcEnvironment.getProps(); if (gwcProps == null) { gwcProps = new Properties(); } gwcProps.putAll(gsEnvironment.getProps()); gwcEnvironment.setProps(gwcProps); } } }
protected void setUp() throws Exception { super.setUp(); System.setProperty("TEST_JDBC_DRIVER", "org.postgresql.Driver"); System.setProperty("TEST_JDBC_URL", "jdbc:postgresql:gttest"); System.setProperty("TEST_JDBC_USER", "test"); System.setProperty("TEST_JDBC_PASSWORD", "toast"); System.setProperty("ALLOW_ENV_PARAMETRIZATION", "true"); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment(); gse.setApplicationContext(appContext); expect(appContext.getBeanNamesForType(GeoWebCacheEnvironment.class)) .andReturn(new String[] {"environment"}); expect(appContext.getBean("environment")).andReturn(genv); Map<String, GeoWebCacheEnvironment> genvMap = new HashMap<>(); genvMap.put("environment", genv); expect(appContext.getBeansOfType(GeoWebCacheEnvironment.class)) .andReturn(genvMap) .anyTimes(); expect(appContext.getBean("environment")).andReturn(genv).anyTimes(); replay(appContext); }
protected String resolvePlaceholder(String placeholder) { String propVal = null; propVal = resolveSystemProperty(placeholder); if (props != null && propVal == null) { propVal = props.getProperty(placeholder); } return propVal; }
public void testEnvironment() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoWebCacheEnvironment genv = new GeoWebCacheEnvironment(); assertEquals(0, GeoWebCacheExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(GeoWebCacheEnvironment.class)) .andReturn(new String[] {"geoWebCacheEnvironment"}); expect(appContext.getBean("geoWebCacheEnvironment")).andReturn(genv); Map<String, GeoWebCacheEnvironment> genvMap = new HashMap<>(); genvMap.put("geoWebCacheEnvironment", genv); expect(appContext.getBeansOfType(GeoWebCacheEnvironment.class)) .andReturn(genvMap) .anyTimes(); replay(appContext); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(appContext); List<GeoWebCacheEnvironment> extensions = GeoWebCacheExtensions.extensions(GeoWebCacheEnvironment.class); assertNotNull(extensions); assertEquals(1, extensions.size()); assertTrue(extensions.contains(genv)); assertTrue(GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION); }
private static String resolveFromEnv(String str) { if (gwcEnvironment == null) { gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); } if (gwcEnvironment != null && str != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { Object result = gwcEnvironment.resolveValue(str); if (result == null) { return null; } return result.toString(); } return str; }
public static DiskQuotaConfig loadConfiguration(final Reader reader, XStream xstream) { DiskQuotaConfig fromXML = (DiskQuotaConfig) xstream.fromXML(reader); final GeoWebCacheEnvironment gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); if (gwcEnvironment != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { fromXML.setQuotaStore((String) gwcEnvironment.resolveValue(fromXML.getQuotaStore())); } return fromXML; }
&& gwcEnvironment != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { conf.setDialect((String) gwcEnvironment.resolveValue(getDialect())); conf.setJNDISource((String) gwcEnvironment.resolveValue(getJNDISource())); ConnectionPoolConfiguration connectionPoolConfig = getConnectionPool(); if (connectionPoolConfig != null) { SerializationUtils.clone(connectionPoolConfig); expConnectionPoolConfig.setDriver( (String) gwcEnvironment.resolveValue(connectionPoolConfig.getDriver())); expConnectionPoolConfig.setUrl( (String) gwcEnvironment.resolveValue(connectionPoolConfig.getUrl())); expConnectionPoolConfig.setUsername( (String) gwcEnvironment.resolveValue(connectionPoolConfig.getUsername())); expConnectionPoolConfig.setPassword( (String) gwcEnvironment.resolveValue(connectionPoolConfig.getPassword())); expConnectionPoolConfig.setValidationQuery( (String) gwcEnvironment.resolveValue( connectionPoolConfig.getValidationQuery()));