List of usage examples for org.springframework.core.env Environment getProperty
String getProperty(String key, String defaultValue);
From source file:shiver.me.timbers.waiting.SpringPropertyGetterTest.java
@Test public void Can_get_a_spring_property_while_supplying_a_default_value() { final String key = someString(); final Environment environment = mock(Environment.class); final Object defaultValue = new Object(); final String expected = someString(); // Given/*w w w. ja v a 2s.co m*/ given(context.getEnvironment()).willReturn(environment); given(environment.getProperty(key, defaultValue.toString())).willReturn(expected); // When final String actual = getter.get(key, defaultValue); // Then assertThat(actual, equalTo(expected)); }
From source file:org.vaadin.spring.samples.mvp.security.config.HttpSecurityConfigurer.java
void configure(Environment env, ApplicationContext context, HttpSecurity http) throws Exception { // all requests are authenticated http.authorizeRequests().antMatchers("/VAADIN/**", "/PUSH/**", "/UIDL/**", "/login", "/login/**") .permitAll().antMatchers("/**").fullyAuthenticated().and() // Vaadin chokes if this filter is enabled, disable it! .csrf().disable();/* www . j ava2 s . c o m*/ // have UI peacefully coexist with Apache CXF web-services String id = env.getProperty("app.security.scheme", Scheme.BASIC.id()); Scheme scheme = Scheme.fromValue(id); switch (scheme) { case FORM: http.formLogin().failureUrl("/login?error").defaultSuccessUrl("/ui").permitAll().and().logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login") .permitAll(); break; case BASIC: http.httpBasic(); break; case DIGEST: // @see http://java.dzone.com/articles/basic-and-digest http.httpBasic(); http.addFilterAfter(context.getBean(DigestAuthenticationFilter.class), BasicAuthenticationFilter.class); break; } // TODO plumb custom HTTP 403 and 404 pages /* http.exceptionHandling().accessDeniedPage("/access?error"); */ }
From source file:it.scoppelletti.programmerpower.web.control.ActionBase.java
/** * Restituisce l’indirizzo della pagina HTML di guida. * //from w ww . j av a2 s . c om * <P>Questa implementazione del metodo {@code getHelpUrl} rileva il valore * della proprietà {@code path.help} tra le risorse * associate all’azione: se questa proprietà è * impostata, è considerata come un percorso relativo * all’indirizzo di base della guida di riferimento di Programmer * Power ({@code http://www.scoppelletti.it/programmerpower/reference}); * questo indirizzo di base può essere sovrascritto dal valore * impostato sulla proprietà di ambiente * {@code it.scoppelletti.programmerpower.web.help.url}.<BR> * Le classi derivate da terze parti dovrebbero implementare una versione * prevalente del metodo {@code getHelpUrl} per restituire l’URL * opportuno.</P> * * @return Valore. Se la guida non è prevista, restituisce * {@code null}. * @see <A HREF="{@docRoot}/../reference/setup/envprops.html" * TARGET="_top">Proprietà di ambiente</A> */ public String getHelpUrl() { String base, path; UriComponentsBuilder uriBuilder; Environment env; path = getText(ActionBase.PROP_HELPPATH); if (Strings.isNullOrEmpty(path) || ActionBase.PROP_HELPPATH.equals(path)) { return null; } if (myApplCtx == null) { base = ActionBase.DEF_HELPURL; } else { env = myApplCtx.getEnvironment(); base = env.getProperty(ActionBase.PROP_HELPURL, ActionBase.DEF_HELPURL); } if (!base.endsWith("/") && !path.startsWith("/")) { base = base.concat("/"); } uriBuilder = UriComponentsBuilder.fromUriString(base); uriBuilder.path(path); return uriBuilder.build().toUriString(); }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
@Override public void setEnvironment(Environment environment) { String property = environment.getProperty(RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY, String.class); if (property != null) { this.emptyStringArguments.addAll(StringUtils.commaDelimitedListToSet(property)); }/*from ww w . ja v a2 s . co m*/ }
From source file:org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.java
private Properties getPropertiesFromApplication(Environment environment) { Properties properties = new Properties(); try {//from w w w.jav a 2 s . com String property = environment.getProperty(VCAP_APPLICATION, "{}"); Map<String, Object> map = this.parser.parseMap(property); extractPropertiesFromApplication(properties, map); } catch (Exception ex) { logger.error("Could not parse VCAP_APPLICATION", ex); } return properties; }
From source file:org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.java
private Properties getPropertiesFromServices(Environment environment) { Properties properties = new Properties(); try {//from w w w .j ava 2s .c o m String property = environment.getProperty(VCAP_SERVICES, "{}"); Map<String, Object> map = this.parser.parseMap(property); extractPropertiesFromServices(properties, map); } catch (Exception ex) { logger.error("Could not parse VCAP_SERVICES", ex); } return properties; }
From source file:org.springframework.boot.cloudfoundry.VcapApplicationListener.java
private Properties getPropertiesFromApplication(Environment environment) { Properties properties = new Properties(); try {//from w w w. j a v a2 s . c om Map<String, Object> map = this.parser.parseMap(environment.getProperty(VCAP_APPLICATION, "{}")); extractPropertiesFromApplication(properties, map); } catch (Exception ex) { logger.error("Could not parse VCAP_APPLICATION", ex); } return properties; }
From source file:org.springframework.boot.cloudfoundry.VcapApplicationListener.java
private Properties getPropertiesFromServices(Environment environment) { Properties properties = new Properties(); try {/*from www . j ava 2 s . c o m*/ Map<String, Object> map = this.parser.parseMap(environment.getProperty(VCAP_SERVICES, "{}")); extractPropertiesFromServices(properties, map); } catch (Exception ex) { logger.error("Could not parse VCAP_SERVICES", ex); } return properties; }
From source file:org.springframework.boot.context.initializer.VcapApplicationContextInitializer.java
private Properties getPropertiesFromApplication(Environment environment) { Properties properties = new Properties(); try {//from ww w . jav a 2 s. c om Map<String, Object> map = this.parser.parseMap(environment.getProperty(VCAP_APPLICATION, "{}")); if (map != null) { map = new LinkedHashMap<String, Object>(map); for (String key : map.keySet()) { Object value = map.get(key); if (!(value instanceof String)) { if (value == null) { value = ""; } map.put(key, value.toString()); } } properties.putAll(map); } } catch (Exception ex) { logger.error("Could not parse VCAP_APPLICATION", ex); } return properties; }
From source file:org.springframework.boot.context.initializer.VcapApplicationContextInitializer.java
private Properties getPropertiesFromServices(Environment environment) { Properties properties = new Properties(); try {/* w w w . ja va 2s .c o m*/ Map<String, Object> map = this.parser.parseMap(environment.getProperty(VCAP_SERVICES, "{}")); if (map != null) { for (Object services : map.values()) { @SuppressWarnings("unchecked") List<Object> list = (List<Object>) services; for (Object object : list) { @SuppressWarnings("unchecked") Map<String, Object> service = (Map<String, Object>) object; String key = (String) service.get("name"); if (key == null) { key = (String) service.get("label"); } flatten(properties, service, key); } } } } catch (Exception ex) { logger.error("Could not parse VCAP_SERVICES", ex); } return properties; }