當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectTimeoutException類代碼示例

本文整理匯總了Java中org.apache.http.conn.ConnectTimeoutException的典型用法代碼示例。如果您正苦於以下問題:Java ConnectTimeoutException類的具體用法?Java ConnectTimeoutException怎麽用?Java ConnectTimeoutException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectTimeoutException類屬於org.apache.http.conn包,在下文中一共展示了ConnectTimeoutException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retryRequest

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    if (executionCount >= 5) {// 如果已經重試了5次,就放棄
        return false;
    }
    if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
        return true;
    }
    if (exception instanceof InterruptedIOException) {// 超時
        return false;
    }
    if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
        return false;
    }
    if (exception instanceof UnknownHostException) {// 目標服務器不可達
        return false;
    }
    if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
        return false;
    }
    if (exception instanceof SSLException) {// SSL握手異常
        return false;
    }
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    HttpRequest request = clientContext.getRequest();
    // 如果請求是冪等的,就再次嘗試
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return true;
    }
    return false;
}
 
開發者ID:adealjason,項目名稱:dtsopensource,代碼行數:32,代碼來源:HttpProtocolParent.java

示例2: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Override
public Socket connectSocket(
        final int connectTimeout,
        final Socket socket, final HttpHost host,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpContext context
) throws IOException {
    Socket socket0 = socket != null ? socket : createSocket(context);
    if (localAddress != null) {
        socket0.bind(localAddress);
    }
    try {
        socket0.connect(remoteAddress, connectTimeout);
    } catch (SocketTimeoutException e) {
        throw new ConnectTimeoutException(e, host, remoteAddress.getAddress());
    }
    return socket0;
}
 
開發者ID:ZhangJiupeng,項目名稱:Gospy,代碼行數:20,代碼來源:HttpFetcher.java

示例3: determine

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Override
public Type determine(final BackgroundException failure) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Determine cause for failure %s", failure));
    }
    if(failure instanceof ConnectionTimeoutException) {
        return Type.network;
    }
    if(failure instanceof ConnectionRefusedException) {
        return Type.network;
    }
    if(failure instanceof ResolveFailedException) {
        return Type.network;
    }
    if(failure instanceof SSLNegotiateException) {
        return Type.application;
    }
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(cause instanceof SSLException) {
            return Type.network;
        }
        if(cause instanceof NoHttpResponseException) {
            return Type.network;
        }
        if(cause instanceof ConnectTimeoutException) {
            return Type.network;
        }
        if(cause instanceof SocketException
                || cause instanceof TimeoutException // Used in Promise#retrieve
                || cause instanceof SocketTimeoutException
                || cause instanceof UnknownHostException) {
            return Type.network;
        }
    }
    return Type.application;
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:37,代碼來源:DefaultFailureDiagnostics.java

示例4: retryRequest

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

    if (executionCount >= 3) {// 如果已經重試了3次,就放棄
        return false;
    }

    if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
        return true;
    }

    if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
        return false;
    }

    if (exception instanceof InterruptedIOException) {// 超時
        return true;
    }

    if (exception instanceof UnknownHostException) {// 目標服務器不可達
        return false;
    }

    if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
        return false;
    }

    if (exception instanceof SSLException) {// ssl握手異常
        return false;
    }

    HttpClientContext clientContext = HttpClientContext.adapt(context);
    HttpRequest request = clientContext.getRequest();

    // 如果請求是冪等的,就再次嘗試
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return true;
    }
    return false;
}
 
開發者ID:fengzhizi715,項目名稱:PicCrawler,代碼行數:41,代碼來源:RetryHandler.java

