All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.linyuzai.dynamicfeign.proxy.DynamicFeignProxy Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package com.github.linyuzai.dynamicfeign.proxy;

import com.github.linyuzai.dynamicfeign.mapper.DynamicFeignClientMapper;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicFeignProxy implements InvocationHandler {

    private Class feignInterface;

    private DynamicFeignClientMapper.ConfigurableFeignClient feignClient;

    public DynamicFeignProxy(Class feignInterface, DynamicFeignClientMapper.ConfigurableFeignClient feignClient) {
        if (feignInterface == null) {
            throw new RuntimeException("Dynamic feign interface is null");
        }
        if (feignClient == null) {
            throw new RuntimeException("Dynamic feign client is null");
        }
        this.feignInterface = feignInterface;
        this.feignClient = feignClient;
    }

    @SuppressWarnings("unchecked")
    public T get() {
        return (T) Proxy.newProxyInstance(feignInterface.getClassLoader(), new Class[]{feignInterface}, this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(feignClient.dynamic(method), args);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy