当前位置: 首页>>代码示例>>Java>>正文


Java BasicHttpContext.setAttribute方法代码示例

本文整理汇总了Java中org.apache.http.protocol.BasicHttpContext.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java BasicHttpContext.setAttribute方法的具体用法?Java BasicHttpContext.setAttribute怎么用?Java BasicHttpContext.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.protocol.BasicHttpContext的用法示例。


在下文中一共展示了BasicHttpContext.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpClient

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
public QMailHttpClient getHttpClient() throws MessagingException {
    if (httpClient == null) {
        httpClient = httpClientFactory.create();
        // Disable automatic redirects on the http client.
        httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        httpContext = new BasicHttpContext();
        authCookies = new BasicCookieStore();
        httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);

        SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(hostname, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient");
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa);
        } catch (KeyManagementException kme) {
            Timber.e(kme, "KeyManagementException in getHttpClient");
            throw new MessagingException("KeyManagementException in getHttpClient: ", kme);
        }
    }
    return httpClient;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:26,代码来源:WebDavStore.java

示例2: createContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
@Override
public BasicHttpContext createContext(final HttpHost targetHost) {

    final CookieStore cookieStore = new BasicCookieStore();

    final BasicClientCookie clientCookie =
            new BasicClientCookie(cookie.getName(), cookie.getValue());
    clientCookie.setDomain(targetHost.getHostName());
    clientCookie.setPath("/");
    cookieStore.addCookie(clientCookie);

    final BasicHttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);

    return context;
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:17,代码来源:UseCookieConfigurator.java

示例3: getHTTPStatusCode

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
/**
    * Perform an HTTP Status check and return the response code
    *
    * @return
    * @throws IOException
    */
   @SuppressWarnings("resource")
public int getHTTPStatusCode() throws IOException {

       HttpClient client = new DefaultHttpClient();
       BasicHttpContext localContext = new BasicHttpContext();

       LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState);
       if (this.mimicWebDriverCookieState) {
           localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies()));
       }
       HttpRequestBase requestMethod = this.httpRequestMethod.getRequestMethod();
       requestMethod.setURI(this.linkToCheck);
       HttpParams httpRequestParameters = requestMethod.getParams();
       httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
       requestMethod.setParams(httpRequestParameters);

       LOG.info("Sending " + requestMethod.getMethod() + " request for: " + requestMethod.getURI());
       HttpResponse response = client.execute(requestMethod, localContext);
       LOG.info("HTTP " + requestMethod.getMethod() + " request status: " + response.getStatusLine().getStatusCode());

       return response.getStatusLine().getStatusCode();
   }
 
开发者ID:GovernIB,项目名称:helium,代码行数:29,代码来源:URLStatusChecker.java

