当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientContext.getRequest方法代码示例

本文整理汇总了Java中org.apache.http.client.protocol.HttpClientContext.getRequest方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientContext.getRequest方法的具体用法?Java HttpClientContext.getRequest怎么用?Java HttpClientContext.getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.protocol.HttpClientContext的用法示例。


在下文中一共展示了HttpClientContext.getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的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: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的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

示例3: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的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

示例4: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
/**
 * 自定义的恢复策略
 */
public boolean retryRequest(IOException exception, int exceptionCount,
		HttpContext context) {
	if (exceptionCount >= 3)
		return false;
	if (exception instanceof InterruptedIOException) {
		return false;
	}
	if (exception instanceof UnknownHostException) {
		return false;
	}
	if (exception instanceof ConnectTimeoutException) {
		return false;
	}
	if (exception instanceof SSLException) {
		return false;
	}
	HttpClientContext clientContext = HttpClientContext.adapt(context);
	HttpRequest request = clientContext.getRequest();
	boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
	if (idempotent) {
		return true;
	}
	return false;
}
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:28,代码来源:HttpConnectionManager.java

示例5: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
/**
 * Used <code>retryCount</code> and <code>requestSentRetryEnabled</code> to determine
 * if the given method should be retried.
 */
public boolean retryRequest(
        final IOException exception,
        final int executionCount,
        final HttpContext context) {
    Args.notNull(exception, "Exception parameter");
    Args.notNull(context, "HTTP context");
    if (executionCount > this.retryCount) {
        // Do not retry if over max retry count
        return false;
    }
    if (this.nonRetriableClasses.contains(exception.getClass())) {
        return false;
    } else {
        for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
            if (rejectException.isInstance(exception)) {
                return false;
            }
        }
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final HttpRequest request = clientContext.getRequest();

    if(requestIsAborted(request)){
        return false;
    }

    if (handleAsIdempotent(request)) {
        // Retry if the request is considered idempotent
        return true;
    }

    if (!clientContext.isRequestSent() || this.requestSentRetryEnabled) {
        // Retry if the request has not been sent fully or
        // if it's OK to retry methods that have been sent
        return true;
    }
    // otherwise do not retry
    return false;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:44,代码来源:DefaultHttpRequestRetryHandlerHC4.java

示例6: testPostNoRedirect

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testPostNoRedirect() throws Exception {
    this.serverBootstrap.registerHandler("*", new BasicRedirectService());

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpPost httppost = new HttpPost("/oldlocation/");
    httppost.setEntity(new StringEntity("stuff"));

    final HttpResponse response = this.httpclient.execute(target, httppost, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();

    Assert.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals("POST", reqWrapper.getRequestLine().getMethod());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestRedirects.java

示例7: testRelativeRedirect2

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testRelativeRedirect2() throws Exception {
    this.serverBootstrap.registerHandler("*", new RelativeRedirectService2());

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
    final HttpGet httpget = new HttpGet("/test/oldlocation");
    httpget.setConfig(config);

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/test/relativelocation", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(host, target);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRedirects.java

示例8: testRelativeRequestURIWithFragment

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testRelativeRequestURIWithFragment() throws Exception {
    this.serverBootstrap.registerHandler("*", new SimpleService());

    final HttpHost target = start();

    final HttpGet httpget = new HttpGet("/stuff#blahblah");
    final HttpClientContext context = HttpClientContext.create();

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());

    final HttpRequest request = context.getRequest();
    Assert.assertEquals("/stuff", request.getRequestLine().getUri());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestClientRequestExecution.java

示例9: testRelativeRedirect

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testRelativeRedirect() throws Exception {
    this.serverBootstrap.registerHandler("*", new RelativeRedirectService());

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
    final HttpGet httpget = new HttpGet("/oldlocation/");
    httpget.setConfig(config);

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/relativelocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(host, target);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRedirects.java

示例10: testBasicRedirect302

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testBasicRedirect302() throws Exception {
    this.serverBootstrap.registerHandler("*",
            new BasicRedirectService(HttpStatus.SC_MOVED_TEMPORARILY));

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpGet httpget = new HttpGet("/oldlocation/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(target, host);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestRedirects.java

示例11: testBasicRedirect303

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testBasicRedirect303() throws Exception {
    this.serverBootstrap.registerHandler("*",
            new BasicRedirectService(HttpStatus.SC_SEE_OTHER));

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpGet httpget = new HttpGet("/oldlocation/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(target, host);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestRedirects.java

示例12: testBasicRedirect305

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testBasicRedirect305() throws Exception {
    this.serverBootstrap.registerHandler("*",
            new BasicRedirectService(HttpStatus.SC_USE_PROXY));
    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpGet httpget = new HttpGet("/oldlocation/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();

    Assert.assertEquals(HttpStatus.SC_USE_PROXY, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:TestRedirects.java

示例13: testBasicRedirect307

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testBasicRedirect307() throws Exception {
    this.serverBootstrap.registerHandler("*",
            new BasicRedirectService(HttpStatus.SC_TEMPORARY_REDIRECT));

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();

    final HttpGet httpget = new HttpGet("/oldlocation/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    EntityUtils.consume(response.getEntity());

    final HttpRequest reqWrapper = context.getRequest();
    final HttpHost host = context.getTargetHost();

    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
    Assert.assertEquals(target, host);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestRedirects.java

示例14: createHttpClient

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private static CloseableHttpClient createHttpClient(int maxTotal, int maxPerRoute, int maxRoute, String hostname, int port) {
    ConnectionSocketFactory plainsf = PlainConnectionSocketFactory
            .getSocketFactory();
    LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory
            .getSocketFactory();
    Registry<ConnectionSocketFactory> registry = RegistryBuilder
            .<ConnectionSocketFactory>create()
            .register("http", plainsf)
            .register("https", sslsf)
            .build();

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
            registry);

    // 将最大连接数增加
    cm.setMaxTotal(maxTotal);
    // 将每个路由基础的连接增加
    cm.setDefaultMaxPerRoute(maxPerRoute);

    // 将目标主机的最大连接数增加
    HttpHost httpHost = new HttpHost(hostname, port);
    cm.setMaxPerRoute(new HttpRoute(httpHost), maxRoute);

    // 请求重试处理
    HttpRequestRetryHandler httpRequestRetryHandler = (exception, executionCount, context) -> {
        if (executionCount >= 5) {// 如果已经重试了5次,就放弃
            return false;
        }
        if (exception instanceof NoHttpResponseException) {// 如果服务器丢掉了连接,那么就重试
            return true;
        }
        if (exception instanceof SSLHandshakeException) {// 不要重试SSL握手异常
            return false;
        }
        if (exception instanceof InterruptedIOException) {// 超时
            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;
    };

    CloseableHttpClient httpClient = HttpClients.custom()
            .setConnectionManager(cm)
            .setRetryHandler(httpRequestRetryHandler)
            .build();

    return httpClient;
}
 
开发者ID:Evan1120,项目名称:wechat-api-java,代码行数:64,代码来源:HttpRequestUtil.java

示例15: retryRequest

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
  public boolean retryRequest(
          IOException exception,
          int executionCount,
          HttpContext context) {
if (executionCount > retryExecutionCount) {
          return false;
      }
      if (exception instanceof InterruptedIOException) {
          return false;
      }
      if (exception instanceof UnknownHostException) {
          return false;
      }
      if (exception instanceof ConnectTimeoutException) {
          return true;
      }
      if (exception instanceof SSLException) {
          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:luotuo,项目名称:springboot-security-wechat,代码行数:30,代码来源:HttpClientFactory.java


注:本文中的org.apache.http.client.protocol.HttpClientContext.getRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。