Example usage for org.apache.commons.httpclient.protocol ReflectionSocketFactory createSocket

List of usage examples for org.apache.commons.httpclient.protocol ReflectionSocketFactory createSocket

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.protocol ReflectionSocketFactory createSocket.

Prototype

public static Socket createSocket(final String socketfactoryName, final String host, final int port,
        final InetAddress localAddress, final int localPort, int timeout)
        throws IOException, UnknownHostException, ConnectTimeoutException 

Source Link

Document

This method attempts to execute Socket method available since Java 1.4 using reflection.

Usage

From source file:hudson.util.NoClientBindSSLProtocolSocketFactory.java

/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>/*ww  w .  java 2 s. com*/
 * This method employs several techniques to circumvent the limitations of older JREs that 
 * do not support connect timeout. When running in JRE 1.4 or above reflection is used to 
 * call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older 
 * JREs a controller thread is executed. The controller thread attempts to create a new socket
 * within the given limit of time. If socket constructor does not return until the timeout 
 * expires, the controller terminates and throws an {@link ConnectTimeoutException}
 * </p>
 *  
 * @param host the host name/IP
 * @param port the port on the host
 * @param localAddress the local host name/IP to bind the socket to, ignored.
 * @param localPort the port on the local machine, ignored.
 * @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
 * 
 * @since 3.0
 */
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();
    if (timeout == 0) {
        return createSocket(host, port);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        Socket socket = ReflectionSocketFactory.createSocket("javax.net.ssl.SSLSocketFactory", host, port, null,
                0, timeout);
        if (socket == null) {
            socket = ControllerThreadSocketFactory.createSocket(this, host, port, null, 0, timeout);
        }
        return socket;
    }
}

From source file:nl.nn.adapterframework.http.AuthSSLProtocolSocketFactory.java

/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>/*from   ww  w . ja v a2s  .  co  m*/
 * This method employs several techniques to circumvent the limitations of older JREs that 
 * do not support connect timeout. When running in JRE 1.4 or above reflection is used to 
 * call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older 
 * JREs a controller thread is executed. The controller thread attempts to create a new socket
 * within the given limit of time. If socket constructor does not return until the timeout 
 * expires, the controller terminates and throws an {@link ConnectTimeoutException}
 * </p>
 *  
 * @param host the host name/IP
 * @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
 * 
 * @author Copied from HttpClient 3.0.1 SSLProtocolSocketFactory
 * @since 3.0
 */
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();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    }
    // To be eventually deprecated when migrated to Java 1.4 or above
    Socket socket = ReflectionSocketFactory.createSocket("javax.net.ssl.SSLSocketFactory", host, port,
            localAddress, localPort, timeout);
    if (socket == null) {
        socket = ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
    return socket;
}

From source file:org.archive.wayback.liveweb.DNSTimingProtocolSocketFactory.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");
    }/*from  w  w  w .  j  a v a 2 s .  co m*/
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        Socket socket = ReflectionSocketFactory.createSocket("javax.net.SocketFactory", host, port,
                localAddress, localPort, timeout);
        if (socket == null) {
            socket = ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort,
                    timeout);
        }
        return socket;
    }
}

From source file:test.MyProtocolSocketFactory.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");
    }//from   w w  w .ja  va 2 s  .c om
    int timeout = params.getConnectionTimeout();

    // localPort????
    int controlledLocalPort = autoAllocate(localPort) ? getAvailableLocalPort() : localPort;

    if (timeout == 0) {
        return createSocket(host, port, localAddress, controlledLocalPort);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        Socket socket = ReflectionSocketFactory.createSocket("javax.net.SocketFactory", host, port,
                localAddress, controlledLocalPort, timeout);
        if (socket == null) {
            socket = ControllerThreadSocketFactory.createSocket(this, host, port, localAddress,
                    controlledLocalPort, timeout);
        }
        return socket;
    }
}