List of usage examples for org.apache.commons.httpclient HttpConnectionManager getConnection
public abstract HttpConnection getConnection(HostConfiguration paramHostConfiguration);
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;/* w w w. ja v a 2s .c o 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; }