Package org.apache.http.client

Examples of org.apache.http.client.AuthCache


            String host = url.getHost();
            int port = url.getPort() > -1 ? url.getPort() : AuthScope.ANY_PORT;

            httpClient.getCredentialsProvider().setCredentials( new AuthScope( host, port ), creds );

            AuthCache authCache = new BasicAuthCache();
            BasicScheme basicAuth = new BasicScheme();
            HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol() );
            authCache.put( targetHost, basicAuth );

            localContext = new BasicHttpContext();
            localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
        }
    }
View Full Code Here


        httpClient.getCredentialsProvider().setCredentials( new AuthScope( uri.getHost(), uri.getPort() ),
                                                            new UsernamePasswordCredentials( username, password ) );

        HttpHost targetHost = new HttpHost( url.getHost(), url.getPort(), url.getProtocol() );

        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put( targetHost, basicAuth );

        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute( ClientContext.AUTH_CACHE, authCache );

        System.out.println( "Retrieving resource '" + url.toString() + "' using HttpClient's get method.." );
View Full Code Here

        // Add AuthCache to the execution context
        BasicHttpContext localcontext = new BasicHttpContext();

        // Generate BASIC scheme object and add it to the local auth cache
        AuthCache authCache = new BasicAuthCache();
        authCache.put(targetHost, new BasicScheme());
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        return localcontext;
    }
View Full Code Here

        final AuthScope scope = ((PreemptiveAuthHttpRequestFactory) SyncopeSession.get().getRestTemplate().
                getRequestFactory()).getAuthScope();
        final HttpHost targetHost = new HttpHost(scope.getHost(), scope.getPort(), scope.getScheme());
        BasicHttpContext localcontext = new BasicHttpContext();
        // Generate BASIC scheme object and add it to the local auth cache
        AuthCache authCache = new BasicAuthCache();
        authCache.put(targetHost, new BasicScheme());
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        HttpGet getMethod = new HttpGet(this.uri);
        HttpResponse response;
        try {
View Full Code Here

        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        Assert.assertNotNull(authCache);
        Assert.assertSame(this.authscheme1, authCache.get(this.target));
        Assert.assertSame(this.authscheme2, authCache.get(this.proxy));
    }
View Full Code Here

        context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, this.proxy);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        Assert.assertNull(authCache);
    }
View Full Code Here

        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        Assert.assertNull(authCache);
    }
View Full Code Here

        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        Assert.assertNull(authCache);
    }
View Full Code Here

        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        Assert.assertNotNull(authCache);
        Assert.assertNull(authCache.get(this.target));
        Assert.assertNull(authCache.get(this.proxy));
    }
View Full Code Here

        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, this.proxy);
        context.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetState);
        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

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

        context.setAttribute(ClientContext.AUTH_CACHE, authCache);

        HttpResponseInterceptor interceptor = new ResponseAuthCache();
        interceptor.process(response, context);

        Assert.assertNull(authCache.get(this.target));
        Assert.assertNull(authCache.get(this.proxy));
    }
View Full Code Here

TOP

Related Classes of org.apache.http.client.AuthCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.