Android HttpClientConnection - 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 HttpClientConnection class.

This code example shows how to use the following methods:getSocketTimeout, isOpen
    @Test 
    public void testHttpCreateConnection() throws Exception { 
        host = new HttpHost("localhost", serverPort, "http");
        conn = connFactory.create(host);
 
        assertTrue(conn.isOpen());
        assertEquals(100, conn.getSocketTimeout());
    } 
 
    @Test 
    public void testHttpsCreateConnection() throws Exception { 
        final SocketConfig sconfig = SocketConfig.custom().setSoTimeout(100).build();
        connFactory = new BasicConnFactory(
                null, 
                (SSLSocketFactory)SSLSocketFactory.getDefault(),
                0, sconfig, ConnectionConfig.DEFAULT);
        host = new HttpHost("localhost", sslServerPort, "https");
        conn = connFactory.create(host);
 
        assertTrue(conn.isOpen());
5
CodeRank
This code example shows how to use the following methods:close, shutdown
 
    @After 
    public void tearDown() throws Exception { 
        server.close();
        if(conn != null) {
            conn.close();
            conn.shutdown();
        } 
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testNullConstructor1() throws Exception { 
        new BasicConnPool((HttpParams) null);
    } 
 
    @Test(expected=IllegalArgumentException.class) 
    public void testNullConstructor2() throws Exception { 
        new BasicConnPool((BasicConnFactory) null); 
    } 
 
4
CodeRank
This code example shows how to use the following methods:isOpen
        Mockito.when(connFactory.create(
                Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);
 
        final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
        final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
        Assert.assertNotNull(conn1);
        Assert.assertFalse(conn1.isOpen());
 
        mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);
 
        Assert.assertNull(mgr.getRoute());
        Assert.assertNull(mgr.getState());
 
        final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
        final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
        Assert.assertNotNull(conn2);
        Assert.assertFalse(conn2.isOpen());
 
        Mockito.verify(connFactory, Mockito.times(2)).create(
                Mockito.eq(route), Mockito.<ConnectionConfig>any());
4
CodeRank
This code example shows how to use the following methods:receiveResponseEntity
    } 
 
    public void receiveResponseEntity( 
            final HttpResponse response) throws HttpException, IOException {
        OperatedClientConnection conn = ensureConnection();
        conn.receiveResponseEntity(response);
    } 
 
    public HttpResponse receiveResponseHeader() throws HttpException, IOException {
        OperatedClientConnection conn = ensureConnection();
        return conn.receiveResponseHeader();
    } 
 
    public void sendRequestEntity( 
            final HttpEntityEnclosingRequest request) throws HttpException, IOException {
        OperatedClientConnection conn = ensureConnection();
        conn.sendRequestEntity(request);
    } 
 
    public void sendRequestHeader( 
3
CodeRank
This code example shows how to use the following methods:close
        return this.routeComplete;
    } 
 
    public void closeConnection() throws IOException { 
        final HttpClientConnection conn = getConnection();
        conn.close();
    } 
 
    public void shutdownConnection() throws IOException { 
        final HttpClientConnection conn = getConnection();
        conn.shutdown();
    } 
 
    @Override 
    public boolean isExpired(final long now) {
        final boolean expired = super.isExpired(now);
        if (expired && this.log.isDebugEnabled()) {
            this.log.debug("Connection " + this + " expired @ " + new Date(getExpiry()));
        } 
        return expired;
4
CodeRank
This code example shows how to use the following methods:isOpen
    public void testExecAbortedPriorToConnectionLease() throws Exception { 
        final HttpRoute route = new HttpRoute(target);
        final HttpClientContext context = new HttpClientContext();
        final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
 
        Mockito.when(managedConn.isOpen()).thenReturn(Boolean.FALSE);
        Mockito.when(execAware.isAborted()).thenReturn(Boolean.TRUE);
        try { 
            minimalClientExec.execute(route, request, context, execAware);
        } catch (IOException ex) {
            Mockito.verify(connRequest, Mockito.times(1)).cancel();
            throw ex;
        } 
    } 
 
    @Test(expected=RequestAbortedException.class) 
    public void testExecConnectionRequestFailed() throws Exception { 
        final HttpRoute route = new HttpRoute(target);
        final HttpClientContext context = new HttpClientContext();
        final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
3
CodeRank
See Code Examples for Android HttpClientConnection Methods: