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

info.unifast.storage.client.SocksSslConnectionSocketFactory Maven / Gradle / Ivy

package info.unifast.storage.client;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.protocol.HttpContext;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;

public class SocksSslConnectionSocketFactory extends SSLConnectionSocketFactory {

    public SocksSslConnectionSocketFactory(SSLContext sslContext) {
        super(sslContext);
    }

    public SocksSslConnectionSocketFactory(SSLContext sslContext, HostnameVerifier hostnameVerifier) {
        super(sslContext, hostnameVerifier);
    }

    @Override
    public Socket createSocket(HttpContext context) throws IOException {
        Proxy p = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 10808));
        if (p != null) {
            return new Socket(p);
        } else {
            return super.createSocket(context);
        }
    }

    @Override
    public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host, InetSocketAddress remoteAddress,
                                InetSocketAddress localAddress, HttpContext context) throws IOException {

        remoteAddress = InetSocketAddress
                .createUnresolved(host.getHostName(), host.getPort());

        return super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy