本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}