类org.apache.commons.httpclient.ConnectTimeoutException源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.ConnectTimeoutException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: freeacs   文件: EasySSLProtocolSocketFactory.java
/**
 * 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}
 *
 * @param host the host name/IP
 * @param port the port on the host
 * @param localAddress the local address
 * @param localPort the local port
 * @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 the connect timeout exception
 */
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;
  }
}
 
源代码2 项目: Cirrus_depricated   文件: ErrorMessageAdapter.java
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;
    }
 
源代码3 项目: http4e   文件: AuthSSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
源代码4 项目: http4e   文件: SocketFactoryWrapper.java
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;
}
 
源代码5 项目: http4e   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
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;
}
 
/**
 * 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}
 *
 * @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;
    }
}
 
源代码8 项目: sakai   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
源代码9 项目: sakai   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
源代码10 项目: elasticsearch-hadoop   文件: SocksSocketFactory.java
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;
}
 
源代码11 项目: elasticsearch-hadoop   文件: SSLSocketFactory.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");
    }
    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;
    }
}
 
源代码12 项目: http4e   文件: StrictSSLProtocolSocketFactory.java
/**
 * 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;
}
 
/**
 * This method spawns a controller thread overseeing the process of socket 
 * initialisation. If the socket constructor cannot be created within the specified time
 * limit, the controller terminates and throws an {@link ConnectTimeoutException}
 * 
 * @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 timeout the timeout value to be used in milliseconds. If the socket cannot be
 *        completed within the given time limit, it will be abandoned
 * 
 * @return a connected 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 if socket cannot be connected within the
 *  given time limit
 * 
 */
public static Socket createSocket(
    final ProtocolSocketFactory socketfactory, 
    final String host,
    final int port,
    final InetAddress localAddress,
    final int localPort,
    int timeout)
 throws IOException, UnknownHostException, ConnectTimeoutException
{
        SocketTask task = new SocketTask() {
            public void doit() throws IOException {
                setSocket(socketfactory.createSocket(host, port, localAddress, localPort));
            }                 
        };
        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;
}
 
源代码14 项目: egdownloader   文件: WebClient.java
public static InputStream postRequestAsStream(String url) throws ConnectTimeoutException, SocketTimeoutException{
	try {
		return postRequestAsStreamWithCookie(url, "utf-8", null, null);
	} catch (WebClientException e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码15 项目: egdownloader   文件: WebClient.java
public static InputStream postRequestAsStream(String url, String encoding) throws ConnectTimeoutException, SocketTimeoutException{
	try {
		return postRequestAsStreamWithCookie(url, encoding, null, null);
	} catch (WebClientException e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码16 项目: egdownloader   文件: WebClient.java
public static InputStream postRequestAsStreamWithCookie(String url, String cookieInfo) throws ConnectTimeoutException, SocketTimeoutException{
	try {
		return postRequestAsStreamWithCookie(url, "utf-8", null, cookieInfo);
	} catch (WebClientException e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码17 项目: egdownloader   文件: ScriptParser.java
/**
 * 收集图片
 * @return List<Picture>
 */
private static List<Picture> collectpictrues(String source, Setting setting) throws ConnectTimeoutException, SocketTimeoutException, SpiderException, FileNotFoundException, ScriptException{
	Map<String, Object> param = new HashMap<String, Object>();
	param.put("htmlSource", source);
	
	Object o = parseJsScript(param, getCollectScriptFile(setting.getCollectPictureScriptPath()));
	if(o == null){
		Tracker.println(ScriptParser.class, setting.getCollectPictureScriptPath() + "脚本解析错误");
	}
	return JsonUtil.jsonArray2beanList(Picture.class, o.toString());
}
 
源代码18 项目: egdownloader   文件: ScriptParser.java
/**
 * 搜索漫画列表,第一个元素为分页信息字符串,格式为 count,pageCount;
 * 第二个元素为漫画列表JSON字符串
 */
public static String[] search(String source, Setting setting, boolean first) throws ConnectTimeoutException, SocketTimeoutException, FileNotFoundException, ScriptException{
	Map<String, Object> param = new HashMap<String, Object>();
	param.put("htmlSource", source);
	
	Object result = parseJsScript(param, getSearchScriptFile(first ? setting.getSearchScriptPath() : setting.getSearchScriptPath2()));
	return result == null ? null : result.toString().split("\\###");
}
 
源代码19 项目: egdownloader   文件: LoginWindow.java
public static void main(String[] args) throws ConnectTimeoutException, SocketTimeoutException, WebClientException {
	Map<String, String> params = new HashMap<String, String>();
	params.put("referer", "http://forums.e-hentai.org/index.php");
	params.put("b", "");
	params.put("bt", "");
	params.put("UserName", "username");
	params.put("PassWord", "******");//
	params.put("CookieDate", "1");
	String cookieInfo = WebClient.getCookieByPostWithoutCookie("https://forums.e-hentai.org/index.php?act=Login&CODE=01",
			"UTF-8", params); 
	System.out.println(cookieInfo);
	cookieInfo = WebClient.getCookieByPostWithCookie("http://exhentai.org/", "UTF-8", null, cookieInfo);
	System.out.println(cookieInfo);
}
 
源代码20 项目: cloudstack   文件: TrustingProtocolSocketFactory.java
@Override
public Socket createSocket(String host, int port, InetAddress localAddress,
        int localPort, HttpConnectionParams params) throws IOException,
        UnknownHostException, ConnectTimeoutException {
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    }
    else {
        Socket s = ssf.createSocket();
        s.bind(new InetSocketAddress(localAddress, localPort));
        s.connect(new InetSocketAddress(host, port), timeout);
        return s;
    }
}
 
源代码21 项目: openemm   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
	}
}
 
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException
{
    // TODO Auto-generated method stub
    return null;
}
 
/**
 * 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
 * @throws ConnectTimeoutException if socket cannot be connected within the
 *  given time limit
 * 
 * @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);
    } 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;
    }
}
 
/**
 * 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
 * 
 * @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);
    } else {
        // 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;
    }
}
 
源代码25 项目: olat   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
源代码26 项目: olat   文件: EasySSLProtocolSocketFactory.java
/**
 * 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;
    }
}
 
源代码27 项目: egdownloader   文件: WebClient.java
public static String postRequest(String url) throws ConnectTimeoutException, SocketTimeoutException, WebClientException{
	return postRequestWithCookie(url, "utf-8", null, null);
}
 
源代码28 项目: egdownloader   文件: WebClient.java
public static String postRequest(String url, String encoding) throws ConnectTimeoutException, SocketTimeoutException, WebClientException{
	return postRequestWithCookie(url, encoding, null, null);
}
 
源代码29 项目: egdownloader   文件: WebClient.java
public static String postRequestWithCookie(String url, String cookieInfo) throws ConnectTimeoutException, SocketTimeoutException, WebClientException{
	return postRequestWithCookie(url, "utf-8", null, cookieInfo);
}
 
源代码30 项目: egdownloader   文件: WebClient.java
public static String postRequestWithCookie(String url, String encoding, Map<String, String> rawParams, String cookieInfo) throws WebClientException, ConnectTimeoutException, SocketTimeoutException {
	return postRequestWithCookie( url,  encoding,  rawParams, cookieInfo, true);
}
 
 类方法
 同包方法