Example usage for javax.net.ssl SSLSocketFactory createSocket

List of usage examples for javax.net.ssl SSLSocketFactory createSocket

Introduction

In this page you can find the example usage for javax.net.ssl SSLSocketFactory createSocket.

Prototype

public abstract Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException;

Source Link

Document

Returns a socket layered over an existing socket connected to the named host, at the given port.

Usage

From source file:org.apache.jmeter.util.HttpSSLProtocolSocketFactory.java

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
        throws IOException {
    SSLSocketFactory sslfac = getSSLSocketFactory();
    Socket sock = sslfac.createSocket(address, port, localAddress, localPort);
    setSocket(sock);/*  w  ww. j a v  a2  s. c om*/
    return wrapSocket(sock);
}

From source file:org.apache.jmeter.util.HttpSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
 *//*from   w ww .  ja v a  2  s .  c o m*/
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
        throws IOException, UnknownHostException {
    SSLSocketFactory sslfac = getSSLSocketFactory();
    Socket sock = sslfac.createSocket(socket, host, port, autoClose);
    setSocket(sock);
    return wrapSocket(sock);
}

From source file:org.apache.jmeter.util.HttpSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
 *//*w w w .j  a  v a 2 s  . c o m*/
@Override
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
        throws IOException, UnknownHostException {

    SSLSocketFactory sslfac = getSSLSocketFactory();
    Socket sock = sslfac.createSocket(host, port, clientHost, clientPort);
    setSocket(sock);
    return wrapSocket(sock);
}

From source file:org.apache.jmeter.util.HttpSSLProtocolSocketFactory.java

/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 *
 * @param host the host name/IP//from w  w  w . ja v  a2s  .  c o m
 * @param port the port on the host
 * @param localAddress the local host name/IP to bind the socket to
 * @param localPort the port on the local machine
 * @param params {@link HttpConnectionParams Http connection parameters}
 *
 * @return Socket a new socket
 *
 * @throws IOException if an I/O error occurs while creating the socket
 * @throws UnknownHostException if the IP address of the host cannot be
 * determined
 */
@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params)
        throws IOException, UnknownHostException, ConnectTimeoutException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    int timeout = params.getConnectionTimeout();

    SSLSocketFactory sslfac = getSSLSocketFactory();
    Socket socket;
    if (timeout == 0) {
        socket = sslfac.createSocket(host, port, localAddress, localPort);
    } else {
        socket = sslfac.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
    }
    setSocket(socket);
    return wrapSocket(socket);
}

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.StrictSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
 *///from w w w  .  j a  v  a  2 s .  c o m
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
        throws IOException, UnknownHostException {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket sslSocket = (SSLSocket) sf.createSocket(host, port, clientHost, clientPort);
    verifyHostname(sslSocket);

    return sslSocket;
}

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.StrictSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
 *//*ww  w  .j  a  v a  2 s .c  o  m*/
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
        throws IOException, UnknownHostException {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket sslSocket = (SSLSocket) sf.createSocket(socket, host, port, autoClose);
    verifyHostname(sslSocket);

    return sslSocket;
}

From source file:cc.abstra.trantor.security.ssl.OwnSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
 *///  w  ww  .  java  2  s .  c  o m
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
        throws IOException, UnknownHostException {
    SSLSocketFactory sf = getSSLContext().getSocketFactory();
    SSLSocket sslSocket = (SSLSocket) sf.createSocket(host, port, clientHost, clientPort);
    verifyHostname(sslSocket);

    return sslSocket;
}

From source file:cc.abstra.trantor.security.ssl.OwnSSLProtocolSocketFactory.java

/**
 * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
 *//*from   www  . ja  v  a  2 s.  c o m*/
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
        throws IOException, UnknownHostException {
    SSLSocketFactory sf = getSSLContext().getSocketFactory();
    SSLSocket sslSocket = (SSLSocket) sf.createSocket(socket, host, port, autoClose);
    verifyHostname(sslSocket);

    return sslSocket;
}

From source file:org.elasticsearch.hadoop.rest.commonshttp.CommonsHttpTransportTests.java

private ProtocolSocketFactory getSocketFactory() throws Exception {
    final SSLSocketFactory delegate = SSLContext.getDefault().getSocketFactory();
    return new ProtocolSocketFactory() {

        @Override//  w w w  .  j  a  va 2s.c  om
        public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
                throws IOException, UnknownHostException {
            return delegate.createSocket(host, port, localAddress, localPort);
        }

        @Override
        public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
                HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
            return this.createSocket(host, port, localAddress, localPort);
        }

        @Override
        public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
            return delegate.createSocket(host, port);
        }
    };
}

From source file:org.apache.ftpserver.ssl.Ssl.java

/**
 * Returns a socket layered over an existing socket.
 *//*from  www  . j a  v a 2 s . c o m*/
public Socket createSocket(String protocol, Socket soc, boolean clientMode) throws Exception {

    // already wrapped - no need to do anything
    if (soc instanceof SSLSocket) {
        return soc;
    }

    // get socket factory
    SSLContext ctx = getSSLContext(protocol);
    SSLSocketFactory socFactory = ctx.getSocketFactory();

    // create socket
    String host = soc.getInetAddress().getHostAddress();
    int port = soc.getLocalPort();
    SSLSocket ssoc = (SSLSocket) socFactory.createSocket(soc, host, port, true);
    ssoc.setUseClientMode(clientMode);

    // initialize socket
    String cipherSuites[] = ssoc.getSupportedCipherSuites();
    ssoc.setEnabledCipherSuites(cipherSuites);
    ssoc.setNeedClientAuth(m_clientAuthReqd);

    return ssoc;
}