package com.sifang.modules.factory.aiswei.config;

import com.sifang.modules.sys.util.http.EzTemplateBase;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;

@Service
public class AisweiApiRestTemplate extends EzTemplateBase {

    private static final Logger log = LoggerFactory.getLogger(AisweiApiRestTemplate.class);

    public AisweiApiRestTemplate() {
        super(createRestTemplate(createHttpRequestFactory()));
    }

    protected static ClientHttpRequestFactory createHttpRequestFactory() {
        int timeout = 30000;
        RequestConfig config = RequestConfig.custom()
                .setConnectTimeout(timeout)
                .setConnectionRequestTimeout(timeout)
                .setSocketTimeout(timeout).build();

        CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
        return new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
    }

}
