当前位置: 首页>>代码示例>>Java>>正文


Java ConnectTimeoutException类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.ConnectTimeoutException的典型用法代码示例。如果您正苦于以下问题:Java ConnectTimeoutException类的具体用法?Java ConnectTimeoutException怎么用?Java ConnectTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectTimeoutException类属于org.apache.commons.httpclient包,在下文中一共展示了ConnectTimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
/**
 * 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 clientHost the local host name/IP to bind the socket to
 * @param clientPort 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();
    Socket socket = null;
    
    SocketFactory socketfactory = SSLSocketFactory.getDefault();
    if (timeout == 0) {
        socket = socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        socket = socketfactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        socket.bind(localaddr);
        socket.connect(remoteaddr, timeout);
    }
    verifyHostname((SSLSocket)socket);
    return socket;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:50,代码来源:StrictSSLProtocolSocketFactory.java

示例2: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
/**
 * 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 clientHost the local host name/IP to bind the socket to
 * @param clientPort 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();
    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;
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:45,代码来源:AuthSSLProtocolSocketFactory.java

示例3: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
/**
 * 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 clientHost the local host name/IP to bind the socket to
 * @param clientPort 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();
	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;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:46,代码来源:EasySSLProtocolSocketFactory.java

示例4: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
public static Socket createSocket(final SocketTask task, int timeout)
 throws IOException, UnknownHostException, ConnectTimeoutException
{
        try {
            TimeoutController.execute(task, timeout);
        } catch (TimeoutController.TimeoutException e) {
            throw new ConnectTimeoutException(
                "The host did not accept the connection within timeout of " 
                + timeout + " ms");
        }
        Socket socket = task.getSocket();
        if (task.exception != null) {
            throw task.exception;
        }
        return socket;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:17,代码来源:ControllerThreadSocketFactory.java

示例5: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
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);
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:SimpleSSLTestProtocolSocketFactory.java

示例6: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
public Socket createSocket(
        String host, 
        int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException,
        ConnectTimeoutException {
    // Based on code from EasySSLProtocolSocketFactory.java
    Socket rval;
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        rval = socketFactory.createSocket(host, port, localAddress, localPort);
    } else {
        rval = socketFactory.createSocket();
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
        rval.bind(localaddr);
        rval.connect(remoteaddr, timeout);
    }
    return rval;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:SocketFactoryWrapper.java

示例7: retryRequest

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
/**
 * 自定义的恢复策略
 */
public boolean retryRequest(IOException exception, int exceptionCount,
		HttpContext context) {
	if (exceptionCount >= 3)
		return false;
	if (exception instanceof InterruptedIOException) {
		return false;
	}
	if (exception instanceof UnknownHostException) {
		return false;
	}
	if (exception instanceof ConnectTimeoutException) {
		return false;
	}
	if (exception instanceof SSLException) {
		return false;
	}
	HttpClientContext clientContext = HttpClientContext.adapt(context);
	HttpRequest request = clientContext.getRequest();
	boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
	if (idempotent) {
		return true;
	}
	return false;
}
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:28,代码来源:HttpConnectionManager.java

示例8: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
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");  
    }  
    int timeout = params.getConnectionTimeout();  
    SocketFactory socketfactory = getSSLContext().getSocketFactory(); //<-----------  
    if (timeout == 0) {  
        return socketfactory.createSocket(host, port, localAddress,  
                localPort);  
    }  
  
    Socket socket = socketfactory.createSocket();  
    SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);  
    SocketAddress remoteaddr = new InetSocketAddress(host, port);  
    socket.bind(localaddr);  
    try {  
        socket.connect(remoteaddr, timeout);  
    } catch (Exception e) {  
        e.printStackTrace();  
        throw new ConnectTimeoutException("Possível timeout de conexão", e);  
    }  
  
    return socket;  
}
 
开发者ID:edigomes,项目名称:nfe-a3-hostapp,代码行数:27,代码来源:SocketFactoryDinamico.java