示例4: checkLocalContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private synchronized void checkLocalContext()
{
    if (null != sdkProtocolAdatperCustProvider && null != target)
    {
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate DIGEST scheme object, initialize it and add it to the local auth cache
        String authType = (String) ThreadLocalHolder.get().getEntities().get("AuthType");
        if ("Basic".equals(authType))
        {
            LOGGER.debug("authentication type: basic");
        }
        else
        {
            DigestScheme digestAuth = new DigestScheme();
            digestAuth.overrideParamter("nc", String.valueOf(serverNounceCount++));
            digestAuth.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
            digestAuth.overrideParamter("qop", "auth");
            authCache.put(target, digestAuth);
        }
        
        // Add AuthCache to the execution context
        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:27,代码来源:RestfulAdapterImplHttpClient.java

示例5: checkLocalContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private synchronized void checkLocalContext()
{
    if (null != sdkProtocolAdatperCustProvider && null != target)
    {
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate DIGEST scheme object, initialize it and add it to the local auth cache
        String authType = (String)ThreadLocalHolder.get().getEntities().get("AuthType");
        if ("Basic".equals(authType))
        {
            LOGGER.debug("authentication type: basic");
        }
        else
        {
            DigestScheme digestAuth = new DigestScheme();
            digestAuth.overrideParamter("nc", String.valueOf(serverNounceCount++));
            digestAuth.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
            digestAuth.overrideParamter("qop", "auth");
            authCache.put(target, digestAuth);
        }
        
        // Add AuthCache to the execution context
        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:27,代码来源:RestfulAdapterImplHttpClientHTLS.java

示例6: getHttpClient

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
public WebDavHttpClient getHttpClient() throws MessagingException {
    if (mHttpClient == null) {
        mHttpClient = mHttpClientFactory.create();
        // Disable automatic redirects on the http client.
        mHttpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        mContext = new BasicHttpContext();
        mAuthCookies = new BasicCookieStore();
        mContext.setAttribute(ClientContext.COOKIE_STORE, mAuthCookies);

        SchemeRegistry reg = mHttpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(mHost, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Log.e(LOG_TAG, "NoSuchAlgorithmException in getHttpClient: " + nsa);
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
        } catch (KeyManagementException kme) {
            Log.e(LOG_TAG, "KeyManagementException in getHttpClient: " + kme);
            throw new MessagingException("KeyManagementException in getHttpClient: " + kme);
        }
    }
    return mHttpClient;
}
 
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:26,代码来源:WebDavStore.java

示例7: createContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
@Override
    public BasicHttpContext createContext(HttpHost targetHost) {

        final AuthCache authCache = new BasicAuthCache();

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

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        // OPTIMIZED
        credentialsProvider
                .setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

        // NON-OPTIMIZED
//        credentialsProvider.setCredentials(
//                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
//                new UsernamePasswordCredentials(username, password));

        final BasicHttpContext context = new BasicHttpContext();
        context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, credentialsProvider);

        return context;
    }
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:26,代码来源:BasicAuthConfigurator.java

示例8: createHttpContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
	final AuthCache authCache = new BasicAuthCache();

	final BasicScheme basicAuth = new BasicScheme();
	authCache.put(host, basicAuth);

	final BasicHttpContext localcontext = new BasicHttpContext();
	localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
	return localcontext;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:12,代码来源:PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory.java

示例9: createHttpContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private HttpContext createHttpContext() {
	// Create AuthCache instance
	final AuthCache authCache = new BasicAuthCache();
	// Generate BASIC scheme object and add it to the local auth cache
	final BasicScheme basicAuth = new BasicScheme();
	authCache.put(host, basicAuth);

	// Add AuthCache to the execution context
	final BasicHttpContext localcontext = new BasicHttpContext();
	localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
	return localcontext;
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:13,代码来源:HttpComponentsClientHttpRequestFactoryBasicAuth.java

示例10: createHttpContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private HttpContext createHttpContext() {
    final AuthCache authCache = new BasicAuthCache();
    final BasicScheme basicAuth = new BasicScheme();
    authCache.put(host, basicAuth);
    final BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
    return localcontext;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:CasRestAuthenticationConfiguration.java

示例11: makeHttpRequest

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
@Override
protected HttpResponse makeHttpRequest(HttpEntity entity, long startTime) {
    if (entity != null) {
        requestBuilder.setEntity(entity);
        requestBuilder.setHeader(entity.getContentType());
    }
    HttpUriRequest httpRequest = requestBuilder.build();
    CloseableHttpClient client = clientBuilder.build();
    BasicHttpContext context = new BasicHttpContext();
    context.setAttribute(URI_CONTEXT_KEY, getRequestUri());
    CloseableHttpResponse httpResponse;
    byte[] bytes;
    try {
        httpResponse = client.execute(httpRequest, context);
        HttpEntity responseEntity = httpResponse.getEntity();
        if (responseEntity == null || responseEntity.getContent() == null) {
            bytes = new byte[0];
        } else {
            InputStream is = responseEntity.getContent();
            bytes = FileUtils.toBytes(is);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    long responseTime = getResponseTime(startTime);
    HttpResponse response = new HttpResponse(responseTime);
    response.setUri(getRequestUri());
    response.setBody(bytes);
    response.setStatus(httpResponse.getStatusLine().getStatusCode());
    for (Cookie c : cookieStore.getCookies()) {
        com.intuit.karate.http.Cookie cookie = new com.intuit.karate.http.Cookie(c.getName(), c.getValue());
        cookie.put(DOMAIN, c.getDomain());
        cookie.put(PATH, c.getPath());
        if (c.getExpiryDate() != null) {
            cookie.put(EXPIRES, c.getExpiryDate().getTime() + "");
        }
        cookie.put(PERSISTENT, c.isPersistent() + "");
        cookie.put(SECURE, c.isSecure() + "");
        response.addCookie(cookie);
    }
    cookieStore.clear(); // we rely on the StepDefs for cookie 'persistence'
    for (Header header : httpResponse.getAllHeaders()) {
        response.addHeader(header.getName(), header.getValue());
    }
    return response;
}
 
开发者ID:intuit,项目名称:karate,代码行数:47,代码来源:ApacheHttpClient.java

示例12: downloadHTTPfile

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private byte[] downloadHTTPfile(String fileToDownloadLocation) throws IOException, NullPointerException, URISyntaxException {
  	
      URL fileToDownload = new URL(fileToDownloadLocation);
      
      File downloadedFile = new File(this.localDownloadPath + fileToDownload.getFile().replaceFirst("/|\\\\", ""));
      if (downloadedFile.canWrite() == false) downloadedFile.setWritable(true);
 
      @SuppressWarnings("resource")
HttpClient client = new DefaultHttpClient();
      BasicHttpContext localContext = new BasicHttpContext();
 
      LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState);
      if (this.mimicWebDriverCookieState) {
          localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies()));
      }
      
      HttpGet httpget = new HttpGet(fileToDownload.toURI());
      HttpParams httpRequestParameters = httpget.getParams();
      httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
      httpget.setParams(httpRequestParameters);
 
      LOG.info("Sending GET request for: " + httpget.getURI());
      HttpResponse response = client.execute(httpget, localContext);
      this.httpStatusOfLastDownloadAttempt = response.getStatusLine().getStatusCode();
      LOG.info("HTTP GET request status: " + this.httpStatusOfLastDownloadAttempt);
      LOG.info("Downloading file: " + downloadedFile.getName());

      byte[] file = IOUtils.toByteArray(response.getEntity().getContent());
      response.getEntity().getContent().close();
      return file;
  }
 
开发者ID:GovernIB,项目名称:helium,代码行数:32,代码来源:FileDownloader.java

示例13: postDownloaderWithRedirects

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
public byte[] postDownloaderWithRedirects(String formToDownloadLocation, List<NameValuePair> params) throws IOException, NullPointerException, URISyntaxException {
	
    HttpClient client = new DefaultHttpClient();
    BasicHttpContext localContext = new BasicHttpContext();
 
    LOG.info("Mimic WebDriver cookie state: " + this.mimicWebDriverCookieState);
    if (this.mimicWebDriverCookieState) {
        localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(this.driver.manage().getCookies()));
    }
 
    HttpResponse response = realizaPeticion(null, client, localContext, formToDownloadLocation, params, null);
    
    boolean segueixRedirs = true;
    while (response.getStatusLine().getStatusCode()==302 && segueixRedirs) {
    	try {
    		String URLaux   = formToDownloadLocation.substring(0, formToDownloadLocation.lastIndexOf("/")+1);
    		String nuevaURL = URLaux + response.getHeaders("RedirectTo")[0].getValue();
    		response = realizaPeticion(response, client, localContext, nuevaURL, params, response.getParams());
    	}catch (Exception ex) {
    		segueixRedirs = false;
    	}
    }
    
    this.httpStatusOfLastDownloadAttempt = response.getStatusLine().getStatusCode();
    LOG.info("HTTP GET request status: " + this.httpStatusOfLastDownloadAttempt);
 
    byte[] file = IOUtils.toByteArray(response.getEntity().getContent());
    response.getEntity().getContent().close();
    return file;
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:31,代码来源:FileDownloader.java

示例14: buildBasicHttpContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private void buildBasicHttpContext()
{
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.overrideParamter("nc", String.valueOf(serverNounceCount++));
    digestScheme.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
    digestScheme.overrideParamter("qop", "auth");
    authCache.put(target, digestScheme);
    
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:13,代码来源:RestUtils.java

示例15: buildBasicHttpContext

import org.apache.http.protocol.BasicHttpContext; //导入方法依赖的package包/类
private void buildBasicHttpContext()
{
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.overrideParamter("nc", String.valueOf(serverNounceCount++));
    digestScheme.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
    digestScheme.overrideParamter("qop", "auth");
    authCache.put(target, digestScheme);

    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:13,代码来源:RestUtils.java


注:本文中的org.apache.http.protocol.BasicHttpContext.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。