本文整理匯總了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;
}
示例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;
}
示例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;
}
});
}
示例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;
}
示例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;
}
示例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);
});
}
}
示例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"));
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}