Example usage for javax.net.ssl SSLSocket connect

List of usage examples for javax.net.ssl SSLSocket connect

Introduction

In this page you can find the example usage for javax.net.ssl SSLSocket connect.

Prototype

public void connect(SocketAddress endpoint, int timeout) throws IOException 

Source Link

Document

Connects this socket to the server with a specified timeout value.

Usage

From source file:com.hp.mercury.ci.jenkins.plugins.oo.ssl.FakeSocketFactory.java

@Override
public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket(params));
    if (localAddress != null) {
        // we need to bind explicitly
        sslsock.bind(localAddress);/*from   w  ww.j  a va2s .co  m*/
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}

From source file:edu.htl3r.schoolplanner.backend.network.Network.java

/**
 * Liefert ein {@link SSLSocket}, wenn eine Verbindung via SSL zum Server aufgebaut werden konnte oder 'null', wenn SSL nicht verfuegbar ist.
 * @param sa Die Adresse des Sockets, zum dem die Verbindung aufgebaut werden soll
 * @param set Ein Set mit {@link SSLSocket}s, mithilfe derer versucht werden soll, eine Verbindung aufzubauen 
 * @return Das erste SSLSocket aus dem Set, mit dem eine problemlos Verbindung zum Server aufgebaut werden konnte oder 'null', wenn dies mit keinem moeglich war
 *//* ww w .  java 2 s  .  co m*/
private SSLSocket getWorkingSSLSocket(SocketAddress sa, Set<SSLSocket> set) {
    final int sslSocketTimeout = 2000;
    for (SSLSocket sslSocket : set) {
        try {
            sslSocket.connect(sa, sslSocketTimeout);
            sslSocket.setSoTimeout(sslSocketTimeout);
            sslSocket.setReuseAddress(true);
            sslSocket.startHandshake();
            return sslSocket;
        } catch (IOException e) {
        } finally {
            try {
                sslSocket.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}

From source file:com.sos.VirtualFileSystem.HTTP.EasySSLSocketFactory.java

@Override
public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket(params));
    if (localAddress != null) {
        // we need to bind explicitly 
        sslsock.bind(localAddress);//  w w w  .  j a  va 2s. co  m
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}

From source file:securitytools.common.http.TrustingSSLConnectionSocketFactory.java

@Override
public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress,
        InetSocketAddress localAddress, HttpContext context) throws IOException {
    if (sock == null) {
        sock = createSocket(context);/*from w  w  w  .  j  a  v  a  2s  . c  o m*/
    }
    SSLSocket sslSocket = null;
    if (sock instanceof SSLSocket) {
        sslSocket = (SSLSocket) sock;
    } else {
        throw new AssertionError("Unexpected type: " + sock);
    }

    if (localAddress != null) {
        sslSocket.bind(localAddress);
    }

    sslSocket.connect(remoteAddress, connectTimeout);
    return sslSocket;
}

From source file:it.anyplace.sync.core.security.KeystoreHandler.java

public Socket createSocket(InetSocketAddress relaySocketAddress, final String... protocols) throws Exception {
    SSLSocket socket = (SSLSocket) getSocketFactory().createSocket();
    socket.connect(relaySocketAddress, SOCKET_TIMEOUT);
    enableALPN(socket, protocols);/*from   ww  w .jav a  2s . c om*/
    return socket;
}

From source file:com.lolay.android.security.OpenSSLSocketFactory.java

@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0) {
            localPort = 0;/*from www . j  av  a  2 s  . c o m*/
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}

From source file:com.dvdprime.android.app.http.CustomSSLSocketFactory.java

@Override
public Socket connectSocket(Socket socket, String reqHost, int reqPort, InetAddress arg3, int arg4,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(reqHost, reqPort);
    SSLSocket sslSocket = null;
    if (socket != null) {
        sslSocket = (SSLSocket) socket;
    } else {/*from  w  w w  .j ava  2  s. c  o m*/
        sslSocket = (SSLSocket) createSocket();
    }
    InetSocketAddress inetSocketAddress = new InetSocketAddress(arg3, arg4);
    sslSocket.bind(inetSocketAddress);

    sslSocket.connect(remoteAddress, connTimeout);
    sslSocket.setSoTimeout(soTimeout);
    return sslSocket;
}

From source file:com.manning.androidhacks.hack023.net.SimpleSSLSocketFactory.java

public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0) {
            localPort = 0;/*ww w  . ja  va 2s  .c om*/
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}

From source file:pt.hive.cameo.ssl.SSLSocketFactory.java

public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslSocket = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0) {
            localPort = 0;//from ww  w  . j  av a 2s.  com
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslSocket.bind(isa);
    }

    sslSocket.connect(remoteAddress, connTimeout);
    sslSocket.setSoTimeout(soTimeout);
    return sslSocket;

}

From source file:com.diaw.lib.tool.FakeSocketFactory.java

public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException {
    final int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    final int soTimeout = HttpConnectionParams.getSoTimeout(params);

    final InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    final SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }/*from   www. j a  v  a2  s .c o m*/
        final InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);

    return sslsock;
}