cn.ishow.starter.rpc.aop.RpcClientAdvice Maven / Gradle / Ivy
package cn.ishow.starter.rpc.aop;
import cn.ishow.starter.common.util.AopTargetUtils;
import cn.ishow.starter.common.util.ExceptionUtils;
import cn.ishow.starter.common.util.java.FieldUtils;
import cn.ishow.starter.rpc.annotation.Decode;
import cn.ishow.starter.rpc.annotation.Options;
import cn.ishow.starter.rpc.constant.RpcConst;
import cn.ishow.starter.rpc.context.RpcContext;
import feign.Feign;
import feign.Request;
import feign.Target;
import feign.codec.DecodeException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.env.Environment;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/**
* 拦截Feign接口上面方法,并动态设置HTTP的options和自定义解码器
*
* @author bucheng
* @create 2022/5/15 11:29
*/
@Slf4j
public class RpcClientAdvice implements MethodInterceptor {
public static final String TARGET = "target";
private final RpcContext rpcContext;
private final Environment environment;
private final ConcurrentHashMap