Example usage for org.springframework.util ReflectionUtils findField

List of usage examples for org.springframework.util ReflectionUtils findField

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils findField.

Prototype

@Nullable
public static Field findField(Class<?> clazz, String name) 

Source Link

Document

Attempt to find a Field field on the supplied Class with the supplied name .

Usage

From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurerTests.java

/**
 * Test ensuring that the {@link AuthScope} is set for the target host and the proxy server.
 *//*  w w  w.  j a v  a  2 s . co  m*/
@Test
public void testThatHttpClientWithProxyIsCreatedAndHasCorrectCredentialsProviders2() throws Exception {
    final URI targetHost = new URI("http://test.com");
    final HttpClientConfigurer builder = HttpClientConfigurer.create(targetHost);
    builder.basicAuthCredentials("foo", "password");
    builder.withProxyCredentials(URI.create("https://spring.io"), "proxyuser", "proxypassword");

    final Field credentialsProviderField = ReflectionUtils.findField(HttpClientConfigurer.class,
            "credentialsProvider");
    ReflectionUtils.makeAccessible(credentialsProviderField);
    CredentialsProvider credentialsProvider = (CredentialsProvider) credentialsProviderField.get(builder);
    Assert.assertNotNull(credentialsProvider.getCredentials(new AuthScope("test.com", 80)));
    Assert.assertNotNull(credentialsProvider.getCredentials(new AuthScope("spring.io", 80)));
}

From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java

private void setField(Class<?> type, String name, Object value) {
    Field field = ReflectionUtils.findField(type, name);
    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, null, value);
}

From source file:org.springframework.cloud.netflix.eureka.CloudEurekaClient.java

public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
        DiscoveryClientOptionalArgs args, ApplicationEventPublisher publisher) {
    super(applicationInfoManager, config, args);
    this.applicationInfoManager = applicationInfoManager;
    this.publisher = publisher;
    this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class, "eurekaTransport");
    ReflectionUtils.makeAccessible(this.eurekaTransportField);
}

From source file:org.springframework.cloud.netflix.eureka.CloudEurekaClient.java

EurekaHttpClient getEurekaHttpClient() {
    if (this.eurekaHttpClient.get() == null) {
        try {//from ww w . j  a  va  2 s  .  c  o  m
            Object eurekaTransport = this.eurekaTransportField.get(this);
            Field registrationClientField = ReflectionUtils.findField(eurekaTransport.getClass(),
                    "registrationClient");
            ReflectionUtils.makeAccessible(registrationClientField);
            this.eurekaHttpClient.compareAndSet(null,
                    (EurekaHttpClient) registrationClientField.get(eurekaTransport));
        } catch (IllegalAccessException e) {
            log.error("error getting EurekaHttpClient", e);
        }
    }
    return this.eurekaHttpClient.get();
}

From source file:org.springframework.cloud.netflix.feign.FeignHttpClientConfigurationTests.java

protected <T> Object getField(Object target, String name) {
    Field field = ReflectionUtils.findField(target.getClass(), name);
    ReflectionUtils.makeAccessible(field);
    Object value = ReflectionUtils.getField(field, target);
    return value;
}

From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilterTests.java

protected <T> T getField(Object target, String name) {
    Field field = ReflectionUtils.findField(target.getClass(), name);
    ReflectionUtils.makeAccessible(field);
    Object value = ReflectionUtils.getField(field, target);
    return (T) value;
}

From source file:org.springframework.cloud.netflix.zuul.test.ZuulApacheHttpClientConfigurationTests.java

@SuppressWarnings("unchecked")
protected <T> T getField(Object target, String name) {
    Field field = ReflectionUtils.findField(target.getClass(), name);
    ReflectionUtils.makeAccessible(field);
    Object value = ReflectionUtils.getField(field, target);
    return (T) value;
}

From source file:org.springframework.cloud.netflix.zuul.ZuulFilterInitializer.java

private void clearLoaderCache() {
    Field field = ReflectionUtils.findField(FilterLoader.class, "hashFiltersByType");
    ReflectionUtils.makeAccessible(field);
    @SuppressWarnings("rawtypes")
    Map cache = (Map) ReflectionUtils.getField(field, filterLoader);
    cache.clear();/*w w w.ja  v  a 2s  .  c o  m*/
}

From source file:org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration.java

SleuthKafkaAspect(KafkaTracing kafkaTracing, Tracer tracer) {
    this.kafkaTracing = kafkaTracing;
    this.tracer = tracer;
    this.recordMessageConverter = ReflectionUtils.findField(MessagingMessageListenerAdapter.class,
            "recordMessageConverter");
}

From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java

protected Object getEnumValue(String asmTypeDescriptor, String attributeValue) {
    Object valueToUse = attributeValue;
    try {/*from  w  ww .  j  a  va  2  s  . c om*/
        Class<?> enumType = ClassUtils.forName(Type.getType(asmTypeDescriptor).getClassName(),
                this.classLoader);
        Field enumConstant = ReflectionUtils.findField(enumType, attributeValue);
        if (enumConstant != null) {
            ReflectionUtils.makeAccessible(enumConstant);
            valueToUse = enumConstant.get(null);
        }
    } catch (ClassNotFoundException | NoClassDefFoundError ex) {
        logger.debug("Failed to classload enum type while reading annotation metadata", ex);
    } catch (IllegalAccessException | AccessControlException ex) {
        logger.debug("Could not access enum value while reading annotation metadata", ex);
    }
    return valueToUse;
}