Android HttpContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android HttpContext class.

This code example shows how to use the following methods:setAttribute
    /** 
     * Sets an optional CookieStore to use when making requests 
     * @param cookieStore The CookieStore implementation to use, usually an instance of {@link PersistentCookieStore} 
     */ 
    public void setCookieStore(CookieStore cookieStore) {
        httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    } 
 
    /** 
     * Overrides the threadpool implementation used when queuing/pooling 
     * requests. By default, Executors.newCachedThreadPool() is used. 
     * @param threadPool an instance of {@link ThreadPoolExecutor} to use for queuing/pooling requests. 
     */ 
    public void setThreadPool(ThreadPoolExecutor threadPool) {
        this.threadPool = threadPool;
    } 
 
    /** 
     * Sets the User-Agent header to be sent with each request. By default, 
     * "Android Asynchronous Http Client/VERSION (http://loopj.com/android-async-http/)" is used. 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAttribute
     * If the authentication failed, this method only responses with 401 
     * Unauthorized. 
     */ 
    @Override 
    public final void handle(final HttpRequest request, final HttpResponse response, HttpContext context) throws HttpException, IOException {
        Object authAttribute = context.getAttribute("authenticated");
 
        if (authAttribute == null || (authAttribute instanceof Boolean && ((Boolean) authAttribute).booleanValue())) {
            getResponse(request, response, context);
            return; 
        } 
 
        AbstractHttpEntity entity = new StringEntity("401 Unauthorized");
        entity.setContentType("text/plain");
        response.setEntity(entity);
        response.setStatusCode(401);
    } 
 
    /** 
     * This method is only called if the authentication was successful. 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAttribute
        HttpClient httpClient = getNewHttpClient();
 
        URL urlObj = new URL(url);
        HttpHost host = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol());
 
        HttpContext credContext = new BasicHttpContext();
        credContext.setAttribute(ClientContext.CREDS_PROVIDER, cp);
 
        HttpGet job = new HttpGet(url);
        HttpResponse response = httpClient.execute(host, job, credContext);
 
        HttpEntity entity = response.getEntity();
        return EntityUtils.toString(entity).toCharArray();
    } 
 
    /** 
     * Gets data from URL as char[] throws {@link RuntimeException} If anything 
     * goes wrong 
     *  
     * @return The content of the URL as a char[] 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAttribute
    @Test 
    public void testParseCookies() throws Exception { 
        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader(SM.SET_COOKIE, "name1=value1");
 
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_ORIGIN, this.cookieOrigin);
        context.setAttribute(ClientContext.COOKIE_SPEC, this.cookieSpec);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
 
        HttpResponseInterceptor interceptor = new ResponseProcessCookies();
        interceptor.process(response, context);
 
        List<Cookie> cookies = this.cookieStore.getCookies();
        Assert.assertNotNull(cookies);
        Assert.assertEquals(1, cookies.size());
        Cookie cookie = cookies.get(0);
        Assert.assertEquals(0, cookie.getVersion());
        Assert.assertEquals("name1", cookie.getName());
        Assert.assertEquals("value1", cookie.getValue());
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAttribute
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAttribute, setAttribute
    protected abstract HttpRequest generateRequest(Job testjob);
 
    public HttpRequest submitRequest(final HttpContext context) {
 
        @SuppressWarnings("unchecked") 
        Queue<Job> queue = (Queue<Job>) context.getAttribute("queue");
        if (queue == null) {
            throw new IllegalStateException("Queue is null");
        } 
 
        Job testjob = queue.poll();
        context.setAttribute("job", testjob);
 
        if (testjob != null) {
            return generateRequest(testjob);
        } else { 
            return null; 
        } 
    } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setAttribute
    } 
 
    @Test 
    public void testConnectionKeepAliveForDirectRequests() throws Exception { 
        HttpRequest request = new BasicHttpRequest("GET", "/");
        HttpContext context = new BasicHttpContext();
 
        HttpHost target = new HttpHost("localhost", 80, "http");
        HttpRoute route = new HttpRoute(target, null, false);
 
        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
 
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
 
        HttpRequestInterceptor interceptor = new RequestClientConnControl();
        interceptor.process(request, context);
 
        Header header1 = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
        Assert.assertNotNull(header1);

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAttribute, setAttribute
 
        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
 
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
 
        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);
 
        CookieSpec cookieSpec = (CookieSpec) context.getAttribute(
                ClientContext.COOKIE_SPEC);
        Assert.assertTrue(cookieSpec instanceof BrowserCompatSpec);
 
        Header[] headers1 = request.getHeaders(SM.COOKIE);
        Assert.assertNotNull(headers1);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAttribute
	public <T> T execute(final HttpUriRequest arg0,
			final ResponseHandler<? extends T> arg1) throws IOException,
			ClientProtocolException { 
 
		// Pre-Process requests 
		final HttpContext context = new BasicHttpContext();
 
		ResponseHandler<? extends T> wrappedHandler = new ResponseHandler<T>() {
 
			@Override 
			public T handleResponse(HttpResponse arg00)
					throws ClientProtocolException, IOException { 
 
				try { 
					httpproc.process(arg00, context);
				} catch (HttpException e) {
					throw new ClientProtocolException(e);
				} 
 
				return arg1.handleResponse(arg00);

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:removeAttribute
    } 
 
    public void release(NHttpClientConnection conn) {
        conn.getMetrics().reset();
        HttpContext ctx = conn.getContext();
        ctx.removeAttribute(ExecutionContext.HTTP_REQUEST);
        ctx.removeAttribute(ExecutionContext.HTTP_RESPONSE);
 
        lock.lock();
        try { 
            if (busyConnections.remove(conn)) {
                freeConnections.add(conn);
            } else { 
                log.error("Attempted to releaseConnection connection not in the busy list");
            } 
        } finally { 
            lock.unlock();
        } 
    } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android HttpContext Questions & Answers:

See Code Examples for Android HttpContext Methods: