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


Java BasicAuthCache.put方法代碼示例

本文整理匯總了Java中org.apache.http.impl.client.BasicAuthCache.put方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicAuthCache.put方法的具體用法?Java BasicAuthCache.put怎麽用?Java BasicAuthCache.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.client.BasicAuthCache的用法示例。


在下文中一共展示了BasicAuthCache.put方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getContext

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
private HttpClientContext getContext() throws IOException {
    if (context == null) {
        BrokerAddress broker = getBroker();
        String scheme = broker.getProtocol();
        HttpHost targetHost = new HttpHost(broker.getAddress(), broker.getPort(), scheme);

        context = HttpClientContext.create();
        if (configuration.getUsername() != null && !configuration.getUsername().isEmpty()) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort(), AuthScope.ANY_REALM, AuthScope.ANY_SCHEME),
                creds);
            BasicAuthCache authCache = new BasicAuthCache();
            BasicScheme basicAuth = new BasicScheme();
            authCache.put(targetHost, basicAuth);
            context.setCredentialsProvider(credsProvider);
            context.setAuthCache(authCache);
        }

    }
    return context;
}
 
開發者ID:diennea,項目名稱:majordodo,代碼行數:24,代碼來源:HTTPClientConnection.java

示例2: httpContext

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
private HttpContext httpContext() {
    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
    if (isNotBlank(this.username) && this.password != null) {
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password);
        HttpHost httpHost = HttpHost.create(this.rootConfluenceUrl);
        AuthScope authScope = new AuthScope(httpHost);
        basicCredentialsProvider.setCredentials(authScope, credentials);

        BasicAuthCache basicAuthCache = new BasicAuthCache();
        basicAuthCache.put(httpHost, new BasicScheme());

        HttpClientContext httpClientContext = HttpClientContext.create();
        httpClientContext.setCredentialsProvider(basicCredentialsProvider);
        httpClientContext.setAuthCache(basicAuthCache);

        return httpClientContext;
    } else {
        return null;
    }
}
 
開發者ID:jboz,項目名稱:living-documentation,代碼行數:21,代碼來源:ConfluenceRestClient.java

示例3: createAuthCache

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
/**
 * Creates an Authentication Cache
 * @return {@link AuthCache}
 */
public AuthCache createAuthCache() {
	System.out.println("StreakConnectionUtil.createAuthCache()");
	// Create Authentication Cache instance
	authCache = new BasicAuthCache();
	// Generate Basic Authentication scheme and add to the local Authentication cache
	authCache.put(targetHost, new BasicScheme());
	context = HttpClientContext.create();
	context.setCredentialsProvider(credentialsProvider);
	context.setAuthCache(authCache);
	return authCache;
}
 
開發者ID:dingy007,項目名稱:JStreakAPI,代碼行數:16,代碼來源:StreakConnectionUtil.java

示例4: BasicAuthHttpRequestFactory

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
public BasicAuthHttpRequestFactory(HttpClient httpClient, TaxiiServiceSettings settings, ProxySettings proxySettings, CredentialsProvider credsProvider) {
    super(httpClient);
    this.credsProvider = credsProvider;

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

    // Create auth cache with BASIC scheme
    authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());
}
 
開發者ID:CiscoCTA,項目名稱:taxii-log-adapter,代碼行數:15,代碼來源:BasicAuthHttpRequestFactory.java

示例5: getProjectNames

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
/**
 * I return a list of available project names from sonar.
 *
 * @return
 */
public List<RawSonarProject> getProjectNames() {
    CredentialsProvider credsProvider = sonarAuthenticationHelper.credentialsProvider();
    String rawProjectValuesString = null;
    try (CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build()) {
        HttpHost httpHost = new HttpHost(sonarConfig.getHost(), sonarConfig.getHostPort(), "http");
        BasicScheme basicScheme = new BasicScheme();
        BasicAuthCache authCache = new BasicAuthCache();
        authCache.put(httpHost, basicScheme);

        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProvider);
        context.setAuthCache(authCache);

        URIBuilder baseURIBuilder = setupBaseURI(PROJECTS_URL);
        URI uri = baseURIBuilder.build();
        HttpGet httpGet = new HttpGet(uri);
        rawProjectValuesString = processHttpGet(httpclient, context, httpGet);
    } catch(IOException | URISyntaxException e) {
        LOGGER.error("Error thrown refreshing Sonar Stats", e);
    }
    Type listType = new TypeToken<ArrayList<RawSonarProject>>() {}.getType();
    List<RawSonarProject> sonarProjects = new Gson().fromJson(rawProjectValuesString, listType);
    return sonarProjects;
}
 
開發者ID:JohnCannon87,項目名稱:Hammerhead-StatsCollector,代碼行數:32,代碼來源:SonarHttpClient.java

示例6: getProjectValuesFromStartOfTimeToNow

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
/**
 * I return the raw string for all metrics for the provided project name.
 *
 * @param credsProvider
 * @param projectName
 * @return rawString
 * @throws Exception
 */
public RawSonarMetrics getProjectValuesFromStartOfTimeToNow(final String projectName) {
    CredentialsProvider credsProvider = sonarAuthenticationHelper.credentialsProvider();
    String rawProjectValuesString = null;
    try (CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build()) {
        HttpHost httpHost = new HttpHost(sonarConfig.getHost(), sonarConfig.getHostPort(), "http");
        BasicScheme basicScheme = new BasicScheme();
        BasicAuthCache authCache = new BasicAuthCache();
        authCache.put(httpHost, basicScheme);

        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProvider);
        context.setAuthCache(authCache);

        URIBuilder baseURIBuilder = setupBaseURI(TIME_MACHINE_URL);
        baseURIBuilder.addParameters(getDateWindowParameters(projectName));
        URI uri = baseURIBuilder.build();
        HttpGet httpGet = new HttpGet(uri);
        rawProjectValuesString = processHttpGet(httpclient, context, httpGet);
    } catch(IOException | URISyntaxException e) {
        LOGGER.error("Error thrown refreshing Sonar Stats", e);
    }

    Type listType = new TypeToken<ArrayList<RawSonarMetrics>>() {}.getType();
    List<RawSonarMetrics> rawSonarMetrics = new Gson().fromJson(rawProjectValuesString, listType);
    return rawSonarMetrics.get(0);
}
 
開發者ID:JohnCannon87,項目名稱:Hammerhead-StatsCollector,代碼行數:37,代碼來源:SonarHttpClient.java

示例7: createHttpContext

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
    BasicHttpContext localContext = new BasicHttpContext();
    if (Boolean.valueOf(settings.getProperty(HTTP_AUTH_PREEMPTIVE))) {
        HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        BasicScheme basicScheme = new BasicScheme();
        BasicAuthCache authCache = new BasicAuthCache();
        authCache.put(targetHost, basicScheme);
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }

    return createHttpContext(localContext);
}
 
開發者ID:motech,項目名稱:modules,代碼行數:17,代碼來源:HttpComponentsClientHttpRequestFactoryWithAuth.java

示例8: getHttpClientContext

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
private HttpClientContext getHttpClientContext() throws Exception {
    HttpProxyConfig httpProxyConfig = configRepository.getHttpProxyConfig();
    if (httpProxyConfig.host().isEmpty() || httpProxyConfig.username().isEmpty()) {
        return HttpClientContext.create();
    }

    // perform preemptive proxy authentication

    int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80);
    HttpHost proxyHost = new HttpHost(httpProxyConfig.host(), proxyPort);

    BasicScheme basicScheme = new BasicScheme();
    basicScheme.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm="));
    BasicAuthCache authCache = new BasicAuthCache();
    authCache.put(proxyHost, basicScheme);

    String password = httpProxyConfig.password();
    if (!password.isEmpty()) {
        password = Encryption.decrypt(password, configRepository.getLazySecretKey());
    }
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(proxyHost),
            new UsernamePasswordCredentials(httpProxyConfig.username(), password));
    HttpClientContext context = HttpClientContext.create();
    context.setAuthCache(authCache);
    context.setCredentialsProvider(credentialsProvider);
    return context;
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:29,代碼來源:SyntheticMonitorService.java

示例9: getClient

import org.apache.http.impl.client.BasicAuthCache; //導入方法依賴的package包/類
/**
 * Returns a HTTP client doing Basic Auth if needed.
 * @param url The URL to browse.
 * @param user The user. Maybe null.
 * @param password The password. Maybe null.
 * @return The HTTP client.
 */
public static CloseableHttpClient getClient(
    URL url, String user, String password
) {
    int timeout = DEFAULT_TIMEOUT;

    ApplicationSettings set = Config
        .getInstance()
        .getApplicationSettings();

    String ts = set.getApplicationSetting("requestTimeout_s");
    if (ts != null) {
        try {
            timeout = S_TO_MS * Integer.parseInt(ts);
        } catch (NumberFormatException nfe) {
            log.log(Level.SEVERE, nfe.getMessage());
        }
    }

    // Use JVM proxy settings.
    SystemDefaultRoutePlanner routePlanner
        = new SystemDefaultRoutePlanner(ProxySelector.getDefault());

    RequestConfig requestConfig = RequestConfig.
            custom().
            setSocketTimeout(timeout).build();
    HttpClientBuilder builder = HttpClientBuilder.create()
            .setDefaultRequestConfig(requestConfig);
    builder.setRetryHandler(new StandardHttpRequestRetryHandler(1, true));
    builder.setRoutePlanner(routePlanner);

    builder.setUserAgent(getUserAgent());
    if (user != null && password != null) {

        UsernamePasswordCredentials defaultCreds =
            new UsernamePasswordCredentials(user, password);

        BasicCredentialsProvider credsProv = new BasicCredentialsProvider();

        credsProv.setCredentials(
            new AuthScope(url.getHost(), url.getPort()), defaultCreds);

        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProv);

        BasicAuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        HttpHost target = new HttpHost(url.getHost(), url.getPort());

        authCache.put(target, basicAuth);
        context.setAuthCache(authCache);

        builder.setDefaultCredentialsProvider(credsProv);
    }


    return builder.build();
}
 
開發者ID:gdi-by,項目名稱:downloadclient,代碼行數:65,代碼來源:HTTP.java


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