List of usage examples for org.springframework.core.env Environment getProperty
@Nullable String getProperty(String key);
From source file:org.egov.services.zuulproxy.filter.ZuulProxyFilter.java
private String getTanentId(final WebApplicationContext springContext) { final Environment environment = (Environment) springContext.getBean(ENVIRONMENT); final String clientId = environment.getProperty(CLIENT_ID); String tenantId = ApplicationThreadLocals.getTenantID(); if (StringUtils.isNotBlank(clientId)) { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(clientId).append('.').append(tenantId); tenantId = stringBuilder.toString(); }//from www. j av a2 s. co m return tenantId; }
From source file:org.flowable.app.conf.FlowableAppDatasourceUtil.java
public static DataSource createDataSource(Environment environment) { String dataSourceJndiName = environment.getProperty("datasource.jndi.name"); if (StringUtils.isNotEmpty(dataSourceJndiName)) { LOGGER.info("Using jndi datasource '{}'", dataSourceJndiName); JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); dsLookup.setResourceRef(//from w ww.j a v a2 s. c o m environment.getProperty("datasource.jndi.resourceRef", Boolean.class, Boolean.TRUE)); DataSource dataSource = dsLookup.getDataSource(dataSourceJndiName); return dataSource; } else { String url = environment.getProperty("datasource.url", "jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000"); String driver = environment.getProperty("datasource.driver", "org.h2.Driver"); String username = environment.getProperty("datasource.username", "sa"); String password = environment.getProperty("datasource.password", ""); HikariDataSource dataSource = new HikariDataSource(); dataSource.setJdbcUrl(url); dataSource.setDriverClassName(driver); dataSource.setUsername(username); dataSource.setPassword(password); /* * Connection pool settings (see https://github.com/brettwooldridge/HikariCP) */ // Timeout to wait for a connection of the pool Long connectionTimeout = environment.getProperty("datasource.connection-timeout", Long.class); if (connectionTimeout == null) { // Backwards compatible property name (pre 6.3.0) connectionTimeout = environment.getProperty("datasource.connection.timeout", Long.class); } if (connectionTimeout != null) { dataSource.setConnectionTimeout(connectionTimeout); } // Minimum amount of connections to keep idle in the pool Integer minIdle = environment.getProperty("datasource.min-pool-size", Integer.class); if (minIdle == null) { // Backwards compatible property name (pre 6.3.0) minIdle = environment.getProperty("datasource.connection.minidle", Integer.class); } if (minIdle != null) { dataSource.setMinimumIdle(minIdle); } // Maximum amount of connections in the pool Integer maxPoolSize = environment.getProperty("datasource.max-pool-size", Integer.class); if (maxPoolSize == null) { // Backwards compatible property name (pre 6.3.0) maxPoolSize = environment.getProperty("datasource.connection.maxpoolsize", Integer.class); } if (maxPoolSize != null) { dataSource.setMaximumPoolSize(maxPoolSize); } // Time in milliseconds to indicate when a connection will be removed from the pool. // Use 0 to never remove an idle connection from the pool Long idleTimeout = environment.getProperty("datasource.max-idle-time", Long.class); if (idleTimeout != null) { // Property has been historically expressed in seconds, but Hikari expects milliseconds idleTimeout = idleTimeout * 1000; } else if (idleTimeout == null) { // Backwards compatible property name (pre 6.3.0) idleTimeout = environment.getProperty("datasource.connection.idletimeout", Long.class); } if (idleTimeout != null) { dataSource.setIdleTimeout(idleTimeout); } // The maximum lifetime of a connection in the pool Long maxLifetime = environment.getProperty("datasource.connection.max-lifetime", Long.class); if (maxLifetime == null) { maxLifetime = environment.getProperty("datasource.connection.maxlifetime", Long.class); } if (maxLifetime != null) { dataSource.setMaxLifetime(maxLifetime); } // Test query String testQuery = environment.getProperty("datasource.test-query"); if (testQuery == null) { // Backwards compatible property name (pre 6.3.0) testQuery = environment.getProperty("datasource.preferred-test-query"); } if (testQuery != null) { dataSource.setConnectionTestQuery(testQuery); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Configuring datasource with following properties"); LOGGER.info("Datasource driver: {}", driver); LOGGER.info("Datasource url: {}", url); LOGGER.info("Datasource user name: {}", username); LOGGER.info("Min pool size | Max pool size | {} | {}", minIdle != null ? minIdle : "default", maxPoolSize != null ? maxPoolSize : "default"); } return dataSource; } }
From source file:org.flowable.app.conf.RestApiUtil.java
public static boolean isVerifyRestApiPrivilege(Environment env) { String authMode = env.getProperty("rest.authentication.mode"); if (StringUtils.isNotEmpty(authMode)) { return "verify-privilege".equals(authMode); }//from w ww.j av a 2 s .c o m return true; // checking privilege is the default }
From source file:org.springframework.boot.SpringApplicationBannerPrinter.java
private Banner getImageBanner(Environment environment) { String location = environment.getProperty(BANNER_IMAGE_LOCATION_PROPERTY); if (StringUtils.hasLength(location)) { Resource resource = this.resourceLoader.getResource(location); return (resource.exists() ? new ImageBanner(resource) : null); }//from w w w.ja va 2s . c om for (String ext : IMAGE_EXTENSION) { Resource resource = this.resourceLoader.getResource("banner." + ext); if (resource.exists()) { return new ImageBanner(resource); } } return null; }
From source file:org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClientTest.java
@Before public void setUp() { this.cloudFoundryClient = mock(CloudFoundryClient.class); Environment environment = mock(Environment.class); given(environment.getProperty("VCAP_APPLICATION")) .willReturn("{\"limits\":{\"mem\":1024,\"disk\":1024,\"fds\":16384},\"application_version\":" + "\"36eff082-96d6-498f-8214-508fda72ba65\",\"application_name\":\"" + hiServiceServiceId + "\",\"application_uris\"" + ":[\"" + hiServiceServiceId + ".cfapps.io\"],\"version\":\"36eff082-96d6-498f-8214-508fda72ba65\",\"name\":" + "\"hi-service\",\"space_name\":\"joshlong\",\"space_id\":\"e0cd969c-3461-41ae-abde-4e11bb5acbd1\"," + "\"uris\":[\"hi-service.cfapps.io\"],\"users\":null,\"application_id\":\"af350f7c-88c4-4e35-a04e-698a1dbc7354\"," + "\"instance_id\":\"e4843ca23bd947b28e6d4cb3f9b92cbb\",\"instance_index\":0,\"host\":\"0.0.0.0\",\"port\":61590," + "\"started_at\":\"2015-05-07 20:00:10 +0000\",\"started_at_timestamp\":1431028810,\"start\":\"2015-05-07 20:00:10 +0000\"," + "\"state_timestamp\":1431028810}"); List<CloudApplication> cloudApplications = new ArrayList<>(); cloudApplications.add(/*from w ww . j a v a 2 s .co m*/ fakeCloudApplication(this.hiServiceServiceId, "hi-service.cfapps.io", "hi-service-1.cfapps.io")); cloudApplications .add(fakeCloudApplication("config-service", "conf-service.cfapps.io", "conf-service-1.cfapps.io")); given(this.cloudFoundryClient.getApplications()).willReturn(cloudApplications); cloudApplication = cloudApplications.get(0); given(this.cloudFoundryClient.getApplication(this.hiServiceServiceId)).willReturn(cloudApplication); given(this.cloudFoundryClient.getApplication(this.hiServiceServiceId)).willReturn(this.cloudApplication); InstanceInfo instanceInfo = mock(InstanceInfo.class); InstancesInfo instancesInfo = mock(InstancesInfo.class); given(instancesInfo.getInstances()).willReturn(Collections.singletonList(instanceInfo)); given(instanceInfo.getState()).willReturn(InstanceState.RUNNING); given(this.cloudFoundryClient.getApplicationInstances(this.cloudApplication)).willReturn(instancesInfo); this.cloudFoundryDiscoveryClient = new CloudFoundryDiscoveryClient(cloudFoundryClient, environment); }
From source file:org.springframework.xd.dirt.launcher.AbstractContainerLauncher.java
private String logXDEnvironment(XDContainer container) { Environment environment = container.getApplicationContext().getEnvironment(); String[] keys = new String[] { XDPropertyKeys.XD_HOME, XDPropertyKeys.XD_TRANSPORT, XDPropertyKeys.XD_STORE, XDPropertyKeys.XD_ANALYTICS, XDPropertyKeys.XD_HADOOP_DISTRO }; StringBuilder sb = new StringBuilder("\nXD Configuration:\n"); for (String key : keys) { sb.append("\t" + key + "=" + environment.getProperty(key) + "\n"); }/*from w w w . j a v a2 s.c o m*/ return sb.toString(); }
From source file:org.unitedinternet.cosmo.dav.provider.CalendarCollectionProvider.java
/** * @param collectionItem//from w w w . j a v a 2s .c om * @return */ private Calendar getCalendarFromCollection(DavRequest req, CollectionItem collectionItem) { Calendar result = new Calendar(); if (productId == null) { synchronized (this) { if (productId == null) { Environment environment = WebApplicationContextUtils .findWebApplicationContext(req.getServletContext()).getEnvironment(); productId = environment.getProperty(PRODUCT_ID_KEY); } } } result.getProperties().add(new ProdId(productId)); result.getProperties().add(Version.VERSION_2_0); result.getProperties().add(CalScale.GREGORIAN); for (Item item : collectionItem.getChildren()) { if (!NoteItem.class.isInstance(item)) { continue; } for (Stamp s : item.getStamps()) { if (BaseEventStamp.class.isInstance(s)) { BaseEventStamp baseEventStamp = BaseEventStamp.class.cast(s); result.getComponents().add(baseEventStamp.getEvent()); } } } return result; }