org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory Java Examples

The following examples show how to use org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EasySSLProtocolSocketFactory.java    From flex-blazeds with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>
 * To circumvent the limitations of older JREs that do not support connect timeout 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
 */
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");
    }
    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
        return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
}
 
Example #2
Source File: EasySSLProtocolSocketFactory.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Attempts to get a new socket connection to the given host within the given time limit.
    * <p/>
    * To circumvent the limitations of older JREs that do not support connect timeout 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 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 {
       if (params == null) {
           throw new IllegalArgumentException("Parameters may not be null");
       }
       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
           return ControllerThreadSocketFactory.createSocket(
                   this, host, port, localAddress, localPort, timeout);
       }
   }
 
Example #3
Source File: AuthSSLProtocolSocketFactoryForJsse10x.java    From iaf with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>
 * 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
 * 
 * Copied from HttpClient 3.0.1 SSLProtocolSocketFactory
 */
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;
}
 
Example #4
Source File: AuthSSLProtocolSocketFactory.java    From iaf with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the given time limit.
 * <p>
 * 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
 * 
 * Copied from HttpClient 3.0.1 SSLProtocolSocketFactory
 */
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;
}
 
Example #5
Source File: DefaultSslProtocolSocketFactory.java    From kylin-on-parquet-v2 with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the
 * given time limit.
 * 
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 * @throws ConnectTimeoutException
 *             DOCUMENT ME!
 * @throws IllegalArgumentException
 *             DOCUMENT ME!
 */
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);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
}
 
Example #6
Source File: DummySSLProtocolSocketFactory.java    From anthelion with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the given
 * time limit.
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 */
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);
  } else {
    // To be eventually deprecated when migrated to Java 1.4 or above
    return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
  }
}
 
Example #7
Source File: DefaultSslProtocolSocketFactory.java    From kylin with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the
 * given time limit.
 * 
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 * @throws ConnectTimeoutException
 *             DOCUMENT ME!
 * @throws IllegalArgumentException
 *             DOCUMENT ME!
 */
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);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
}
 
Example #8
Source File: DefaultSslProtocolSocketFactory.java    From Kylin with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the
 * given time limit.
 * 
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 * @throws ConnectTimeoutException
 *             DOCUMENT ME!
 * @throws IllegalArgumentException
 *             DOCUMENT ME!
 */
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);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
}
 
Example #9
Source File: DefaultSslProtocolSocketFactory.java    From Kylin with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the
 * given time limit.
 * 
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 * @throws ConnectTimeoutException
 *             DOCUMENT ME!
 * @throws IllegalArgumentException
 *             DOCUMENT ME!
 */
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);
    } else {
        // To be eventually deprecated when migrated to Java 1.4 or above
        return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
    }
}
 
Example #10
Source File: DummySSLProtocolSocketFactory.java    From nutch-htmlunit with Apache License 2.0 3 votes vote down vote up
/**
 * Attempts to get a new socket connection to the given host within the given
 * time limit.
 * <p>
 * To circumvent the limitations of older JREs that do not support connect
 * timeout 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
 */
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);
  } else {
    // To be eventually deprecated when migrated to Java 1.4 or above
    return ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
  }
}