Example usage for javax.net SocketFactory createSocket

List of usage examples for javax.net SocketFactory createSocket

Introduction

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

Prototype

public abstract Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
        throws IOException;

Source Link

Document

Creates a socket and connect it to the specified remote address on the specified remote port.

Usage

From source file:proxy.ElementalHttpGet.java

private static void request(HttpProcessor httpproc, HttpRequestExecutor httpexecutor,
        HttpCoreContext coreContext, HttpHost host, InetAddress localinetAddress)
        throws NoSuchAlgorithmException, IOException, HttpException {
    DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
    ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
    try {/*from   w w w .  j  ava 2  s . c o  m*/

        String[] targets = { "/2/users/show.json?access_token=2.00SlDQsDdcZIJC94e5308f67sRL13D&uid=3550148352",
                "/account/rate_limit_status.json?access_token=2.00SlDQsDdcZIJC94e5308f67sRL13D" };

        for (int i = 0; i < targets.length; i++) {
            if (!conn.isOpen()) {
                SSLContext sslcontext = SSLContext.getInstance("Default");
                //               sslcontext.init(null, null, null);
                SocketFactory sf = sslcontext.getSocketFactory();
                SSLSocket socket = (SSLSocket) sf.createSocket(host.getHostName(), host.getPort(),
                        localinetAddress, 0);
                socket.setEnabledCipherSuites(new String[] { "TLS_RSA_WITH_AES_256_CBC_SHA",
                        "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" });
                conn.bind(socket);
                //               Socket socket = new Socket(host.getHostName(), host.getPort());
                //               conn.bind(socket);
            }
            BasicHttpRequest request = new BasicHttpRequest("GET", targets[i]);
            System.out.println(">> Request URI: " + request.getRequestLine().getUri());

            httpexecutor.preProcess(request, httpproc, coreContext);
            HttpResponse response = httpexecutor.execute(request, conn, coreContext);
            httpexecutor.postProcess(response, httpproc, coreContext);

            System.out.println("<< Response: " + response.getStatusLine());
            System.out.println(EntityUtils.toString(response.getEntity()));
            System.out.println("==============");
            if (!connStrategy.keepAlive(response, coreContext)) {
                conn.close();
            } else {
                System.out.println("Connection kept alive...");
            }
        }
    } finally {
        conn.close();
    }
}

From source file:org.apache.axis2.java.security.SSLProtocolSocketFactory.java

public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//  w  ww.j a v  a2 s .c  o m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = ctx.getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:org.candlepin.client.AbstractSLLProtocolSocketFactory.java

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");
    }/*ww  w  .j  a v  a  2 s  .c o  m*/
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:org.oscarehr.olis.OLISProtocolSocketFactory.java

public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//w  ww . j a  v  a  2 s .c  o  m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = context.getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:com.vmware.aurora.vc.vcservice.TlsSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//w w  w .  j  ava 2  s .  co  m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(new InetSocketAddress(host, port), timeout);
        return socket;
    }
}

From source file:eu.europa.ec.markt.dss.validation.https.SimpleProtocolSocketFactory.java

@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");
    }//ww w  .  j a va2s. c o  m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:org.opensaml.ws.soap.client.http.TLSProtocolSocketFactory.java

/** {@inheritDoc} */
public Socket createSocket(String host, int port, InetAddress localHost, int localPort,
        HttpConnectionParams connParams) throws IOException {
    if (connParams == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }/*from w ww  . j  a  v  a 2 s  .c o  m*/
    int timeout = connParams.getConnectionTimeout();
    SocketFactory socketfactory = sslContext.getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localHost, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localHost, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:com.linkedin.d2.discovery.stores.glu.TrustingSocketFactory.java

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");
    }//www. ja  v a 2 s  .co  m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}

From source file:com.denimgroup.threadfix.remote.AcceptAllTrustManager.java

@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//  w  w w  .  j ava2s . com

    int timeout = params.getConnectionTimeout();
    SocketFactory socketFactory = getSSLContext().getSocketFactory();

    if (timeout == 0) {
        return socketFactory.createSocket(host, port, localAddress, localPort);
    }

    else {
        Socket socket = socketFactory.createSocket();
        SocketAddress localAddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteAddr = new InetSocketAddress(host, port);
        socket.bind(localAddr);
        socket.connect(remoteAddr, timeout);
        return socket;
    }
}

From source file:org.codeartisans.proxilet.EasySSLProtocolSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//  w w w .  j  a  v a2 s.  c  o  m
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
        return socket;
    }
}