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

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

There is a newer version: 1.2.4
Show newest version
package com.github.dadiyang.httpinvoker.spring;

import com.github.dadiyang.httpinvoker.HttpApiProxyFactory;
import com.github.dadiyang.httpinvoker.propertyresolver.PropertyResolver;
import com.github.dadiyang.httpinvoker.requestor.RequestPreprocessor;
import com.github.dadiyang.httpinvoker.requestor.Requestor;
import com.github.dadiyang.httpinvoker.requestor.ResponseProcessor;
import org.springframework.beans.factory.FactoryBean;

/**
 * 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 PropertyResolver propertyResolver;
    private RequestPreprocessor requestPreprocessor;
    private ResponseProcessor responseProcessor;

    public Class getInterfaceClass() {
        return interfaceClass;
    }

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

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

    public void setPropertyResolver(PropertyResolver propertyResolver) {
        this.propertyResolver = propertyResolver;
    }

    public void setRequestPreprocessor(RequestPreprocessor requestPreprocessor) {
        this.requestPreprocessor = requestPreprocessor;
    }

    public void setResponseProcessor(ResponseProcessor responseProcessor) {
        this.responseProcessor = responseProcessor;
    }

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

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy