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

top.jfunc.http.component.AbstractRequesterFactory Maven / Gradle / Ivy

package top.jfunc.http.component;

import top.jfunc.http.request.HttpRequest;
import top.jfunc.common.utils.CollectionUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author xiongshiyan at 2020/1/6 , contact me with email [email protected] or phone 15208384257
 */
public abstract class AbstractRequesterFactory implements RequesterFactory {
    private List> requesterCustomizers;

    @Override
    public C create(HttpRequest httpRequest) throws IOException{
        C c = doCreate(httpRequest);

        if(CollectionUtil.isNotEmpty(getRequesterCustomizers())){
            for (RequesterCustomizer customer : getRequesterCustomizers()) {
                customer.customize(c , httpRequest);
            }
        }

        return c;
    }

    /**真正的创建*/
    protected abstract C doCreate(HttpRequest httpRequest) throws IOException;


    public List> getRequesterCustomizers() {
        return requesterCustomizers;
    }

    public void setRequesterCustomizers(List> requesterCustomizers) {
        this.requesterCustomizers = requesterCustomizers;
    }

    public void addCustomizers(RequesterCustomizer... requesterCustomizers){
        if(null == this.requesterCustomizers){
            this.requesterCustomizers = new ArrayList<>();
        }

        this.requesterCustomizers.addAll(Arrays.asList(requesterCustomizers));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy