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

io.gitee.huangguiming.Imcode.service.impl.IMServiceHttpClientImpl Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package io.gitee.huangguiming.Imcode.service.impl;


import io.gitee.huangguiming.Imcode.domain.HttpType;
import io.gitee.huangguiming.Imcode.imconfig.IMConfigStorage;
import io.gitee.huangguiming.Imcode.utils.ApacheHttpClientBuilder;
import io.gitee.huangguiming.Imcode.utils.DefaultApacheHttpClientBuilder;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;

public class IMServiceHttpClientImpl extends BashIMServiceImpl {
    private CloseableHttpClient httpClient;
    private HttpHost httpProxy;

    @Override
    public CloseableHttpClient getRequestHttpClient() {
        return httpClient;
    }

    @Override
    public HttpHost getRequestHttpProxy() {
        return httpProxy;
    }

    @Override
    public HttpType getRequestType() {
        return HttpType.APACHE_HTTP;
    }

    @Override
    public void initHttp() {
        IMConfigStorage configStorage = this.getIMConfigStorage();
        ApacheHttpClientBuilder apacheHttpClientBuilder = configStorage.getApacheHttpClientBuilder();
        if (null == apacheHttpClientBuilder) {
            apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
        }

        apacheHttpClientBuilder.httpProxyHost(configStorage.getHttpProxyHost())
                .httpProxyPort(configStorage.getHttpProxyPort())
                .httpProxyUsername(configStorage.getHttpProxyUsername())
                .httpProxyPassword(configStorage.getHttpProxyPassword());

        if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
            this.httpProxy = new HttpHost(configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort());
        }

        this.httpClient = apacheHttpClientBuilder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy