當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientContext.setAuthSchemeRegistry方法代碼示例

本文整理匯總了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());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:21,代碼來源:TestAuthenticationStrategy.java

示例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());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestAuthenticationStrategy.java

示例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());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:27,代碼來源:TestInternalHttpClient.java

示例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);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:28,代碼來源:TestAuthenticationStrategy.java

示例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);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:31,代碼來源:TestAuthenticationStrategy.java

示例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);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:33,代碼來源:TestAuthenticationStrategy.java


注:本文中的org.apache.http.client.protocol.HttpClientContext.setAuthSchemeRegistry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。