Java Code Examples for org.springframework.cloud.util.ProxyUtils

The following examples show how to use org.springframework.cloud.util.ProxyUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: api-layer   Source File: DiscoveryClientConfig.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@RefreshScope
public ApimlDiscoveryClient eurekaClient(ApplicationInfoManager manager,
                                         EurekaClientConfig config,
                                         EurekaInstanceConfig instance,
                                         @Autowired(required = false) HealthCheckHandler healthCheckHandler
) {
    ApplicationInfoManager appManager;
    if (AopUtils.isAopProxy(manager)) {
        appManager = ProxyUtils.getTargetObject(manager);
    } else {
        appManager = manager;
    }
    final ApimlDiscoveryClient discoveryClientClient = new ApimlDiscoveryClient(appManager, config, this.optionalArgs, this.context);
    discoveryClientClient.registerHealthCheck(healthCheckHandler);

    discoveryClientClient.registerEventListener(event -> {
        if (event instanceof CacheRefreshedEvent) {
            refreshableRouteLocators.forEach(RefreshableRouteLocator::refresh);
            zuulHandlerMapping.setDirty(true);
        }
    });
    return discoveryClientClient;
}
 
Example 2
@Bean(destroyMethod = "shutdown")
@RefreshScope
public ApimlDiscoveryClientStub eurekaClient(ApplicationInfoManager manager,
                                             EurekaClientConfig config,
                                             EurekaInstanceConfig instance,
                                             @Autowired(required = false) HealthCheckHandler healthCheckHandler,
                                             ApplicationRegistry applicationRegistry
) {
    ApplicationInfoManager appManager;
    if (AopUtils.isAopProxy(manager)) {
        appManager = ProxyUtils.getTargetObject(manager);
    } else {
        appManager = manager;
    }

    final ApimlDiscoveryClientStub discoveryClient = new ApimlDiscoveryClientStub(appManager, config, this.optionalArgs, this.context, applicationRegistry);
    discoveryClient.registerHealthCheck(healthCheckHandler);

    discoveryClient.registerEventListener(event -> {
        if (event instanceof CacheRefreshedEvent) {
            refreshableRouteLocators.forEach(RefreshableRouteLocator::refresh);
            zuulHandlerMapping.setDirty(true);
        }
    });
    return discoveryClient;
}
 
Example 3
@Override
public void postProcessBeforeDestruction(Object bean, String name) throws BeansException {
    if (environment == null) {
        return;
    }

    Object target = bean;
    if (AopUtils.isAopProxy(bean)) {
        target = ProxyUtils.getTargetObject(target);
    }

    if (AnnotationUtils.findAnnotation(target.getClass(), ConfigurationProperties.class) == null) {
        return;
    }

    try {
        target.getClass().getConstructor();
    } catch (NoSuchMethodException e) {
        logger.debug("can not found default constructor, skip it");
        return;
    }

    try {
        ConfigurationProperties annotation = AnnotationUtils.findAnnotation(
                target.getClass(), ConfigurationProperties.class);
        String prefix = annotation.prefix();
        Object result = Binder.get(environment).bind(prefix, (Class) target.getClass()).orElseCreate(target.getClass());
        BeanUtils.copyProperties(result, target);
    } catch (Throwable t) {
        logger.warn("error while process destruction bean with name: {}", name, t);
    }
}
 
Example 4
Source Project: spring-cloud-sleuth   Source File: TracingFeignClient.java    License: Apache License 2.0 5 votes vote down vote up
TracingFeignClient(HttpTracing httpTracing, Client delegate) {
	this.currentTraceContext = httpTracing.tracing().currentTraceContext();
	this.handler = HttpClientHandler.create(httpTracing);
	Client delegateTarget = ProxyUtils.getTargetObject(delegate);
	this.delegate = delegateTarget instanceof TracingFeignClient
			? ((TracingFeignClient) delegateTarget).delegate : delegateTarget;
}