Search in sources :

Example 1 with Level

use of feign.Logger.Level in project nutzboot by nutzam.

the class FeignStarter method afterBorn.

@SuppressWarnings({ "unchecked", "rawtypes" })
public Object afterBorn(Object obj, String beanName) {
    try {
        Mirror mirror = Mirror.me(obj);
        for (Field field : obj.getClass().getDeclaredFields()) {
            FeignInject fc = field.getAnnotation(FeignInject.class);
            if (fc == null)
                continue;
            String url = Strings.sBlank(conf.get(PROP_URL), "http://127.0.0.1:8080");
            Encoder encoder = getEncoder(fc, field);
            Decoder decoder = getDecoder(fc, field);
            Client client = getClient(fc, field, url);
            Logger.Level level = Level.valueOf(conf.get(PROP_LOGLEVEL, "BASIC").toUpperCase());
            Class apiType = field.getType();
            Logger logger = new Slf4jLogger(apiType);
            boolean useHystrix = "true".equals(Strings.sBlank(fc.useHystrix(), conf.get(PROP_HYSTRIX_ENABLE)));
            Feign.Builder builder = useHystrix ? HystrixFeign.builder() : Feign.builder();
            if (encoder != null)
                builder.encoder(encoder);
            if (decoder != null)
                builder.decoder(decoder);
            if (client != null)
                builder.client(client);
            builder.logger(logger);
            builder.logLevel(level);
            int connectTimeout = fc.connectTimeout();
            if (connectTimeout == 0)
                connectTimeout = conf.getInt(PROP_CONNECT_TIMEOUT, 10 * 1000);
            int readTimeout = fc.readTimeout();
            if (readTimeout == 0)
                readTimeout = conf.getInt(PROP_READ_TIMEOUT, 10 * 1000);
            builder.options(new Options(connectTimeout, readTimeout));
            Object t = null;
            if (useHystrix) {
                t = ((HystrixFeign.Builder) builder).target(apiType, url, getFallbackIocBean(apiType, fc.fallback()));
            } else {
                t = builder.target(apiType, url);
            }
            mirror.setValue(obj, field.getName(), t);
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return obj;
}
Also used : Options(feign.Request.Options) Slf4jLogger(feign.slf4j.Slf4jLogger) Decoder(feign.codec.Decoder) JAXBDecoder(feign.jaxb.JAXBDecoder) JacksonDecoder(feign.jackson.JacksonDecoder) GsonDecoder(feign.gson.GsonDecoder) Logger(feign.Logger) Slf4jLogger(feign.slf4j.Slf4jLogger) FeignInject(org.nutz.boot.starter.feign.annotation.FeignInject) Level(feign.Logger.Level) HystrixFeign(feign.hystrix.HystrixFeign) Field(java.lang.reflect.Field) Encoder(feign.codec.Encoder) JacksonEncoder(feign.jackson.JacksonEncoder) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) Feign(feign.Feign) HystrixFeign(feign.hystrix.HystrixFeign) RibbonClient(feign.ribbon.RibbonClient) EurekaClient(com.netflix.discovery.EurekaClient) Client(feign.Client) OkHttpClient(feign.okhttp.OkHttpClient) ApacheHttpClient(feign.httpclient.ApacheHttpClient) LBClient(feign.ribbon.LBClient) Mirror(org.nutz.lang.Mirror)

Aggregations

EurekaClient (com.netflix.discovery.EurekaClient)1 Client (feign.Client)1 Feign (feign.Feign)1 Logger (feign.Logger)1 Level (feign.Logger.Level)1 Options (feign.Request.Options)1 Decoder (feign.codec.Decoder)1 Encoder (feign.codec.Encoder)1 GsonDecoder (feign.gson.GsonDecoder)1 GsonEncoder (feign.gson.GsonEncoder)1 ApacheHttpClient (feign.httpclient.ApacheHttpClient)1 HystrixFeign (feign.hystrix.HystrixFeign)1 JacksonDecoder (feign.jackson.JacksonDecoder)1 JacksonEncoder (feign.jackson.JacksonEncoder)1 JAXBDecoder (feign.jaxb.JAXBDecoder)1 JAXBEncoder (feign.jaxb.JAXBEncoder)1 OkHttpClient (feign.okhttp.OkHttpClient)1 LBClient (feign.ribbon.LBClient)1 RibbonClient (feign.ribbon.RibbonClient)1 Slf4jLogger (feign.slf4j.Slf4jLogger)1