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


Java HttpClientContext.getRequestConfig方法代码示例

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


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

示例1: determineRoute

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
public HttpRoute determineRoute(
        final HttpHost host,
        final HttpRequest request,
        final HttpContext context) throws HttpException {
    Args.notNull(request, "Request");
    if (host == null) {
        throw new ProtocolException("Target host is not specified");
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig config = clientContext.getRequestConfig();
    final InetAddress local = config.getLocalAddress();
    HttpHost proxy = config.getProxy();
    if (proxy == null) {
        proxy = determineProxy(host, request, context);
    }

    final HttpHost target;
    if (host.getPort() <= 0) {
        try {
            target = new HttpHost(
                    host.getHostName(),
                    this.schemePortResolver.resolve(host),
                    host.getSchemeName());
        } catch (final UnsupportedSchemeException ex) {
            throw new HttpException(ex.getMessage());
        }
    } else {
        target = host;
    }
    final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
    if (proxy == null) {
        return new HttpRoute(target, local, secure);
    } else {
        return new HttpRoute(target, local, proxy, secure);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:37,代码来源:DefaultRoutePlanner.java

示例2: process

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
public void process(HttpResponse response, HttpContext context)
        throws HttpException, IOException {
    ArrayList<Header[]> headersToSave = null;
    
    final HttpEntity entity = response.getEntity();
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig requestConfig = clientContext.getRequestConfig();
    // store the headers if necessary
    if (requestConfig.isContentCompressionEnabled() && entity != null && entity.getContentLength() != 0) {
        final Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            headersToSave = new ArrayList<>(3);
            for(String name : HEADERS_TO_SAVE) {
                Header[] hdr = response.getHeaders(name); // empty if none
                headersToSave.add(hdr);
            }
        }
    }

    // Now invoke original parent code
    super.process(response, clientContext);
    // Should this be in a finally ? 
    if(headersToSave != null) {
        for (Header[] headers : headersToSave) {
            for (Header headerToRestore : headers) {
                if (response.containsHeader(headerToRestore.getName())) {
                    break;
                }
                response.addHeader(headerToRestore);
            }
        }
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:35,代码来源:HTTPHC4Impl.java

示例3: determineRoute

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
public HttpRoute determineRoute(
        final HttpHost host,
        final HttpRequest request,
        final HttpContext context) throws HttpException {
    Args.notNull(request, "Request");
    if (host == null) {
        throw new ProtocolException("Target host is not specified");
    }
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final RequestConfig config = clientContext.getRequestConfig();
    final InetAddress local = config.getLocalAddress();
    HttpHost proxy = config.getProxy();
    if (proxy == null) {
        proxy = determineProxy(host, request, context);
    }

    final HttpHost target;
    if (host.getPort() <= 0) {
        try {
            target = new HttpHost(
                    host.getHostName(),
                    this.schemePortResolver.resolve(host),
                    host.getSchemeName());
        } catch (final UnsupportedSchemeException ex) {
            throw new HttpException(ex.getMessage());
        }
    } else {
        target = host;
    }
    final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
    if (proxy == null) {
        return new HttpRoute(target, local, secure);
    } else {
        return new HttpRoute(target, local, proxy, secure);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:38,代码来源:DefaultRoutePlanner.java

示例4: select

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
public Queue<AuthOption> select(final Map<String, Header> challenges, final HttpHost authhost, final HttpResponse response, final HttpContext context) throws MalformedChallengeException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if(registry == null) {
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = config.getProxyPreferredAuthSchemes();
    if(authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if(log.isDebugEnabled()) {
        log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for(final String id : authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
        if(challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if(authSchemeProvider == null) {
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);
            final Credentials saved = keychain.getCredentials(authhost.getHostName());
            if(StringUtils.isEmpty(saved.getPassword())) {
                try {
                    final Credentials input = prompt.prompt(bookmark,
                        StringUtils.EMPTY,
                        String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), authhost.getHostName()),
                        authScheme.getRealm(),
                        new LoginOptions()
                            .icon(bookmark.getProtocol().disk())
                            .usernamePlaceholder(LocaleFactory.localizedString("Username", "Credentials"))
                            .passwordPlaceholder(LocaleFactory.localizedString("Password", "Credentials"))
                            .user(true).password(true)
                    );
                    if(input.isSaved()) {
                        context.setAttribute(PROXY_CREDENTIALS_INPUT_ID, input);
                    }
                    options.add(new AuthOption(authScheme, new NTCredentials(input.getUsername(), input.getPassword(),
                        preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain"))));
                }
                catch(LoginCanceledException ignored) {
                    // Ignore dismiss of prompt
                    throw new MalformedChallengeException(ignored.getMessage(), ignored);
                }
            }
            else {
                options.add(new AuthOption(authScheme, new NTCredentials(saved.getUsername(), saved.getPassword(),
                    preferences.getProperty("webdav.ntlm.workstation"), preferences.getProperty("webdav.ntlm.domain"))));
            }
        }
        else {
            if(log.isDebugEnabled()) {
                log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:65,代码来源:CallbackProxyAuthenticationStrategy.java

示例5: needAuthentication

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private boolean needAuthentication(
        final AuthStateHC4 targetAuthState,
        final AuthStateHC4 proxyAuthState,
        final HttpRoute route,
        final HttpResponse response,
        final HttpClientContext context) {
    final RequestConfig config = context.getRequestConfig();
    if (config.isAuthenticationEnabled()) {
        HttpHost target = context.getTargetHost();
        if (target == null) {
            target = route.getTargetHost();
        }
        if (target.getPort() < 0) {
            target = new HttpHost(
                    target.getHostName(),
                    route.getTargetHost().getPort(),
                    target.getSchemeName());
        }
        final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
                target, response, this.targetAuthStrategy, targetAuthState, context);

        HttpHost proxy = route.getProxyHost();
        // if proxy is not set use target host instead
        if (proxy == null) {
            proxy = route.getTargetHost();
        }
        final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
                proxy, response, this.proxyAuthStrategy, proxyAuthState, context);

        if (targetAuthRequested) {
            return this.authenticator.handleAuthChallenge(target, response,
                    this.targetAuthStrategy, targetAuthState, context);
        }
        if (proxyAuthRequested) {
            return this.authenticator.handleAuthChallenge(proxy, response,
                    this.proxyAuthStrategy, proxyAuthState, context);
        }
    }
    return false;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:41,代码来源:MainClientExec.java

示例6: 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

示例7: select

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Auth scheme registry not set in the context");
        }
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Credentials provider not set in the context");
        }
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (Log.isLoggable(TAG, Log.WARN)) {
                    Log.w(TAG, "Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:69,代码来源:AuthenticationStrategyImpl.java

示例8: needAuthentication

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private boolean needAuthentication(
        final AuthState targetAuthState,
        final AuthState proxyAuthState,
        final HttpRoute route,
        final HttpResponse response,
        final HttpClientContext context) {
    final RequestConfig config = context.getRequestConfig();
    if (config.isAuthenticationEnabled()) {
        HttpHost target = context.getTargetHost();
        if (target == null) {
            target = route.getTargetHost();
        }
        if (target.getPort() < 0) {
            target = new HttpHost(
                    target.getHostName(),
                    route.getTargetHost().getPort(),
                    target.getSchemeName());
        }
        final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
                target, response, this.targetAuthStrategy, targetAuthState, context);

        HttpHost proxy = route.getProxyHost();
        // if proxy is not set use target host instead
        if (proxy == null) {
            proxy = route.getTargetHost();
        }
        final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
                proxy, response, this.proxyAuthStrategy, proxyAuthState, context);

        if (targetAuthRequested) {
            return this.authenticator.handleAuthChallenge(target, response,
                    this.targetAuthStrategy, targetAuthState, context);
        }
        if (proxyAuthRequested) {
            return this.authenticator.handleAuthChallenge(proxy, response,
                    this.proxyAuthStrategy, proxyAuthState, context);
        }
    }
    return false;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:41,代码来源:MainClientExec.java

示例9: 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

示例10: select

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:66,代码来源:AuthenticationStrategyImpl.java


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