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

com.github.dadiyang.httpinvoker.spring.HttpApiProxyFactoryBean Maven / Gradle / Ivy

package com.github.dadiyang.httpinvoker.spring;

import com.github.dadiyang.httpinvoker.HttpApiProxyFactory;
import com.github.dadiyang.httpinvoker.requestor.Requestor;
import org.springframework.beans.factory.FactoryBean;

import java.util.Properties;

/**
 * A factory bean which produce HttpApi interface's implement by using proxyFactory
 *
 * @author huangxuyang
 * date 2018/11/1
 */
public class HttpApiProxyFactoryBean implements FactoryBean {
    private HttpApiProxyFactory proxyFactory;
    private Requestor requestor;
    private Class interfaceClass;
    private Properties properties;

    public Class getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public void setRequestor(Requestor requestor) {
        this.requestor = requestor;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public T getObject() throws Exception {
        if (proxyFactory == null) {
            proxyFactory = new HttpApiProxyFactory(requestor, properties);
        }
        return (T) proxyFactory.getProxy(interfaceClass);
    }

    @Override
    public Class getObjectType() {
        return interfaceClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy