Code example for AuthState

Methods: getAuthScheme

    public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
        final AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
        // If no auth scheme avaialble yet, try to initialize it preemptively 
        if (authState.getAuthScheme() == null) {
            final AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
            final CredentialsProvider credsProvider =
                (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
            final HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (authScheme != null) {
                final Credentials creds =
                    credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
                if (creds == null) {
                    throw new HttpException("No credentials for preemptive authentication.");
Experience pair programming with AI  Get Codota for Java