示例5: getErrorTip

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@NonNull
protected String getErrorTip(@NonNull Throwable error) {
    String errorTip = null;
    if(error == null){
        return errorTip;
    }
    if(error instanceof UnknownHostException){
        errorTip = getString(R.string.no_network_tip);
    } else if (error instanceof SocketTimeoutException || error instanceof ConnectTimeoutException) {
        errorTip = getString(R.string.load_timeout_tip);
    } else if (error instanceof HttpError) {
        errorTip = error.getMessage();
    } else {
        errorTip = StringUtils.isBlank(error.getMessage()) ? error.toString() : error.getMessage();
    }
    return errorTip;
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:18,代碼來源:BasePresenter.java

示例6: testSslHandshakeTimeout

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Test(timeout = 60 * 1000)
public void testSslHandshakeTimeout() {
    AmazonHttpClient httpClient = new AmazonHttpClient(new ClientConfiguration()
            .withSocketTimeout(CLIENT_SOCKET_TO).withMaxErrorRetry(0));

    System.out.println("Sending request to localhost...");

    try {
        httpClient.requestExecutionBuilder()
                .request(new EmptyHttpRequest(server.getHttpsEndpoint(), HttpMethodName.GET))
                .execute();
        fail("Client-side socket read timeout is expected!");

    } catch (AmazonClientException e) {
        /**
         * Http client catches the SocketTimeoutException and throws a
         * ConnectTimeoutException.
         * {@link org.apache.http.impl.conn.DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost, InetSocketAddress, int, SocketConfig, HttpContext)}
         */
        Assert.assertTrue(e.getCause() instanceof ConnectTimeoutException);

        ConnectTimeoutException cte = (ConnectTimeoutException) e.getCause();
        Assert.assertThat(cte.getMessage(), org.hamcrest.Matchers
                .containsString("Read timed out"));
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:27,代碼來源:AmazonHttpClientSslHandshakeTimeoutIntegrationTest.java

示例7: getErrorCommonResponse

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * 根據Volley錯誤對象返回CommonResponse對象並寫入錯誤信息.
 *
 * @param error Volley錯誤對象
 * @return 返回CommonResponse對象並寫入錯誤信息s
 */
private static CommonResponse getErrorCommonResponse(VolleyError error) {
    CommonResponse response = null;
    Throwable cause = error.getCause();
    if (cause == null) {
        cause = error;
    }
    if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum._404);
    } else if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof ConnectTimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof TimeoutError) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof UnknownHostException) {
        response = new CommonResponse(CodeEnum.UNKNOWN_HOST);
    } else if (cause instanceof IOException) {
        response = new CommonResponse(CodeEnum.NETWORK_EXCEPTION);
    } else {
        response = new CommonResponse(CodeEnum.EXCEPTION.getCode(), cause.getLocalizedMessage());
    }
    return response;
}
 
開發者ID:tengbinlive,項目名稱:ooooim_android,代碼行數:30,代碼來源:CommonRequest.java

示例8: retryRequest

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
public boolean retryRequest(
        IOException exception,
        int executionCount,
        HttpContext context) {
    if (executionCount >= 5) {
        // Do not retry if over max retry count
        return false;
    }
    if (exception instanceof InterruptedIOException) {
        // Timeout
        return false;
    }
    if (exception instanceof UnknownHostException) {
        // Unknown host
        return false;
    }
    if (exception instanceof ConnectTimeoutException) {
        // Connection refused
        return false;
    }
    if (exception instanceof SSLException) {
        // SSL handshake exception
        return false;
    }
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    HttpRequest request = clientContext.getRequest();
    boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
    if (idempotent) {
        // Retry if the request is considered idempotent
        return true;
    }
    return false;
}
 
開發者ID:NOAA-PMEL,項目名稱:LAS,代碼行數:34,代碼來源:LASProxy.java

示例9: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * @see SocketFactory#connectSocket(Socket, String, int,
 *      InetAddress, int, HttpParams)
 */
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
		HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
	int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
	int soTimeout = HttpConnectionParams.getSoTimeout(params);
	InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
	SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

	if ((localAddress != null) || (localPort > 0)) {
		// we need to bind explicitly
		if (localPort < 0) {
			localPort = 0; // indicates "any"
		}
		InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
		sslsock.bind(isa);
	}

	sslsock.connect(remoteAddress, connTimeout);
	sslsock.setSoTimeout(soTimeout);
	return sslsock;

}
 
開發者ID:warnerbros,項目名稱:cpe-manifest-android-experience,代碼行數:26,代碼來源:EasySSLSocketFactory.java

示例10: testDelegateConnectionTimeoutException

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Test
public void testDelegateConnectionTimeoutException() throws Exception {
    doThrow(new ClientHandlerException(new ConnectTimeoutException())).when(_delegate).doIt();
    TestInterface service = _serviceFactory.create(_remoteEndPoint);

    try {
        service.doIt();
    } catch (PartitionForwardingException e) {
        assertTrue(e.getCause() instanceof ConnectTimeoutException);
    }

    assertEquals(_metricRegistry.getMeters().get("bv.emodb.web.partition-forwarding.TestInterface.errors").getCount(), 1);

    verify(_delegateServiceFactory).create(_remoteEndPoint);
    verify(_delegate).doIt();

}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:18,代碼來源:PartitionAwareServiceFactoryTest.java

示例11: getErrorCommonResponse

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * 根據Volley錯誤對象返回CommonResponse對象並寫入錯誤信息.
 *
 * @param error Volley錯誤對象
 * @return 返回CommonResponse對象並寫入錯誤信息s
 */
private static CommonResponse getErrorCommonResponse(VolleyError error) {
    CommonResponse response;
    Throwable cause = error.getCause();
    if (cause == null) {
        cause = error;
    }
    if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum._404);
    } else if (cause instanceof ConnectTimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof TimeoutError) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof UnknownHostException) {
        response = new CommonResponse(CodeEnum.UNKNOWN_HOST);
    } else if (cause instanceof IOException) {
        response = new CommonResponse(CodeEnum.NETWORK_EXCEPTION);
    } else {
        response = new CommonResponse(CodeEnum.EXCEPTION.getCode(), cause.getLocalizedMessage());
    }
    return response;
}
 
開發者ID:tengbinlive,項目名稱:aibao_demo,代碼行數:28,代碼來源:CommonRequest.java

示例12: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
 *      java.lang.String, int, java.net.InetAddress, int,
 *      org.apache.http.params.HttpParams)
 */
public Socket connectSocket(Socket sock, String host, int port,
                InetAddress localAddress, int localPort, HttpParams params)
                throws IOException, UnknownHostException, ConnectTimeoutException {
        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);

        InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
        SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

        if ((localAddress != null) || (localPort > 0)) {
                // we need to bind explicitly
                if (localPort < 0) {
                        localPort = 0; // indicates "any"
                }
                InetSocketAddress isa = new InetSocketAddress(localAddress,
                                localPort);
                sslsock.bind(isa);
        }

        sslsock.connect(remoteAddress, connTimeout);
        sslsock.setSoTimeout(soTimeout);
        return sslsock;

}
 
開發者ID:codedavid,項目名稱:PanoramaGL,代碼行數:30,代碼來源:EasySSLSocketFactory.java

示例13: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
@Override
public Socket connectSocket(
        final int connectTimeout,
        final Socket socket,
        final HttpHost host,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpContext context) throws IOException, ConnectTimeoutException {
    Socket sock;
    if (socket != null) {
        sock = socket;
    } else {
        sock = createSocket(context);
    }
    if (localAddress != null) {
        sock.bind(localAddress);
    }
    try {
        sock.connect(remoteAddress, connectTimeout);
    } catch (SocketTimeoutException ex) {
        throw new ConnectTimeoutException(ex, host, remoteAddress.getAddress());
    }
    return sock;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:ClientExecuteSOCKS.java

示例14: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * @deprecated (4.1)  Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
 */
@Override
@Deprecated
public Socket connectSocket(
        final Socket socket,
        final String host, final int port,
        final InetAddress localAddress, final int localPort,
        final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    InetSocketAddress local = null;
    if (localAddress != null || localPort > 0) {
        local = new InetSocketAddress(localAddress, localPort > 0 ? localPort : 0);
    }
    final InetAddress remoteAddress;
    if (this.nameResolver != null) {
        remoteAddress = this.nameResolver.resolve(host);
    } else {
        remoteAddress = InetAddress.getByName(host);
    }
    final InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
    return connectSocket(socket, remote, local, params);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:PlainSocketFactory.java

示例15: connectSocket

import org.apache.http.conn.ConnectTimeoutException; //導入依賴的package包/類
/**
 * @since 4.1
 */
@Override
public Socket connectSocket(
        final Socket socket,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    Args.notNull(remoteAddress, "Remote address");
    Args.notNull(params, "HTTP parameters");
    final HttpHost host;
    if (remoteAddress instanceof HttpInetSocketAddress) {
        host = ((HttpInetSocketAddress) remoteAddress).getHttpHost();
    } else {
        host = new HttpHost(remoteAddress.getHostName(), remoteAddress.getPort(), "https");
    }
    final int socketTimeout = HttpConnectionParams.getSoTimeout(params);
    final int connectTimeout = HttpConnectionParams.getConnectionTimeout(params);
    socket.setSoTimeout(socketTimeout);
    return connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, null);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:SSLSocketFactory.java


注:本文中的org.apache.http.conn.ConnectTimeoutException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。