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

group.flyfish.rest.configuration.RestClientProperties Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package group.flyfish.rest.configuration;

import group.flyfish.rest.configuration.configure.PropertiesConfigurable;
import group.flyfish.rest.configuration.modifier.RestPropertiesModifier;
import group.flyfish.rest.core.auth.RestAuthProvider;
import group.flyfish.rest.registry.proxy.RestInvokers;
import group.flyfish.rest.utils.DataUtils;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 客户端的配置
 *
 * @author wangyu
 * 整合入spring boot,简化配置,提高业务复用性
 */
@Data
@Slf4j
public class RestClientProperties implements InitializingBean {

    /**
     * 超时时间,默认30s
     */
    private Duration connectionTimeout = Duration.ofSeconds(30);

    /**
     * 基本url
     */
    private String baseUrl;

    /**
     * ssl无条件新人
     */
    private Boolean alwaysTrust = true;

    /**
     * 定义的内容字典,可以支持动态取值,使用#variable
     */
    private Map urls = new HashMap<>();

    /**
     * 默认的认证提供者
     */
    private RestAuthProvider authProvider;

    /**
     * 修改器们
     */
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private List modifiers;

    /**
     * 配置感知项
     */
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private List configures;

    /**
     * 获取字典url
     *
     * @param key 键
     * @return 结果
     */
    public String getDictUrl(String key) {
        if (DataUtils.isEmpty(urls)) {
            return null;
        }
        return urls.get(key);
    }

    @Autowired(required = false)
    public void setDefaultAuthProvider(RestAuthProvider provider) {
        this.authProvider = provider;
    }

    @Autowired(required = false)
    public void setModifiers(List modifiers) {
        this.modifiers = modifiers;
    }

    @Autowired(required = false)
    public void setConfigures(List configures) {
        this.configures = configures;
    }

    @Override
    public void afterPropertiesSet() {
        if (DataUtils.isNotEmpty(modifiers)) {
            modifiers.forEach(modifier -> modifier.modify(this));
        }
        if (DataUtils.isNotEmpty(configures)) {
            configures.forEach(item -> item.configure(this));
        }
        RestInvokers.configure(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy