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

com.applitools.connectivity.api.HttpClientImpl Maven / Gradle / Ivy

There is a newer version: 3.215.0-beta
Show newest version
package com.applitools.connectivity.api;

import com.applitools.eyes.AbstractProxySettings;
import com.applitools.eyes.Logger;
import com.applitools.eyes.logging.Stage;
import com.applitools.utils.GeneralUtils;
import com.applitools.utils.NetworkUtils;
import org.apache.commons.lang3.tuple.Pair;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;

public class HttpClientImpl extends HttpClient {
    public HttpClientImpl(Logger logger, int timeout, AbstractProxySettings abstractProxySettings) {
        super(logger, timeout, abstractProxySettings);
        logger.log(new HashSet(), Stage.GENERAL, Pair.of("connectivityPackage", "java.net"));

        try {
            HttpsURLConnection.setDefaultSSLSocketFactory(NetworkUtils.getDisabledSSLContext().getSocketFactory());
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            GeneralUtils.logExceptionStackTrace(logger, Stage.GENERAL, e);
        }
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        });
    }

    @Override
    public ConnectivityTarget target(URI baseUrl) {
        return new ConnectivityTargetImpl(logger, baseUrl.toString(), abstractProxySettings, timeout);
    }

    @Override
    public ConnectivityTarget target(String path) {
        return new ConnectivityTargetImpl(logger, path, abstractProxySettings, timeout);
    }

    @Override
    public void close() {
        isClosed = true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy