当前位置: 首页>>代码示例>>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;未经允许,请勿转载。