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


Java HttpCoreContext类代码示例

本文整理汇总了Java中org.apache.http.protocol.HttpCoreContext的典型用法代码示例。如果您正苦于以下问题:Java HttpCoreContext类的具体用法?Java HttpCoreContext怎么用?Java HttpCoreContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: retryRequest

import org.apache.http.protocol.HttpCoreContext; //导入依赖的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: process

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {

            AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);

            if (authState.getAuthScheme() != null || authState.hasAuthOptions()) {
                return;
            }

            // If no authState has been established and this is a PUT or POST request, add preemptive authorisation
            String requestMethod = request.getRequestLine().getMethod();
            if (alwaysSendAuth || requestMethod.equals(HttpPut.METHOD_NAME) || requestMethod.equals(HttpPost.METHOD_NAME)) {
                CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
                Credentials credentials = credentialsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
                if (credentials == null) {
                    throw new HttpException("No credentials for preemptive authentication");
                }
                authState.update(authScheme, credentials);
            }
        }
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:HttpClientConfigurer.java

示例3: getModSlug0

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Nullable
private String getModSlug0(int id)
{
    try
    {
        log.debug("Getting mod slug from server...");
        URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
        HttpGet request = new HttpGet(uri.toURL().toString());
        HttpContext context = new BasicHttpContext();
        HttpResponse response = http.execute(request, context);
        EntityUtils.consume(response.getEntity());
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
        HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
        String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
        Splitter splitter = Splitter.on('/').omitEmptyStrings();
        List<String> pathParts = splitter.splitToList(currentUrl);
        return pathParts.get(pathParts.size() - 1);
    }
    catch (Exception e)
    {
        log.error("Failed to perform request from CurseForge site.", e);
        return null;
    }
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:25,代码来源:CurseAPI.java

示例4: testSimpleSigner

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testSimpleSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/query?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
}
 
开发者ID:awslabs,项目名称:aws-request-signing-apache-interceptor,代码行数:18,代码来源:AWSRequestSigningApacheInterceptorTest.java

示例5: testEncodedUriSigner

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testEncodedUriSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/foo-2017-02-25%2Cfoo-2017-02-26/_search?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
    assertEquals("/foo-2017-02-25%2Cfoo-2017-02-26/_search", request.getFirstHeader("resourcePath").getValue());
}
 
开发者ID:awslabs,项目名称:aws-request-signing-apache-interceptor,代码行数:19,代码来源:AWSRequestSigningApacheInterceptorTest.java

示例6: retryRequest

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
    if(super.retryRequest(exception, executionCount, context)) {
        final Object attribute = context.getAttribute(HttpCoreContext.HTTP_REQUEST);
        if(attribute instanceof HttpUriRequest) {
            final HttpUriRequest method = (HttpUriRequest) attribute;
            log.warn(String.format("Retrying request %s", method));
            try {
                // Build the authorization string for the method.
                authorizer.authorizeHttpRequest(method, context, null);
                return true;
            }
            catch(ServiceException e) {
                log.warn("Unable to generate updated authorization string for retried request", e);
            }
        }
    }
    return false;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:20,代码来源:S3HttpRequestRetryHandler.java

示例7: keepAlive

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Override
public boolean keepAlive(final HttpResponse response, final HttpContext context) {

    final HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
    if (request != null) {
        final Header[] connHeaders = request.getHeaders(HttpHeaders.CONNECTION);
        if (connHeaders.length != 0) {
            final TokenIterator ti = new BasicTokenIterator(new BasicHeaderIterator(connHeaders, null));
            while (ti.hasNext()) {
                final String token = ti.nextToken();
                if (HTTP.CONN_CLOSE.equalsIgnoreCase(token)) {
                    return false;
                }
            }
        }
    }
    return super.keepAlive(response, context);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:DefaultClientConnectionReuseStrategy.java

示例8: testPreemptiveTargetAndProxyAuth

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testPreemptiveTargetAndProxyAuth() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    authCache.put(this.target, this.authscheme1);
    authCache.put(this.proxy, this.authscheme2);

    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNotNull(this.targetState.getAuthScheme());
    Assert.assertSame(this.creds1, this.targetState.getCredentials());
    Assert.assertNotNull(this.proxyState.getAuthScheme());
    Assert.assertSame(this.creds2, this.proxyState.getCredentials());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:TestRequestAuthCache.java

示例9: testCredentialsProviderNotSet

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testCredentialsProviderNotSet() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, null);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    authCache.put(this.target, this.authscheme1);
    authCache.put(this.proxy, this.authscheme2);

    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:TestRequestAuthCache.java

示例10: testAuthCacheNotSet

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testAuthCacheNotSet() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
    context.setAttribute(HttpClientContext.AUTH_CACHE, null);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestRequestAuthCache.java

示例11: testAuthCacheEmpty

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testAuthCacheEmpty() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestRequestAuthCache.java

示例12: testNoMatchingCredentials

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testNoMatchingCredentials() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    this.credProvider.clear();

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    authCache.put(this.target, this.authscheme1);
    authCache.put(this.proxy, this.authscheme2);

    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestRequestAuthCache.java

示例13: testCookiesForConnectRequest

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testCookiesForConnectRequest() throws Exception {
    final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(0, headers1.length);
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRequestAddCookies.java

示例14: testNoCookieStore

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testNoCookieStore() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, null);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(0, headers1.length);
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRequestAddCookies.java

示例15: testNoCookieSpecRegistry

import org.apache.http.protocol.HttpCoreContext; //导入依赖的package包/类
@Test
public void testNoCookieSpecRegistry() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, null);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(0, headers1.length);
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestRequestAddCookies.java


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