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


Java NoHttpResponseException類代碼示例

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


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

示例1: retryRequest

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Decide about retry #" + executionCount + " for exception " + exception.getMessage());
    }

    if (executionCount >= _maxRetryCount) {
        // Do not retry if over max retry count
        return false;
    } else if (exception instanceof NoHttpResponseException) {
        // Retry if the server dropped connection on us
        return true;
    } else if (exception instanceof SSLHandshakeException) {
        // Do not retry on SSL handshake exception
        return false;
    }

    HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
    boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
    // Retry if the request is considered idempotent
    return idempotent;
}
 
開發者ID:crawler-commons,項目名稱:http-fetcher,代碼行數:23,代碼來源:SimpleHttpFetcher.java

示例2: retryRequest

import org.apache.http.NoHttpResponseException; //導入依賴的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

示例3: HttpEngine

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
private HttpEngine() {
    this.mDefaultHttpClient = null;
    this.mDefaultHttpClient = createHttpClient();
    this.mDefaultHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (DataStatistics.getInstance().isDebug()) {
                Log.d(DataStatistics.TAG, exception.getClass() + NetworkUtils.DELIMITER_COLON + exception.getMessage() + ",executionCount:" + executionCount);
            }
            if (executionCount >= 3) {
                return false;
            }
            if (exception instanceof NoHttpResponseException) {
                return true;
            }
            if (exception instanceof ClientProtocolException) {
                return true;
            }
            return false;
        }
    });
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:HttpEngine.java

示例4: determine

import org.apache.http.NoHttpResponseException; //導入依賴的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

示例5: retryRequest

import org.apache.http.NoHttpResponseException; //導入依賴的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

示例6: findFaultClassifier

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
private String findFaultClassifier(final String id) {
    if (registry.isRegistered(id, FaultClassifier.class)) {
        return generateBeanName(id, FaultClassifier.class);
    } else if (registry.isRegistered(FaultClassifier.class)) {
        return generateBeanName(FaultClassifier.class);
    } else {
        return registry.registerIfAbsent(FaultClassifier.class, () -> {
            final List<Predicate<Throwable>> predicates = list();

            predicates.addAll(FaultClassifier.defaults());
            predicates.add(ConnectionClosedException.class::isInstance);
            predicates.add(NoHttpResponseException.class::isInstance);

            return genericBeanDefinition(FaultClassifier.class)
                    .setFactoryMethod("create")
                    .addConstructorArgValue(predicates);
        });
    }
}
 
開發者ID:zalando,項目名稱:riptide,代碼行數:20,代碼來源:DefaultRiptideRegistrar.java

示例7: testHttpPlainFail

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
@Test
public void testHttpPlainFail() throws Exception {
    thrown.expect(NoHttpResponseException.class);

    enableHTTPClientSSL = false;
    trustHTTPServerCertificate = true;
    sendHTTPClientCertificate = false;

    final Settings settings = Settings.builder().put("searchguard.ssl.transport.enabled", false)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_HTTP_KEYSTORE_ALIAS, "node-0").put("searchguard.ssl.http.enabled", true)
            .put("searchguard.ssl.http.clientauth_mode", "OPTIONAL")
            .put("searchguard.ssl.http.keystore_filepath", getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("searchguard.ssl.http.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks")).build();

    startES(settings);
    Assert.assertTrue(executeSimpleRequest("_searchguard/sslinfo?pretty").length() > 0);
    Assert.assertTrue(executeSimpleRequest("_nodes/settings?pretty").contains(clustername));
    Assert.assertTrue(executeSimpleRequest("_searchguard/sslinfo?pretty").contains("CN=node-0.example.com,OU=SSL,O=Test,L=Test,C=DE"));
}
 
開發者ID:floragunncom,項目名稱:search-guard-ssl,代碼行數:22,代碼來源:SSLTest.java

示例8: resOf

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
protected static int resOf(Exception e) {
    if (e instanceof NoConnectionException || e instanceof ConnectException) {
        return R.string.exception_no_connection;
    }
    if (e instanceof ConnectTimeoutException || e instanceof SocketException
            || e instanceof SocketTimeoutException) {
        return R.string.exception_timeout;
    }
    if (e instanceof NoHttpResponseException || e instanceof FileNotFoundException || e instanceof EOFException
            || e instanceof UnknownHostException || e instanceof SSLException) {
        return R.string.exception_no_response;
    }
    if (e instanceof HttpStatusException) {
        return R.string.exception_http_status;
    }
    if (e instanceof ErrorCodeException) {
        try {
            String name = "exception_" + ((ErrorCodeException) e).getCode();
            return R.string.class.getField(name).getInt(null);
        } catch (Exception ex) {
            return 0;
        }
    }
    return 0;
}
 
開發者ID:wavinsun,項目名稱:MUtils,代碼行數:26,代碼來源:NetExceptionUtil.java

示例9: sendQ

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
private String sendQ(String query, int timeout) throws ClientProtocolException, IOException, NoHttpResponseException {
	logger.trace("Send query (timeout={}): {}", timeout, query);
	
	postReq.setEntity(new StringEntity(query, "UTF-8"));
	postReq.addHeader("content-type", "text/xml");

	final RequestConfig params = RequestConfig.custom()
			.setConnectTimeout(connectTimeout)
			.setSocketTimeout(timeout).build();
	postReq.setConfig(params);

	// Execute POST
	HttpResponse response = client.execute(postReq, IhcConnectionPool
			.getInstance().getHttpContext());

	String resp = EntityUtils.toString(response.getEntity());
	logger.trace("Received response: {}", resp);
	return resp;
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:20,代碼來源:IhcHttpsClient.java

示例10: getHTMLContent

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
public String getHTMLContent(String target) {
	log.info(">>> start get html context from url <" + target + "> <<<");
	get = new HttpGet(target);
	try {
		resp = hc.execute(get);
		if (resp == null) {
			return null;
		}
		if (resp.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK ) {
			entity = resp.getEntity();
			if (entity != null) {
				log.info(">>> end get html context from url <" + target + "> <<<");
				return IOUtils.getString(entity.getContent(), encoding);
			}
		}
		return null;
	} catch (Exception e) {
		if (e instanceof NoHttpResponseException) {
			log.warn("***********  The target server failed to respond  ***********");
			return null;
		}
		log.error("get target " + target + " html content occurrence error", e);
		return null;
	}
}
 
開發者ID:toulezu,項目名稱:play,代碼行數:26,代碼來源:HTMLContentHelper.java

示例11: retryRequest

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
public boolean retryRequest(IOException exception, int executionCount,  
        HttpContext context) {  
    // 設置恢複策略,在發生異常時候將自動重試3次  
    if (executionCount >= 3) {  
        // 如果連接次數超過了最大值則停止重試  
        return false;  
    }  
    if (exception instanceof NoHttpResponseException) {  
        // 如果服務器連接失敗重試  
        return true;  
    }  
    if (exception instanceof SSLHandshakeException) {  
        // 不要重試ssl連接異常  
        return false;  
    }  
    HttpRequest request = (HttpRequest) context  
            .getAttribute(ExecutionContext.HTTP_REQUEST);  
    boolean idempotent = (request instanceof HttpEntityEnclosingRequest);  
    if (!idempotent) {  
        // 重試,如果請求是考慮冪等  
        return true;  
    }  
    return false;  
}
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:25,代碼來源:HttpClientUtil.java

示例12: retryRequest

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
	// 設置恢複策略,在發生異常時候將自動重試errorRetryCount次
	if (executionCount >= errorRetryCount) {
		// Do not retry if over max retry count
		System.out.println("errors");
		return false;
	}
	if (exception instanceof NoHttpResponseException) {
		// Retry if the server dropped connection on us
		return true;
	}
	if (exception instanceof SSLHandshakeException) {
		// Do not retry on SSL handshake exception
		return false;
	}
	HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
	boolean idempotent = (request instanceof HttpEntityEnclosingRequest);
	if (!idempotent) {
		// Retry if the request is considered idempotent
		return true;
	}
	return false;
}
 
開發者ID:hxt168,項目名稱:webpasser,代碼行數:24,代碼來源:HttpclientUtil.java

示例13: testHttpsOnly

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
@Test(expected = NoHttpResponseException.class)
public void testHttpsOnly() throws Exception {
  TestMetricsReporter.reset();
  Properties props = new Properties();
  String uri = "https://localhost:8080";
  props.put(RestConfig.LISTENERS_CONFIG, uri);
  props.put(RestConfig.METRICS_REPORTER_CLASSES_CONFIG, "io.confluent.rest.TestMetricsReporter");
  configServerKeystore(props);
  TestRestConfig config = new TestRestConfig(props);
  SslTestApplication app = new SslTestApplication(config);
  try {
    app.start();

    int statusCode = makeGetRequest(uri + "/test",
                                    clientKeystore.getAbsolutePath(), SSL_PASSWORD, SSL_PASSWORD);
    assertEquals(EXPECTED_200_MSG, 200, statusCode);
    assertMetricsCollected();
    makeGetRequest("http://localhost:8080/test");
  } finally {
    app.stop();
  }
}
 
開發者ID:confluentinc,項目名稱:rest-utils,代碼行數:23,代碼來源:SslTest.java

示例14: sendQ

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
private String sendQ(String query, int timeout)
        throws ClientProtocolException, IOException, NoHttpResponseException {
    logger.trace("Send query (timeout={}): {}", timeout, query);

    postReq.setEntity(new StringEntity(query, "UTF-8"));
    postReq.addHeader("content-type", "text/xml");

    final RequestConfig params = RequestConfig.custom().setConnectTimeout(connectTimeout).setSocketTimeout(timeout)
            .build();
    postReq.setConfig(params);

    // Execute POST
    HttpResponse response = client.execute(postReq, IhcConnectionPool.getInstance().getHttpContext());

    String resp = EntityUtils.toString(response.getEntity());
    logger.trace("Received response: {}", resp);
    return resp;
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:19,代碼來源:IhcHttpsClient.java

示例15: shouldRetry

import org.apache.http.NoHttpResponseException; //導入依賴的package包/類
private boolean shouldRetry(RequestMessage request, Exception exception, int statusCode, int retries)
{
  if (retries >= this.config.getMaxErrorRetry()) {
    return false;
  }
  
  if (!request.isRepeatable()) {
    return false;
  }
  
  if (((exception instanceof SocketException)) || ((exception instanceof SocketTimeoutException)) || ((exception instanceof NoHttpResponseException)))
  {
    log.debug("Retrying on " + exception.getClass().getName() + ": " + exception.getMessage());
    
    return true;
  }
  
  if ((statusCode == 500) || (statusCode == 503))
  {
    log.debug("Retrying on " + exception.getClass().getName() + ": " + exception.getMessage());
    
    return true;
  }
  
  return false;
}
 
開發者ID:kloudkl,項目名稱:aliyun_ecs_java_sdk,代碼行數:27,代碼來源:ServiceClient.java


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