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


Java HttpClientContext.getAttribute方法代碼示例

本文整理匯總了Java中org.apache.http.client.protocol.HttpClientContext.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientContext.getAttribute方法的具體用法?Java HttpClientContext.getAttribute怎麽用?Java HttpClientContext.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.protocol.HttpClientContext的用法示例。


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

示例1: authSucceeded

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Override
public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Credentials credentials = clientContext.getAttribute(PROXY_CREDENTIALS_INPUT_ID, Credentials.class);
    if(null != credentials) {
        clientContext.removeAttribute(PROXY_CREDENTIALS_INPUT_ID);
        if(log.isInfoEnabled()) {
            log.info(String.format("Save passphrase for proxy %s", authhost));
        }
        keychain.addCredentials(authhost.getHostName(), credentials.getUsername(), credentials.getPassword());
    }
    super.authSucceeded(authhost, authScheme, context);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:14,代碼來源:CallbackProxyAuthenticationStrategy.java

示例2: execute

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext clientContext,
        HttpExecutionAware execAware) throws IOException, HttpException {
    Proxy proxy = (Proxy) clientContext.getAttribute(VSCrawlerConstant.VSCRAWLER_AVPROXY_KEY);
    if (proxy != null) {
        proxy.recordUsage();
    }
    try {
        return delegate.execute(route, request, clientContext, execAware);
    } catch (IOException ioe) {
        if (proxy != null) {
            proxy.recordFailed();
        }
        throw ioe;
    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:17,代碼來源:ProxyFeedBackClientExecChain.java

示例3: setupContext

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
private void setupContext(final HttpClientContext context) {
    if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthStateHC4());
    }
    if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthStateHC4());
    }
    if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIESPEC_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIE_STORE) == null) {
        context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    }
    if (context.getAttribute(HttpClientContext.CREDS_PROVIDER) == null) {
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
    }
    if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
        context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.defaultConfig);
    }
}
 
開發者ID:xxonehjh,項目名稱:remote-files-sync,代碼行數:24,代碼來源:InternalHttpClient.java

示例4: setupContext

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
private void setupContext(final HttpClientContext context) {
    if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthState());
    }
    if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) {
        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthState());
    }
    if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIESPEC_REGISTRY) == null) {
        context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
    }
    if (context.getAttribute(HttpClientContext.COOKIE_STORE) == null) {
        context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    }
    if (context.getAttribute(HttpClientContext.CREDS_PROVIDER) == null) {
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
    }
    if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
        context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.defaultConfig);
    }
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:InternalHttpClient.java

示例5: execute

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Override
public CloseableHttpResponse execute(
    HttpRoute route,
    HttpRequestWrapper request,
    HttpClientContext clientContext,
    HttpExecutionAware execAware) throws IOException, HttpException {

  ActiveSpan localSpan = clientContext.getAttribute(ACTIVE_SPAN, ActiveSpan.class);
  CloseableHttpResponse response = null;
  try {
    if (localSpan == null) {
      localSpan = handleLocalSpan(request, clientContext);
    }

    return (response = handleNetworkProcessing(localSpan, route, request, clientContext, execAware));
  } catch (Exception e) {
    localSpan.deactivate();
    throw e;
  } finally {
    if (response != null) {
      /**
       * This exec runs after {@link org.apache.http.impl.execchain.RedirectExec} which loops
       * until there is no redirect or reaches max redirect count.
       * {@link RedirectStrategy} is used to decide whether localSpan should be finished or not.
       * If there is a redirect localSpan is not finished and redirect is logged.
       */
      Integer redirectCount = clientContext.getAttribute(REDIRECT_COUNT, Integer.class);
      if (!redirectHandlingDisabled &&
          clientContext.getRequestConfig().isRedirectsEnabled() &&
          redirectStrategy.isRedirected(request, response, clientContext) &&
          ++redirectCount < clientContext.getRequestConfig().getMaxRedirects()) {

        clientContext.setAttribute(REDIRECT_COUNT, redirectCount);
      } else {
        localSpan.deactivate();
      }
    }
  }
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:40,代碼來源:TracingClientExec.java

示例6: handleLocalSpan

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
protected ActiveSpan handleLocalSpan(HttpRequest httpRequest, HttpClientContext clientContext) {
  Tracer.SpanBuilder spanBuilder = tracer.buildSpan(httpRequest.getRequestLine().getMethod())
      .withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME);

  if (clientContext.getAttribute(PARENT_CONTEXT, SpanContext.class) != null) {
    spanBuilder.ignoreActiveSpan()
            .asChildOf(clientContext.getAttribute(PARENT_CONTEXT, SpanContext.class));
  }

  ActiveSpan localSpan = spanBuilder.startActive();
  clientContext.setAttribute(ACTIVE_SPAN, localSpan);
  clientContext.setAttribute(REDIRECT_COUNT, 0);
  return localSpan;
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:15,代碼來源:TracingClientExec.java

示例7: getLocationURI

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtilsHC4.rewriteURI(requestURI, target, false);
            uri = URIUtilsHC4.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocationsHC4 redirectLocations = (RedirectLocationsHC4) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocationsHC4();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
開發者ID:xxonehjh,項目名稱:remote-files-sync,代碼行數:61,代碼來源:DefaultRedirectStrategy.java

示例8: getLocationURI

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:61,代碼來源:DefaultRedirectStrategy.java


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