示例9: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
public Socket createSocket(String remoteHost, int remotePort,
        InetAddress clientHost, int clientPort, 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 getSocketFactory().createSocket(remoteHost, remotePort,
                clientHost, clientPort);
    } else {
        Socket socket = getSocketFactory().createSocket();
        socket.bind(new InetSocketAddress(clientHost, clientPort));
        socket.connect(new InetSocketAddress(remoteHost, remotePort),
                timeout);
        return socket;
    }
}
 
开发者ID:jonico,项目名称:core,代码行数:20,代码来源:SslProtocolSocketFactory.java

示例10: getErrorMessage

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
private static String getErrorMessage(RemoteOperationResult result, Resources res) {

        String message = null;

        if (!result.isSuccess()) {

            if (result.getCode() == ResultCode.WRONG_CONNECTION) {
                message = res.getString(R.string.network_error_socket_exception);

            } else if (result.getCode() == ResultCode.TIMEOUT) {
                message = res.getString(R.string.network_error_socket_exception);

                if (result.getException() instanceof SocketTimeoutException) {
                    message = res.getString(R.string.network_error_socket_timeout_exception);
                } else if (result.getException() instanceof ConnectTimeoutException) {
                    message = res.getString(R.string.network_error_connect_timeout_exception);
                }

            } else if (result.getCode() == ResultCode.HOST_NOT_AVAILABLE) {
                message = res.getString(R.string.network_host_not_available);
            }
        }

        return message;
    }
 
开发者ID:skymania,项目名称:Cirrus,代码行数:26,代码来源:ErrorMessageAdapter.java

示例11: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
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");
	}
	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;
	}
}
 
开发者ID:seagrape,项目名称:kekoa,代码行数:22,代码来源:MySSLSocketFactory.java

示例12: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params)
        throws IOException, UnknownHostException, ConnectTimeoutException {

    InetSocketAddress socksAddr = new InetSocketAddress(socksHost, socksPort);
    Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksAddr);
    int timeout = params.getConnectionTimeout();

    Socket socket = new Socket(proxy);
    socket.setSoTimeout(timeout);

    SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
    SocketAddress remoteaddr = new InetSocketAddress(host, port);
    socket.bind(localaddr);
    socket.connect(remoteaddr, timeout);
    return socket;
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:17,代码来源:SocksSocketFactory.java

示例13: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
@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");
    }
    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;
    }
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:20,代码来源:SSLSocketFactory.java

示例14: createSocket

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
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");  
    }  
    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;  
    }  
}
 
开发者ID:WilleamZhao,项目名称:sourcod,代码行数:22,代码来源:HTTPSSecureProtocolSocketFactory.java

示例15: createTfsExceptionFromThrowable

import org.apache.commons.httpclient.ConnectTimeoutException; //导入依赖的package包/类
@Nullable
private static TfsException createTfsExceptionFromThrowable(Throwable throwable) {
  if (throwable instanceof ConnectException) {
    return new ConnectionFailedException(throwable);
  }
  if (throwable instanceof UnknownHostException) {
    return new HostNotFoundException(throwable);
  }
  if (throwable instanceof NoHttpResponseException) {
    return new HostNotFoundException(throwable);
  }
  if (throwable instanceof SSLHandshakeException) {
    return new SSLConnectionException((SSLHandshakeException)throwable);
  }
  if (throwable instanceof SOAPProcessingException) {
    return new ConnectionFailedException(throwable, TFSBundle.message("invalid.soap.response"));
  }
  if (throwable instanceof SocketException) {
    return new ConnectionFailedException(throwable);
  }
  if (throwable instanceof SocketTimeoutException || throwable instanceof ConnectTimeoutException) {
    return new ConnectionTimeoutException(throwable);
  }
  return null;
}
 
开发者ID:Microsoft,项目名称:vso-intellij,代码行数:26,代码来源:TfsExceptionManager.java


注:本文中的org.apache.commons.httpclient.ConnectTimeoutException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。