use of org.nutz.boot.starter.feign.annotation.FeignInject 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);
Object t = null;
if (useHystrix) {
t = ((HystrixFeign.Builder) builder).target(apiType, url, getIocBean(apiType, fc.fallback()));
} else {
t = builder.target(apiType, url);
}
mirror.setValue(obj, field.getName(), t);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
return obj;
}
Aggregations