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


Java ClientContext類代碼示例

本文整理匯總了Java中org.apache.http.client.protocol.ClientContext的典型用法代碼示例。如果您正苦於以下問題:Java ClientContext類的具體用法?Java ClientContext怎麽用?Java ClientContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientContext類屬於org.apache.http.client.protocol包,在下文中一共展示了ClientContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createOkResponseWithCookie

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
private Answer<HttpResponse> createOkResponseWithCookie() {
    return new Answer<HttpResponse>() {
        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpContext context = (HttpContext) invocation.getArguments()[1];
            if (context.getAttribute(ClientContext.COOKIE_STORE) != null) {
                BasicCookieStore cookieStore =
                        (BasicCookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
                BasicClientCookie cookie = new BasicClientCookie("cookie", "meLikeCookie");
                cookieStore.addCookie(cookie);
            }

            return OK_200_RESPONSE;
        }
    };
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:17,代碼來源:WebDavStoreTest.java

示例2: getHttpClient

import org.apache.http.client.protocol.ClientContext; //導入依賴的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

示例3: createHttpContext

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
protected HttpContext createHttpContext() {
    HttpContext context = new BasicHttpContext();
    context.setAttribute(
            ClientContext.SCHEME_REGISTRY,
            getConnectionManager().getSchemeRegistry());
    context.setAttribute(
            ClientContext.AUTHSCHEME_REGISTRY,
            getAuthSchemes());
    context.setAttribute(
            ClientContext.COOKIESPEC_REGISTRY,
            getCookieSpecs());
    context.setAttribute(
            ClientContext.COOKIE_STORE,
            getCookieStore());
    context.setAttribute(
            ClientContext.CREDS_PROVIDER,
            getCredentialsProvider());
    return context;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:AbstractHttpClient.java

示例4: authSucceeded

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (authScheme == null) {
        throw new IllegalArgumentException("Auth scheme may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    if (isCachable(authScheme)) {
        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache == null) {
            authCache = new BasicAuthCache();
            context.setAttribute(ClientContext.AUTH_CACHE, authCache);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() +
                    "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:AuthenticationStrategyImpl.java

示例5: authFailed

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
public void authFailed(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    if (authCache != null) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("Clearing cached auth scheme for " + authhost);
        }
        authCache.remove(authhost);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:AuthenticationStrategyImpl.java

示例6: downloadHTTPfile_post

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
private byte[] downloadHTTPfile_post(String formToDownloadLocation, List<NameValuePair> params) throws IOException, NullPointerException, URISyntaxException {
  	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()));
      }
 
      HttpPost httppost = new HttpPost(formToDownloadLocation);
      HttpParams httpRequestParameters = httppost.getParams();
      httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
      httppost.setParams(httpRequestParameters);
      httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
      
      LOG.info("Sending POST request for: " + httppost.getURI());
      @SuppressWarnings("resource")
HttpResponse response = new DefaultHttpClient().execute(httppost, localContext);
      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,代碼行數:25,代碼來源:FileDownloader.java

示例7: getHTTPStatusCode

import org.apache.http.client.protocol.ClientContext; //導入依賴的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

示例8: checkLocalContext

import org.apache.http.client.protocol.ClientContext; //導入依賴的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

示例9: checkLocalContext

import org.apache.http.client.protocol.ClientContext; //導入依賴的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

示例10: process

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    
    // If no auth scheme avaialble yet, try to initialize it preemptively
    if (authState.getAuthScheme() == null) {
        AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
        CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
        HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (authScheme != null) {
            Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
            if (creds == null) {
                throw new HttpException("No credentials for preemptive authentication");
            }
            authState.setAuthScheme(authScheme);
            authState.setCredentials(creds);
        }
    }
    
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:21,代碼來源:HttpSender.java

示例11: process

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    //
    // get the authentication state for the request
    //
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    //
    // if no auth scheme avaialble yet, try to initialize it preemptively
    //
    if (authState.getAuthScheme() == null) {
        // check if credentials are set
        if (this.credentials == null) {
            throw new HttpException("No credentials for preemptive authentication");
        }

        // add the credentials to the auth state
        authState.setAuthScheme(this.basicAuthScheme);
        authState.setCredentials(this.credentials);

        // HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        //CredentialsProvider credsProvider = (CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:24,代碼來源:PreemptiveBasicAuthHttpRequestInterceptor.java

示例12: getHttpClient

import org.apache.http.client.protocol.ClientContext; //導入依賴的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

示例13: process

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    // If no auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
        HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        Credentials credentials = credentialsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (credentials != null) {
            authState.setAuthScheme(new DiadocAuthScheme());
            authState.setCredentials(credentials);
        }
    }
}
 
開發者ID:diadoc,項目名稱:diadocsdk-java,代碼行數:17,代碼來源:DiadocPreemptiveAuthRequestInterceptor.java

示例14: process

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {

    AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider)context
            .getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:22,代碼來源:HttpApiWithBasicAuth.java

示例15: process

import org.apache.http.client.protocol.ClientContext; //導入依賴的package包/類
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {

    AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider)context
            .getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:20,代碼來源:SpecialWebViewActivity.java


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