Example usage for org.apache.commons.httpclient HttpConnection releaseConnection

List of usage examples for org.apache.commons.httpclient HttpConnection releaseConnection

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpConnection releaseConnection.

Prototype

public void releaseConnection() 

Source Link

Document

Releases the connection.

Usage

From source file:domderrien.wrapper.UrlFetch.UrlFetchConnectionManager.java

public void releaseConnection(HttpConnection connection) {
    connection.releaseConnection();
}

From source file:com.gs.jrpip.client.BufferedPostMethod.java

protected void cleanupConnection(HttpConnection conn) {
    conn.close();
    conn.releaseConnection();
}

From source file:com.exalead.io.failover.HttpConnectionAdapter.java

public void releaseConnection() {
    if (!isLocked() && hasConnection()) {
        HttpConnection wrappedConnection = this.wrappedConnection;
        this.wrappedConnection = null;
        wrappedConnection.releaseConnection();
    } else {//from  w  w w. j  a v  a 2  s .c  o m
        // do nothing
    }
}

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testConnectionReuseWithoutParams() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());

    HttpConnection c1 = manager.getConnection(h1);

    // new connection
    assertTrue(!c1.isOpen());//  w  ww. jav  a 2s. co  m

    c1.open();
    c1.releaseConnection();

    HostConfiguration h2 = new HostConfiguration();
    h2.setHost(address, server1.getLocalPort());

    HttpConnection c2 = manager.getConnection(h2);

    // connection should have been released
    // so c2 is c1
    assertTrue(h2.equals(h1));
    assertTrue(c2 == c1);
    assertTrue(c2.isOpen());

    HttpConnection c3 = manager.getConnection(h2);

    // connection c2 was not released so new connection
    // c2 != c3
    assertTrue(!c3.isOpen());
    assertTrue(c3 != c2);
    assertTrue(c3 != c1);

    c2.releaseConnection();
    c3.releaseConnection();

    Server server2 = new Server();

    // it's a new port
    HostConfiguration h4 = new HostConfiguration();
    h4.setHost(address, server2.getLocalPort());

    HttpConnection c4 = manager.getConnection(h4);

    assertTrue(!c4.isOpen());
    assertTrue(c4 != c1);
    assertTrue(c4 != c2);
    assertTrue(c4 != c3);

    server2.close();
}

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testConnectionReuseWithParams() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(PARAMS);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());
    h1.getParams().setParameter("A", "foo");
    h1.getParams().setParameter("B", "bar");
    h1.getParams().setParameter("C", "fff");

    HttpConnection c1 = manager.getConnection(h1);

    assertTrue(!c1.isOpen());/*from  ww w  . j  a  v a  2s.  c o  m*/
    c1.open();
    c1.releaseConnection();

    HostConfiguration h2 = new HostConfiguration();
    h2.setHost(address, server1.getLocalPort());
    h2.getParams().setParameter("A", "foo");
    h2.getParams().setParameter("B", "bar");
    // still should be reused since C is not checked param
    h2.getParams().setParameter("C", "ggg");

    HttpConnection c2 = manager.getConnection(h2);

    // connection should have been released
    // so c2 is c1
    assertTrue(h2.equals(h1));
    assertTrue(c2.isOpen());
    assertTrue(c2 == c1);

    HttpConnection c3 = manager.getConnection(h2);

    // new connection becuase it wasn't released
    assertTrue(c3 != c1);
    assertTrue(c3 != c2);
    assertTrue(!c3.isOpen());

    c2.releaseConnection();
    c3.releaseConnection();

    // this one does not have params
    HostConfiguration h4 = new HostConfiguration();
    h4.setHost(address, server1.getLocalPort());

    HttpConnection c4 = manager.getConnection(h4);

    // new connection
    assertTrue(c4 != c1);
    assertTrue(c4 != c2);
    assertTrue(c4 != c3);
    assertTrue(!c4.isOpen());

    c4.open();
    c4.releaseConnection();

    // this one only has B parameter
    HostConfiguration h5 = new HostConfiguration();
    h5.setHost(address, server1.getLocalPort());
    h5.getParams().setParameter("B", "bar");

    HttpConnection c5 = manager.getConnection(h5);

    // also a new connection
    assertTrue(c5 != c1);
    assertTrue(c5 != c2);
    assertTrue(c5 != c3);
    assertTrue(c5 != c4);
    assertTrue(!c5.isOpen());

    c5.open();
    c5.releaseConnection();

    // this one only has different B parameter
    HostConfiguration h6 = new HostConfiguration();
    h6.setHost(address, server1.getLocalPort());
    h6.getParams().setParameter("A", "fooo");
    h6.getParams().setParameter("B", "bar");

    HttpConnection c6 = manager.getConnection(h6);

    assertTrue(c6 != c1);
    assertTrue(c6 != c2);
    assertTrue(c6 != c3);
    assertTrue(c6 != c4);
    assertTrue(c6 != c5);
    assertTrue(!c6.isOpen());

    c6.open();
    c6.releaseConnection();
}

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testIdleConnectionSweeper() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null);
    manager.setConnectionIdleTime(1000 * 2);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());

    HttpConnection c1 = manager.getConnection(h1);

    // new connection
    assertTrue(!c1.isOpen());//  w  w w.j  a  v a2 s .  com
    c1.open();

    Thread.sleep(1000);

    c1.releaseConnection();

    assertTrue(c1 == manager.getConnection(h1));
    assertTrue(c1.isOpen());
    c1.releaseConnection();

    Thread.sleep(1000 * 4);

    HttpConnection c2 = manager.getConnection(h1);

    assertTrue(c1 != c2);
}

From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java

public void testMultipleConnectionRelease() throws Exception {
    CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null);

    HostConfiguration h1 = new HostConfiguration();
    h1.setHost(address, server1.getLocalPort());

    HttpConnection c1 = manager.getConnection(h1);

    assertTrue(!c1.isOpen());// www .  j  av a  2  s  .  co m
    c1.open();

    c1.releaseConnection();
    c1.releaseConnection();

    HttpConnection c2 = manager.getConnection(h1);

    assertTrue(c1 == c2);

    HttpConnection c3 = manager.getConnection(h1);

    assertTrue(c3 != c2);
}