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


Java HttpContext.getAttribute方法代码示例

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


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

示例1: createOkResponseWithCookie

import org.apache.http.protocol.HttpContext; //导入方法依赖的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: process

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {

            AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);

            if (authState.getAuthScheme() != null || authState.hasAuthOptions()) {
                return;
            }

            // If no authState has been established and this is a PUT or POST request, add preemptive authorisation
            String requestMethod = request.getRequestLine().getMethod();
            if (alwaysSendAuth || requestMethod.equals(HttpPut.METHOD_NAME) || requestMethod.equals(HttpPost.METHOD_NAME)) {
                CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
                Credentials credentials = credentialsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
                if (credentials == null) {
                    throw new HttpException("No credentials for preemptive authentication");
                }
                authState.update(authScheme, credentials);
            }
        }
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:HttpClientConfigurer.java

示例3: getModSlug0

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Nullable
private String getModSlug0(int id)
{
    try
    {
        log.debug("Getting mod slug from server...");
        URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
        HttpGet request = new HttpGet(uri.toURL().toString());
        HttpContext context = new BasicHttpContext();
        HttpResponse response = http.execute(request, context);
        EntityUtils.consume(response.getEntity());
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
        HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
        String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
        Splitter splitter = Splitter.on('/').omitEmptyStrings();
        List<String> pathParts = splitter.splitToList(currentUrl);
        return pathParts.get(pathParts.size() - 1);
    }
    catch (Exception e)
    {
        log.error("Failed to perform request from CurseForge site.", e);
        return null;
    }
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:25,代码来源:CurseAPI.java

示例4: authFailed

import org.apache.http.protocol.HttpContext; //导入方法依赖的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

示例5: createLayeredSocket

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public Socket createLayeredSocket(final Socket socket, final String target, final int port,
                                  final HttpContext context) throws IOException {
    Boolean enableSniValue = (Boolean) context.getAttribute(ENABLE_SNI);
    boolean enableSni = enableSniValue == null || enableSniValue;
    return super.createLayeredSocket(socket, enableSni ? target : "", port, context);
}
 
开发者ID:doubleview,项目名称:fastcrawler,代码行数:8,代码来源:SniSSLConnectionSocketFactory.java

示例6: requestReady

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public void requestReady(NHttpClientConnection conn) throws IOException, HttpException {
	try {
		super.requestReady(conn);
	} catch (Exception ex) {
		LOGGER.error("", ex);
	}

	// 需要自动关闭连接
	if (this.liveTime > 0) {
		HttpRequest httpRequest = conn.getHttpRequest();
		if (httpRequest == null) {
			return;
		}

		HttpContext context = conn.getContext();

		long currentTimeMillis = System.currentTimeMillis();
		Object oldTimeMillisObj = context.getAttribute("t");
		if (oldTimeMillisObj == null) {
			context.setAttribute("t", currentTimeMillis);
		} else {
			long oldTimeMillis = (Long) oldTimeMillisObj;
			long dt = currentTimeMillis - oldTimeMillis;
			if (dt > 1000 * liveTime) { // 超时,重连
				tryCloseConnection(httpRequest);
				context.setAttribute("t", currentTimeMillis);
			}
		}
	}
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:32,代码来源:HiTSDBHttpAsyncCallbackExecutor.java

示例7: retryRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean sent;
    boolean retry = true;
    Boolean b = (Boolean) context.getAttribute("http.request_sent");
    if (b == null || !b.booleanValue()) {
        sent = false;
    } else {
        sent = true;
    }
    if (executionCount > this.maxRetries) {
        retry = false;
    } else if (isInList(exceptionBlacklist, exception)) {
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        retry = true;
    } else if (!sent) {
        retry = true;
    }
    if (retry) {
        if (((HttpUriRequest) context.getAttribute("http.request")).getMethod().equals("POST")) {
            retry = false;
        } else {
            retry = true;
        }
    }
    if (retry) {
        SystemClock.sleep(1500);
    } else {
        exception.printStackTrace();
    }
    return retry;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:33,代码来源:RetryHandler.java

示例8: createAsyncRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	HttpAsyncClient asyncClient = getHttpAsyncClient();
	startAsyncClient();
	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
       HttpContext context = createHttpContext(httpMethod, uri);
       if (context == null) {
           context = HttpClientContext.create();
       }
       // Request configuration not set in the context
       if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
           // Use request configuration given by the user, when available
           RequestConfig config = null;
           if (httpRequest instanceof Configurable) {
               config = ((Configurable) httpRequest).getConfig();
           }
           if (config == null) {
               config = RequestConfig.DEFAULT;
           }
           context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
       }
	return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HttpComponentsAsyncClientHttpRequestFactory.java

示例9: createRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
	CloseableHttpClient client = (CloseableHttpClient) getHttpClient();
	Assert.state(client != null, "Synchronous execution requires an HttpClient to be set");
	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
       HttpContext context = createHttpContext(httpMethod, uri);
       if (context == null) {
           context = HttpClientContext.create();
       }
       // Request configuration not set in the context
       if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
           // Use request configuration given by the user, when available
           RequestConfig config = null;
           if (httpRequest instanceof Configurable) {
               config = ((Configurable) httpRequest).getConfig();
           }
           if (config == null) {
               if (this.socketTimeout > 0 || this.connectTimeout > 0) {
                   config = RequestConfig.custom()
                           .setConnectTimeout(this.connectTimeout)
                           .setSocketTimeout(this.socketTimeout)
                           .build();
               }
			else {
                   config = RequestConfig.DEFAULT;
               }
           }
           context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
       }
	if (this.bufferRequestBody) {
		return new HttpComponentsClientHttpRequest(client, httpRequest, context);
	}
	else {
		return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:HttpComponentsClientHttpRequestFactory.java

示例10: process

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    // Obtain the client connection (required)
    HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        this.log.debug("HTTP connection not set in the context");
        return;
    }

    HttpRoute route = conn.getRoute();

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:RequestClientConnControl.java

示例11: process

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
        return;
    }

    HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        this.log.debug("HTTP connection not set in the context");
        return;
    }
    HttpRoute route = conn.getRoute();
    if (route.isTunnelled()) {
        return;
    }

    // Obtain authentication state
    AuthState authState = (AuthState) context.getAttribute(
            ClientContext.PROXY_AUTH_STATE);
    if (authState == null) {
        this.log.debug("Proxy auth state not set in the context");
        return;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Proxy auth state: " + authState.getState());
    }
    process(authState, request, context);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:RequestProxyAuthentication.java

示例12: authSucceeded

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    if (isCachable(authScheme)) {
        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,代码行数:16,代码来源:AuthenticationStrategyAdaptor.java

示例13: retryRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b);

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
    }

    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:38,代码来源:RetryHandler.java

示例14: retryRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b);

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:40,代码来源:RetryHandler.java

示例15: retryRequest

import org.apache.http.protocol.HttpContext; //导入方法依赖的package包/类
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean sent;
    boolean retry = true;
    Boolean b = (Boolean) context.getAttribute("http.request_sent");
    if (b == null || !b.booleanValue()) {
        sent = false;
    } else {
        sent = true;
    }
    if (executionCount > this.maxRetries) {
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        retry = false;
    } else if (!sent) {
        retry = true;
    }
    if (retry && ((HttpUriRequest) context.getAttribute("http.request")) == null) {
        return false;
    }
    if (retry) {
        SystemClock.sleep((long) this.retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }
    return retry;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:29,代码来源:RetryHandler.java


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