Example usage for org.springframework.util ReflectionUtils getField

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

Introduction

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

Prototype

@Nullable
public static Object getField(Field field, @Nullable Object target) 

Source Link

Document

Get the field represented by the supplied Field field object on the specified Object target object .

Usage

From source file:org.springframework.cloud.config.server.environment.HttpClientConfigurableHttpConnectionFactoryTest.java

private HttpClientBuilder getActualHttpClientBuilder(HttpConnection actualConnection) {
    HttpClient actualHttpClient = getActualHttpClient(actualConnection);
    Field closeablesField = ReflectionUtils.findField(actualHttpClient.getClass(), "closeables");
    ReflectionUtils.makeAccessible(closeablesField);
    List<?> closables = (List<?>) ReflectionUtils.getField(closeablesField, actualHttpClient);
    return closables.stream().map(o -> {
        Field builderField = Arrays.stream(o.getClass().getDeclaredFields())
                .filter(field -> HttpClientBuilder.class.isAssignableFrom(field.getType())).findFirst()
                .orElse(null);// w ww .java2s.c o  m
        if (builderField != null) {
            ReflectionUtils.makeAccessible(builderField);
            return ReflectionUtils.getField(builderField, o);
        }
        return null;
    }).filter(Objects::nonNull).map(HttpClientBuilder.class::cast).findFirst().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();//from  w  w w. j a  va  2  s  .c o  m
}

From source file:org.springframework.data.gemfire.RegionFactoryBean.java

@SuppressWarnings("unchecked")
private AttributesFactory<K, V> findAttrFactory(RegionFactory<K, V> regionFactory) {
    Field attrField = ReflectionUtils.findField(RegionFactory.class, "attrsFactory", AttributesFactory.class);
    ReflectionUtils.makeAccessible(attrField);
    return (AttributesFactory<K, V>) ReflectionUtils.getField(attrField, regionFactory);
}

From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java

/**
 * Clean the LocalDirAllocator#contexts//from  w w  w .ja va 2 s.co m
 */
private static void cleanHadoopLocalDirAllocator() {
    Field field = ReflectionUtils.findField(LocalDirAllocator.class, "contexts");
    ReflectionUtils.makeAccessible(field);
    Map contexts = (Map) ReflectionUtils.getField(field, null);
    if (contexts != null) {
        contexts.clear();
    }
}

From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java

private static void fixHadoopReflectionUtilsLeak(ClassLoader leakedClassLoader) {
    // replace Configuration#CLASS_CACHE in Hadoop 2.0 which prevents CL from being recycled
    // this is a best-effort really as the leak can occur again - see HADOOP-8632

    // only available on Hadoop-2.0/CDH4
    if (CLASS_CACHE == null) {
        return;//from w w w.  ja v a 2 s .c om
    }

    Map<?, ?> cache = (Map<?, ?>) ReflectionUtils.getField(CLASS_CACHE, null);
    cache.remove(leakedClassLoader);
}

From source file:org.springframework.data.hadoop.util.PermissionUtils.java

public static void hackHadoopStagingOnWin() {
    // do the assignment only on Windows systems
    if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
        // 0655 = -rwxr-xr-x
        JobSubmissionFiles.JOB_DIR_PERMISSION.fromShort((short) 0650);
        JobSubmissionFiles.JOB_FILE_PERMISSION.fromShort((short) 0650);

        if (trackerDistributedCacheManagerClass != null) {
            // handle jar permissions as well
            Field field = ReflectionUtils.findField(trackerDistributedCacheManagerClass,
                    "PUBLIC_CACHE_OBJECT_PERM");
            ReflectionUtils.makeAccessible(field);
            FsPermission perm = (FsPermission) ReflectionUtils.getField(field, null);
            perm.fromShort((short) 0650);
        }/*from  w  w  w . java 2 s.  c  om*/
    }
}

From source file:org.springframework.data.solr.server.support.SolrServerUtils.java

@SuppressWarnings("unchecked")
private static <T> T readField(SolrServer solrServer, String fieldName) {
    Field field = ReflectionUtils.findField(solrServer.getClass(), fieldName);
    if (field == null) {
        return null;
    }//from  w  w w .  j  av a  2s. c o m
    ReflectionUtils.makeAccessible(field);
    return (T) ReflectionUtils.getField(field, solrServer);
}