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

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

Introduction

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

Prototype

public abstract void releaseConnection(HttpConnection paramHttpConnection);

Source Link

Usage

From source file:org.kei.android.phone.cellhistory.towers.CellIdHelper.java

public static int tryToLocate(final Context context, final TowerInfo ti, int cfg_timeout, final String mode,
        final String apiKeyOpenCellID) {
    int timeout = cfg_timeout * 1000, ret = CellIdRequestEntity.OK;
    HttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    connectionManager.getParams().setConnectionTimeout(timeout);
    connectionManager.getParams().setSoTimeout(timeout);
    // Create a connection to some 'hidden' Google-API
    String baseURL = null;/*from ww  w  .  ja  v a2  s  .co  m*/
    if (mode.equals(OPEN_CELL_ID_API)) {
        ti.lock();
        try {
            baseURL = "http://opencellid.org/cell/get?key=" + apiKeyOpenCellID + "&mcc=" + ti.getMCC() + "&mnc="
                    + ti.getMNC() + "&cellid=" + ti.getCellId() + "&lac=" + ti.getLac() + "&format=json";
        } finally {
            ti.unlock();
        }
    } else
        baseURL = "http://www.google.com/glm/mmap";
    HttpConnection connection = null;
    ti.setCellLatitude(Double.NaN);
    ti.setCellLongitude(Double.NaN);
    try {
        // Setup the connection
        HttpURL httpURL = null;
        if (baseURL.startsWith("https"))
            httpURL = new HttpsURL(baseURL);
        else
            httpURL = new HttpURL(baseURL);
        final HostConfiguration host = new HostConfiguration();
        host.setHost(httpURL.getHost(), httpURL.getPort());
        connection = connectionManager.getConnection(host);
        // Open it
        connection.open();
        if (mode.equals(OPEN_CELL_ID_API))
            ret = new OpenCellIdRequestEntity(ti).decode(baseURL, connection, timeout);
        else
            ret = new GoogleHiddenRequestEntity(ti).decode(baseURL, connection, timeout);
    } catch (Exception e) {
        Log.e(CellIdHelper.class.getSimpleName(), "Exception: " + e.getMessage(), e);
        ret = CellIdRequestEntity.EXCEPTION;
        CellHistoryApp.addLog(context, "tryToLocate::Exception: " + e.getMessage());
    } finally {
        connection.close();
    }
    connectionManager.releaseConnection(connection);
    return ret;
}