Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

interoperable - framework changes #7

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.cn.api.util;

import com.netflix.hystrix.strategy.HystrixPlugins;
import feign.Feign;
import feign.Target;
import feign.codec.Decoder;
Expand All @@ -29,64 +30,84 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.feign.FeignClientsConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
* @author Myrle Krantz
*/
//@EnableApiFactory (for logger)
@SuppressWarnings({"unused"})
@ConditionalOnProperty(value = "hystrix.wrappers.enabled", matchIfMissing = true)
public class CustomFeignClientsConfiguration extends FeignClientsConfiguration {
private static class AnnotatedErrorDecoderFeignBuilder extends Feign.Builder {
private final Logger logger;

AnnotatedErrorDecoderFeignBuilder(final Logger logger) {
this.logger = logger;
public static final Logger logger = LoggerFactory.getLogger(CustomFeignClientsConfiguration.class.getName());

private static class AnnotatedErrorDecoderFeignBuilder extends Feign.Builder {
private final Logger logger;

AnnotatedErrorDecoderFeignBuilder(final Logger logger) {
this.logger = logger;
}

public <T> T target(Target<T> target) {
this.errorDecoder(new AnnotatedErrorDecoder(logger, target.type()));
return build().newInstance(target);
}
}

public <T> T target(Target<T> target) {
this.errorDecoder(new AnnotatedErrorDecoder(logger, target.type()));
return build().newInstance(target);
@Bean
@ConditionalOnMissingBean
public TenantedTargetInterceptor tenantedTargetInterceptor() {
return new TenantedTargetInterceptor();
}
}

@Bean
@ConditionalOnMissingBean
public TenantedTargetInterceptor tenantedTargetInterceptor()
{
return new TenantedTargetInterceptor();
}
@Bean
@ConditionalOnMissingBean
public TokenedTargetInterceptor tokenedTargetInterceptor() {
return new TokenedTargetInterceptor();
}

@Bean
@ConditionalOnMissingBean
public TokenedTargetInterceptor tokenedTargetInterceptor()
{
return new TokenedTargetInterceptor();
}
@Bean
@ConditionalOnMissingBean
public Decoder feignDecoder() {
return new GsonDecoder();
}

@Bean
@ConditionalOnMissingBean
public Decoder feignDecoder() {
return new GsonDecoder();
}
@Bean
@ConditionalOnMissingBean
public Encoder feignEncoder() {
return new GsonEncoder();
}

@Bean
@ConditionalOnMissingBean
public Encoder feignEncoder() {
return new GsonEncoder();
}
@Bean(name = ApiConfiguration.LOGGER_NAME)
public Logger logger() {
return LoggerFactory.getLogger(ApiConfiguration.LOGGER_NAME);
}

@Bean(name = ApiConfiguration.LOGGER_NAME)
public Logger logger() {
return LoggerFactory.getLogger(ApiConfiguration.LOGGER_NAME);
}
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
public Feign.Builder feignBuilder(@Qualifier(ApiConfiguration.LOGGER_NAME) final Logger logger) {
return new AnnotatedErrorDecoderFeignBuilder(logger);
}

@Bean
@Scope("prototype")
@ConditionalOnMissingBean
public Feign.Builder feignBuilder(@Qualifier(ApiConfiguration.LOGGER_NAME) final Logger logger) {
return new AnnotatedErrorDecoderFeignBuilder(logger);
}
}
@PostConstruct
public void configureHystrixConcurrencyStrategy() {
List<HystrixCallableWrapper> wrappers = new ArrayList<>();
wrappers.add(new ThreadLocalAwareCallableWrapper());
HystrixPlugins instance = HystrixPlugins.getInstance();
try {
instance.registerConcurrencyStrategy(
new HystrixContextAwareConcurrencyStrategy(wrappers));
} catch(IllegalStateException e) {
logger.warn("Another concurrency strategy is already registered in hystrix!");
}
}
}