本文整理汇总了Java中org.apache.http.client.protocol.HttpClientContext.setAuthSchemeRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientContext.setAuthSchemeRegistry方法的具体用法?Java HttpClientContext.setAuthSchemeRegistry怎么用?Java HttpClientContext.setAuthSchemeRegistry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.protocol.HttpClientContext
的用法示例。
在下文中一共展示了HttpClientContext.setAuthSchemeRegistry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSelectNoCredentialsProvider
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testSelectNoCredentialsProvider() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
final HttpHost authhost = new HttpHost("locahost", 80);
final HttpClientContext context = HttpClientContext.create();
final Map<String, Header> challenges = new HashMap<String, Header>();
challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAuthSchemeRegistry(authSchemeRegistry);
final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
Assert.assertNotNull(options);
Assert.assertEquals(0, options.size());
}
示例2: testNoCredentials
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testNoCredentials() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
final HttpHost authhost = new HttpHost("locahost", 80);
final HttpClientContext context = HttpClientContext.create();
final Map<String, Header> challenges = new HashMap<String, Header>();
challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAuthSchemeRegistry(authSchemeRegistry);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
context.setCredentialsProvider(credentialsProvider);
final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
Assert.assertNotNull(options);
Assert.assertEquals(0, options.size());
}
示例3: testExecuteLocalContext
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testExecuteLocalContext() throws Exception {
final HttpGet httpget = new HttpGet("http://somehost/stuff");
final HttpClientContext context = HttpClientContext.create();
final Lookup<CookieSpecProvider> localCookieSpecRegistry = Mockito.mock(Lookup.class);
final Lookup<AuthSchemeProvider> localAuthSchemeRegistry = Mockito.mock(Lookup.class);
final CookieStore localCookieStore = Mockito.mock(CookieStore.class);
final CredentialsProvider localCredentialsProvider = Mockito.mock(CredentialsProvider.class);
final RequestConfig localConfig = RequestConfig.custom().build();
context.setCookieSpecRegistry(localCookieSpecRegistry);
context.setAuthSchemeRegistry(localAuthSchemeRegistry);
context.setCookieStore(localCookieStore);
context.setCredentialsProvider(localCredentialsProvider);
context.setRequestConfig(localConfig);
client.execute(httpget, context);
Assert.assertSame(localCookieSpecRegistry, context.getCookieSpecRegistry());
Assert.assertSame(localAuthSchemeRegistry, context.getAuthSchemeRegistry());
Assert.assertSame(localCookieStore, context.getCookieStore());
Assert.assertSame(localCredentialsProvider, context.getCredentialsProvider());
Assert.assertSame(localConfig, context.getRequestConfig());
}
示例4: testCredentialsFound
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testCredentialsFound() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
final HttpHost authhost = new HttpHost("somehost", 80);
final HttpClientContext context = HttpClientContext.create();
final Map<String, Header> challenges = new HashMap<String, Header>();
challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAuthSchemeRegistry(authSchemeRegistry);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope("somehost", 80, "realm2"),
new UsernamePasswordCredentials("user", "pwd"));
context.setCredentialsProvider(credentialsProvider);
final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
Assert.assertNotNull(options);
Assert.assertEquals(1, options.size());
final AuthOption option = options.remove();
Assert.assertTrue(option.getAuthScheme() instanceof DigestScheme);
}
示例5: testUnsupportedScheme
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testUnsupportedScheme() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
final HttpHost authhost = new HttpHost("somehost", 80);
final HttpClientContext context = HttpClientContext.create();
final Map<String, Header> challenges = new HashMap<String, Header>();
challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
challenges.put("whatever", new BasicHeader(AUTH.WWW_AUTH, "Whatever realm=\"realm3\""));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAuthSchemeRegistry(authSchemeRegistry);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope("somehost", 80),
new UsernamePasswordCredentials("user", "pwd"));
context.setCredentialsProvider(credentialsProvider);
final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
Assert.assertNotNull(options);
Assert.assertEquals(2, options.size());
final AuthOption option1 = options.remove();
Assert.assertTrue(option1.getAuthScheme() instanceof DigestScheme);
final AuthOption option2 = options.remove();
Assert.assertTrue(option2.getAuthScheme() instanceof BasicScheme);
}
示例6: testCustomAuthPreference
import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testCustomAuthPreference() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
final RequestConfig config = RequestConfig.custom()
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
.build();
final HttpHost authhost = new HttpHost("somehost", 80);
final HttpClientContext context = HttpClientContext.create();
final Map<String, Header> challenges = new HashMap<String, Header>();
challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAuthSchemeRegistry(authSchemeRegistry);
context.setRequestConfig(config);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope("somehost", 80),
new UsernamePasswordCredentials("user", "pwd"));
context.setCredentialsProvider(credentialsProvider);
final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
Assert.assertNotNull(options);
Assert.assertEquals(1, options.size());
final AuthOption option1 = options.remove();
Assert.assertTrue(option1.getAuthScheme() instanceof BasicScheme);
}