List of usage examples for org.springframework.core.env Environment getProperty
@Nullable String getProperty(String key);
From source file:de.hska.ld.core.controller.InfoController.java
@Autowired public void init(Environment env) { try {//w w w .jav a 2 s . c o m Properties infoProp = PropertiesLoaderUtils.loadAllProperties("info.properties"); String sandbox = Boolean.parseBoolean(env.getProperty("module.sandbox.enabled")) ? " Sandbox" : ""; info = new Info(infoProp.getProperty("info.title") + sandbox, infoProp.getProperty("info.version"), infoProp.getProperty("info.organization")); } catch (IOException exception) { // } }
From source file:com.nkapps.billing.webservices.AccountWebService.java
private GenericResult initResult(GenericArgument argument, GenericResult result) { try {//from w w w.ja v a2 s.c o m String username = argument.getUsername(); String password = md5Encrypt(argument.getPassword()); WSDao wsDao = (WSDao) getBean("wsDao"); WsUser user = wsDao.findByUsernameAndPassword(username, password); if (user == null) { MessageSource messageSource = (MessageSource) getBean("messageSource"); // throw new Exception(messageSource.getMessage("auth.login_or_password_not_correct",null,new Locale("ru"))); Environment environment = (Environment) getBean("environment"); String a = environment.getProperty("ws.allow_user_add"); if ("true".equals(a)) { if (wsDao.createWsUser(username, password) == null) { throw new Exception(messageSource.getMessage("auth.login_or_password_not_correct", null, new Locale("ru"))); } } else { throw new Exception( messageSource.getMessage("auth.login_or_password_not_correct", null, new Locale("ru"))); } } result.setStatus(GenericResult.STATUS_INIT); } catch (Exception e) { logger.error(e.getMessage()); result.setStatus(GenericResult.STATUS_ERROR_AUTH); result.setReason(e.getMessage()); } return result; }
From source file:ch.sdi.plugins.oxwall.converter.OxConverterGender.java
/** * @see ch.sdi.core.intf.FieldConverter#init(org.springframework.core.env.Environment, java.lang.String) *///from w w w . ja va 2 s . c om @Override public FieldConverter<OxGender> init(Environment aEnv, String aFieldname) throws SdiException { myGenderMapping = new HashMap<String, OxGender>(); for (OxGender gender : OxGender.values()) { String pattern = aEnv .getProperty(SdiMainProperties.KEY_PREFIX_CONVERTER + CONVERTER_NAME + "." + gender); if (StringUtils.hasText(pattern)) { pattern = pattern.trim(); myLog.trace("Gender mapping found for " + gender + ": " + pattern); myGenderMapping.put(pattern, gender); } // if StringUtils.hasText( pattern ) } return this; }
From source file:com.otz.transport.config.EmailPluginConfiguration.java
@Bean public EmailConfigParameters emailConfigParameters(Environment environment) { EmailConfigParameters emailConfigParameters = new EmailConfigParameters(); String selectedEnvironment = environment.getActiveProfiles()[0]; emailConfigParameters.setProtocol(/*from w ww . j av a 2 s .c o m*/ environment.getProperty(selectedEnvironment + ".services.email.mail.transport.protocol")); emailConfigParameters .setAccessKey(environment.getProperty(selectedEnvironment + ".services.email.access.key")); emailConfigParameters .setSecretKey(environment.getProperty(selectedEnvironment + ".services.email.secret.key")); emailConfigParameters.setHost(environment.getProperty(selectedEnvironment + ".services.email.host")); emailConfigParameters.setPort( Integer.parseInt(environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.port"))); emailConfigParameters.setSmtpAuth(Boolean .parseBoolean(environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.auth"))); emailConfigParameters.setSmtpSslEnable(Boolean.parseBoolean( environment.getProperty(selectedEnvironment + ".services.email.mail.smtp.ssl.enable"))); return emailConfigParameters; }
From source file:org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClient.java
public CloudFoundryDiscoveryClient(CloudFoundryClient cloudFoundryClient, Environment environment) { this.cloudFoundryClient = cloudFoundryClient; String vcapApplication = environment.getProperty("VCAP_APPLICATION"); try {//from w w w . j a v a 2 s. co m JsonNode jsonNode = objectMapper.readTree(vcapApplication); JsonNode appNameNode = jsonNode.get("application_name"); this.vcapApplicationName = appNameNode.toString().replaceAll("\"", ""); log.debug("Current ServiceInstance information..."); log.debug("\tvcapApplicationName: " + this.vcapApplicationName); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:io.lavagna.config.PersistenceAndServiceConfig.java
@Bean public NamedParameterJdbcTemplate simpleJdbcTemplate(Environment env, DataSource dataSource) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // mysql does not support check constraints if ("MYSQL".equals(env.getProperty("datasource.dialect"))) { CustomSQLErrorCodesTranslator tr = new CustomSQLErrorCodesTranslator(); tr.setDataSource(dataSource);//from ww w .j a v a2s . c om jdbcTemplate.setExceptionTranslator(tr); } return new NamedParameterJdbcTemplate(jdbcTemplate); }
From source file:de.hska.ld.sandbox.DataGenerator.java
@Autowired @Transactional//from w w w .ja va2s . c o m public void init(DocumentService documentService, UserService userService, RoleService roleService, Environment env) { if (false) { String sandboxUsersConcatString = null; try { sandboxUsersConcatString = env.getProperty("module.sandbox.users"); createSandboxUsers(userService, roleService, sandboxUsersConcatString); } catch (Exception e) { e.printStackTrace(); } // TODO Martin String ddl = env.getProperty("module.core.db.ddl"); if ("create".equals(ddl) || "create-drop".equals(ddl)) { User user = userService.findByUsername(Core.BOOTSTRAP_USER); createSandboxDocument(documentService, userService, user); } } }
From source file:shiver.me.timbers.waiting.SpringPropertyGetterTest.java
@Test public void Can_get_a_spring_property() { final String key = someString(); final Environment environment = mock(Environment.class); final String expected = someString(); // Given//from w w w .j av a 2 s . c o m given(context.getEnvironment()).willReturn(environment); given(environment.getProperty(key)).willReturn(expected); // When final String actual = getter.get(key); // Then assertThat(actual, equalTo(expected)); }
From source file:ch.sdi.core.impl.data.converter.ConverterBoolean.java
/** * Clears the given list and fills it with found configured values according the given key * <p>//from w ww . j a v a2 s .c o m * @param aEnv * @param aValuesToFill * @param aKey * either "trueValues" or "falseValues" */ private void resolveConfiguredValues(Environment aEnv, Set<String> aValuesToFill, String aKey) { aValuesToFill.clear(); String key = SdiMainProperties.KEY_PREFIX_CONVERTER + CONVERTER_NAME + "." + aKey; String values = aEnv.getProperty(key); if (!StringUtils.hasText(values)) { myLog.debug("No configured values found for key " + key); return; } // if !StringUtils.hasText( values ) String[] split = values.split(","); for (String value : split) { if (!StringUtils.hasText(value)) { continue; } // if !StringUtils.hasText( value ) value = value.trim().toLowerCase(); myLog.debug("Found configured value (aKey): " + value); aValuesToFill.add(value); } }
From source file:ch.sdi.plugins.oxwall.profile.OxProfileQuestionGender.java
/** * @see ch.sdi.plugins.oxwall.profile.OxProfileQuestion#init(org.springframework.core.env.Environment) *///ww w. j ava2 s . c o m @Override public void init(Environment aEnvironment) throws SdiException { myGenderMap = new HashMap<OxGender, Number>(); for (OxGender gender : OxGender.values()) { String key = KEY_PREFIX_GENDER + gender; String configured = aEnvironment.getProperty(key); Long value; if (!StringUtils.hasText(configured)) { myLog.warn("Gender mapping not configured: " + key + "; using default value"); value = Long.valueOf(gender.getDefaultValue()); } else { try { value = Long.parseLong(configured); } catch (NumberFormatException t) { throw new SdiException("Gender mapping " + configured + " cannot be converted to number", t, SdiException.EXIT_CODE_CONFIG_ERROR); } } myGenderMap.put(gender, value); } }