Example usage for org.apache.http.client.protocol ClientContext AUTHSCHEME_REGISTRY

List of usage examples for org.apache.http.client.protocol ClientContext AUTHSCHEME_REGISTRY

Introduction

In this page you can find the example usage for org.apache.http.client.protocol ClientContext AUTHSCHEME_REGISTRY.

Prototype

String AUTHSCHEME_REGISTRY

To view the source code for org.apache.http.client.protocol ClientContext AUTHSCHEME_REGISTRY.

Click Source Link

Document

Attribute name of a org.apache.http.config.Lookup object that represents the actual org.apache.http.auth.AuthSchemeRegistry registry.

Usage

From source file:com.lemi.mario.download.http.AndroidHttpClient.java

private AndroidHttpClient(ClientConnectionManager ccm, HttpParams params) {
    super(null);/* w  ww  . j av  a2  s.  co  m*/
    final HttpClient delegate = new DefaultHttpClient(ccm, params) {
        @Override
        protected BasicHttpProcessor createHttpProcessor() {
            // Add interceptor to prevent making requests from main thread.
            BasicHttpProcessor processor = super.createHttpProcessor();
            processor.addRequestInterceptor(sThreadCheckInterceptor);
            processor.addRequestInterceptor(new CurlLogger());

            return processor;
        }

        @Override
        protected HttpContext createHttpContext() {
            // Same as DefaultHttpClient.createHttpContext() minus the
            // cookie store.
            HttpContext context = new BasicHttpContext();
            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
            context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
            context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
            return context;
        }
    };
    setWrappedHttpClient(delegate);
}

From source file:com.appassit.http.AndroidHttpClient.java

private AndroidHttpClient(ClientConnectionManager ccm, HttpParams params) {
    this.delegate = new DefaultHttpClient(ccm, params) {
        @Override/*from   w  ww .j a v a 2 s .  c om*/
        protected BasicHttpProcessor createHttpProcessor() {
            // Add interceptor to prevent making requests from main thread.
            BasicHttpProcessor processor = super.createHttpProcessor();
            processor.addRequestInterceptor(sThreadCheckInterceptor);
            processor.addRequestInterceptor(new CurlLogger());

            return processor;
        }

        @Override
        protected HttpContext createHttpContext() {
            // Same as DefaultHttpClient.createHttpContext() minus the
            // cookie store.
            HttpContext context = new BasicHttpContext();
            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
            context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
            context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
            context.setAttribute(ClientContext.COOKIE_STORE, getCookieStore());
            return context;
        }
    };
}

From source file:org.apache.http.impl.client.AbstractAuthenticationHandler.java

public AuthScheme selectScheme(final Map<String, Header> challenges, final HttpResponse response,
        final HttpContext context) throws AuthenticationException {

    final AuthSchemeRegistry registry = (AuthSchemeRegistry) context
            .getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
    Asserts.notNull(registry, "AuthScheme registry");
    Collection<String> authPrefs = getAuthPreferences(response, context);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }// ww  w .  j  av  a2s . com

    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    AuthScheme authScheme = null;
    for (final String id : authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));

        if (challenge != null) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(id + " authentication scheme selected");
            }
            try {
                authScheme = registry.getAuthScheme(id, response.getParams());
                break;
            } catch (final IllegalStateException e) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    if (authScheme == null) {
        // If none selected, something is wrong
        throw new AuthenticationException("Unable to respond to any of these challenges: " + challenges);
    }
    return authScheme;
}

From source file:org.apache.http.impl.client.AbstractHttpClient.java

protected HttpContext createHttpContext() {
    final HttpContext context = new BasicHttpContext();
    context.setAttribute(ClientContext.SCHEME_REGISTRY, getConnectionManager().getSchemeRegistry());
    context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
    context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
    context.setAttribute(ClientContext.COOKIE_STORE, getCookieStore());
    context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
    return context;
}

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

protected HttpContext createHttpContext() {
    HttpContext context = new BasicHttpContext();
    context.setAttribute(ClientContext.SCHEME_REGISTRY, getConnectionManager().getSchemeRegistry());
    context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
    context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
    context.setAttribute(ClientContext.COOKIE_STORE, getCookieStore());
    context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
    return context;
}