Example usage for org.springframework.core.env PropertyResolver getProperty

List of usage examples for org.springframework.core.env PropertyResolver getProperty

Introduction

In this page you can find the example usage for org.springframework.core.env PropertyResolver getProperty.

Prototype

@Nullable
String getProperty(String key);

Source Link

Document

Return the property value associated with the given key, or null if the key cannot be resolved.

Usage

From source file:com.indeed.imhotep.iql.cache.HDFSQueryCache.java

private void kerberosLogin(PropertyResolver props) {
    try {//from   ww  w .  j  ava  2  s.com
        KerberosUtils.loginFromKeytab(props.getProperty("kerberos.principal"),
                props.getProperty("kerberos.keytab"));
    } catch (IOException e) {
        log.error("Failed to log in to Kerberos", e);
    }
}

From source file:com.indeed.imhotep.iql.cache.HDFSQueryCache.java

public HDFSQueryCache(PropertyResolver props) {

    enabled = true;//ww w. j a va  2 s .  c om
    try {
        kerberosLogin(props);

        cachePath = new Path(props.getProperty("query.cache.hdfs.path"));
        hdfs = cachePath.getFileSystem(new org.apache.hadoop.conf.Configuration());
        cacheDirWorldWritable = props.getProperty("query.cache.worldwritable", Boolean.class);

        makeSurePathExists(cachePath);
    } catch (Exception e) {
        log.info("Failed to initialize the HDFS query cache. Caching disabled.", e);
        enabled = false;
    }
}

From source file:org.obiba.agate.service.UserService.java

@Subscribe
public void sendPendingEmail(UserJoinedEvent userJoinedEvent) throws SignatureException {
    log.info("Sending pending review email: {}", userJoinedEvent.getPersistable());
    PropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "registration.");
    List<User> administrators = userRepository.findByRole("agate-administrator");
    Context ctx = new Context();
    User user = userJoinedEvent.getPersistable();
    String organization = configurationService.getConfiguration().getName();
    ctx.setLocale(LocaleUtils.toLocale(user.getPreferredLanguage()));
    ctx.setVariable("user", user);
    ctx.setVariable("organization", organization);
    ctx.setVariable("publicUrl", configurationService.getPublicUrl());

    administrators.stream()//from ww w .ja va 2  s. com
            .forEach(u -> mailService.sendEmail(u.getEmail(),
                    "[" + organization + "] " + propertyResolver.getProperty("pendingForReviewSubject"),
                    templateEngine.process("pendingForReviewEmail", ctx)));

    mailService.sendEmail(user.getEmail(),
            "[" + organization + "] " + propertyResolver.getProperty("pendingForApprovalSubject"),
            templateEngine.process("pendingForApprovalEmail", ctx));
}

From source file:org.obiba.agate.service.UserService.java

@Subscribe
public void sendConfirmationEmail(UserApprovedEvent userApprovedEvent) throws SignatureException {
    log.info("Sending confirmation email: {}", userApprovedEvent.getPersistable());
    PropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "registration.");
    Context ctx = new Context();
    User user = userApprovedEvent.getPersistable();
    String organization = configurationService.getConfiguration().getName();
    ctx.setLocale(LocaleUtils.toLocale(user.getPreferredLanguage()));
    ctx.setVariable("user", user);
    ctx.setVariable("organization", organization);
    ctx.setVariable("publicUrl", configurationService.getPublicUrl());
    ctx.setVariable("key", configurationService.encrypt(user.getName()));

    mailService.sendEmail(user.getEmail(),
            "[" + organization + "] " + propertyResolver.getProperty("confirmationSubject"),
            templateEngine.process("confirmationEmail", ctx));
}

From source file:org.springframework.util.ExtendedPlaceholderResolverUtils.java

public static final ExtendedPlaceholderResolver toPlaceholderResolver(final PropertyResolver resolver) {
    if (resolver == null) {
        return EMPTY_RESOLVER;
    } else {/*ww  w . j  av  a2s. com*/
        return new ExtendedPlaceholderResolver() {
            @Override
            public String resolvePlaceholder(String placeholderName) {
                return resolver.getProperty(placeholderName);
            }

            @Override
            public String resolvePlaceholder(String placeholderName, String defaultValue) {
                return resolver.getProperty(placeholderName, defaultValue);
            }
        };
    }
}

From source file:org.springframework.web.client.interceptors.ZeroLeggedOAuthInterceptorTest.java

@Test
public void testInterceptor() throws Exception {
    final String url = "http://www.test.com/lrs?param1=val1&param2=val2";
    final String data = "test";
    final String id = "test";
    final String realm = "realm";
    final String consumerKey = "consumerKey";
    final String secretKey = "secretKey";

    PropertyResolver resolver = mock(PropertyResolver.class);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".realm"))).thenReturn(realm);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".consumerKey")))
            .thenReturn(consumerKey);/*from  www.  j a  va 2s.c o  m*/
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".secretKey")))
            .thenReturn(secretKey);

    // holder for the headers...
    HttpHeaders headers = new HttpHeaders();

    // Mock guts of RestTemplate so no need to actually hit the web...
    ClientHttpResponse resp = mock(ClientHttpResponse.class);
    when(resp.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
    when(resp.getHeaders()).thenReturn(new HttpHeaders());

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ClientHttpRequest client = mock(ClientHttpRequest.class);
    when(client.getHeaders()).thenReturn(headers);
    when(client.getBody()).thenReturn(buffer);
    when(client.execute()).thenReturn(resp);

    ClientHttpRequestFactory factory = mock(ClientHttpRequestFactory.class);
    when(factory.createRequest(any(URI.class), any(HttpMethod.class))).thenReturn(client);

    // add the new interceptor...
    ZeroLeggedOAuthInterceptor interceptor = new ZeroLeggedOAuthInterceptor();
    interceptor.setPropertyResolver(resolver);
    interceptor.setId(id);
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
    interceptors.add(interceptor);

    RestTemplate rest = new RestTemplate(factory);
    rest.setInterceptors(interceptors);

    rest.postForLocation(url, data, Collections.emptyMap());

    // make sure auth header is correctly set...
    assertThat(headers, hasKey(Headers.Authorization.name()));

    String authHeader = headers.get(Headers.Authorization.name()).get(0);
    assertThat(authHeader, containsString("OAuth realm=\"" + realm + "\""));
    assertThat(authHeader, containsString("oauth_consumer_key=\"" + consumerKey + "\""));
    // for now, only supports HMAC-SHA1.  May have to fix later...
    assertThat(authHeader, containsString("oauth_signature_method=\"HMAC-SHA1\""));
    assertThat(authHeader, containsString("oauth_version=\"1.0\""));
    assertThat(authHeader, containsString("oauth_timestamp="));
    assertThat(authHeader, containsString("oauth_nonce="));
    assertThat(authHeader, containsString("oauth_signature="));

    // oauth lib will create 2 oauth_signature params if you call sign
    // multiple times.  Make sure only get 1.
    assertThat(StringUtils.countMatches(authHeader, "oauth_signature="), is(1));
}