List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:com.android.dialer.omni.PlaceUtil.java
/** * Executes a get request and return byte array * @param url the API URL/*from w w w. j a va 2s . c o m*/ * @return the byte array containing the web page * @throws ClientProtocolException * @throws IOException */ public static byte[] getRequest(String url) throws ClientProtocolException, IOException { if (DEBUG) Log.d(TAG, "download: " + url); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 15000); HttpConnectionParams.setSoTimeout(params, 15000); HttpClient client = new DefaultHttpClient(params); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); byte[] htmlResultPage = null; if (entity != null) { htmlResultPage = EntityUtils.toByteArray(entity); entity.consumeContent(); } return htmlResultPage; }
From source file:org.wso2.emm.agent.proxy.clients.MutualSSLClient.java
public HttpClient getHttpClient() throws IDPTokenManagerException { HttpClient client;/* www . j a v a2 s.c o m*/ try { if (Constants.SERVER_PROTOCOL.equalsIgnoreCase("https://")) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), Constants.HTTP)); SSLSocketFactory sslSocketFactory; AuthenticatorFactory authenticatorFactory = new AuthenticatorFactory(); MutualSSLAuthenticator mutualSSLAuthenticator = (MutualSSLAuthenticator) authenticatorFactory .getClient(Constants.Authenticator.MUTUAL_SSL_AUTHENTICATOR, null, Constants.ADD_HEADER_CALLBACK); sslSocketFactory = new SSLSocketFactory(mutualSSLAuthenticator.getCredentialCertificate(), Constants.KEYSTORE_PASSWORD, localTrustStore); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", sslSocketFactory, Constants.HTTPS)); HttpParams params = new BasicHttpParams(); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); client = new DefaultHttpClient(connectionManager, params); } else { client = new DefaultHttpClient(); } } catch (KeyStoreException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (NoSuchAlgorithmException e) { String errorMsg = "Error occurred while due to mismatch of defined algorithm."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (UnrecoverableKeyException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } catch (KeyManagementException e) { String errorMsg = "Error occurred while accessing keystore."; Log.e(TAG, errorMsg); throw new IDPTokenManagerException(errorMsg, e); } return client; }
From source file:com.nextgis.metroaccess.MetaDownloader.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(moContext)) { try {//from ww w. j a va 2 s.co m String sURL = urls[0]; moHTTPGet = new HttpGet(sURL); Log.d(TAG, "HTTPGet URL " + sURL); HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(moHTTPGet); if (response == null) return null; HttpEntity entity = response.getEntity(); if (moEventReceiver != null) { if (entity != null) { Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, false); msContent = EntityUtils.toString(entity, HTTP.UTF_8); bundle.putString(BUNDLE_PAYLOAD_KEY, msContent); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } else { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkGetErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } else { msError = moContext.getString(R.string.sNetworkUnreachErr); } } } catch (ClientProtocolException e) { msError = e.getMessage(); //cancel(true); } catch (IOException e) { msError = e.getMessage(); //cancel(true); } } else { if (moEventReceiver != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkUnreachErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } } return null; }
From source file:com.louding.frame.http.download.SimpleDownloader.java
/** * ?httpClient/*from w w w . j av a 2 s . c o m*/ */ private void initHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, config.timeOut); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(config.maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, config.maxConnections); HttpConnectionParams.setSoTimeout(httpParams, config.timeOut); HttpConnectionParams.setConnectionTimeout(httpParams, config.timeOut); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, config.socketBuffer); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, "KJLibrary"); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); context = new SyncBasicHttpContext(new BasicHttpContext()); client = new DefaultHttpClient(cm, httpParams); client.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } for (Entry<String, String> entry : config.httpHeader.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase("gzip")) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); client.setHttpRequestRetryHandler(new RetryHandler(config.timeOut)); }
From source file:org.openihs.seendroid.lib.Connection.java
/** * /*from w w w. j a va2s .co m*/ * @param message * @return * @throws ClientProtocolException * @throws IOException */ public HttpResponse query(HttpRequestBase message) throws ClientProtocolException, IOException, UnknownHostException { // SSL fixes (javax.net.ssl.SSLPeerUnverifiedException: No peer certificate) // From http://www.virtualzone.de/2011-02-27/how-to-use-apache-httpclient-with-httpsssl-on-android/ SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); // Real code: DefaultHttpClient client = new DefaultHttpClient(cm, params); HttpResponse response = client.execute(message); return response; }
From source file:com.browsertophone.AppEngineClient.java
private HttpResponse makeRequestNoRetry(String urlPath, List<NameValuePair> params, boolean newToken) throws Exception { // Get auth token for account Account account = new Account(mAccountName, "com.google"); String authToken = getAuthToken(mContext, account); if (authToken == null) throw new PendingAuthException(mAccountName); if (newToken) { // invalidate the cached token AccountManager accountManager = AccountManager.get(mContext); accountManager.invalidateAuthToken(account.type, authToken); authToken = getAuthToken(mContext, account); }//from w w w . j av a 2s.c om // Get ACSID cookie DefaultHttpClient client = new DefaultHttpClient(); String continueURL = BASE_URL; URI uri = new URI(AUTH_URL + "?continue=" + URLEncoder.encode(continueURL, "UTF-8") + "&auth=" + authToken); HttpGet method = new HttpGet(uri); final HttpParams getParams = new BasicHttpParams(); HttpClientParams.setRedirecting(getParams, false); // continue is not used method.setParams(getParams); HttpResponse res = client.execute(method); Header[] headers = res.getHeaders("Set-Cookie"); if (res.getStatusLine().getStatusCode() != 302 || headers.length == 0) { return res; } String ascidCookie = null; for (Header header : headers) { if (header.getValue().indexOf("ACSID=") >= 0) { // let's parse it String value = header.getValue(); String[] pairs = value.split(";"); ascidCookie = pairs[0]; } } // Make POST request uri = new URI(BASE_URL + urlPath); HttpPost post = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); post.setEntity(entity); post.setHeader("Cookie", ascidCookie); post.setHeader("X-Same-Domain", "1"); // XSRF res = client.execute(post); return res; }
From source file:de.codesourcery.eve.skills.market.impl.EveCentralClient.java
/** * Must <b>only</b> be called while {@link #CLIENT_LOCK} * is being held.//from w w w. j a va 2s.co m * * @return */ protected ThreadSafeClientConnManager getConnectionManager() { if (connectionManager == null) { // Create and initialize HTTP parameters final HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 30); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // Create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); } return connectionManager; }
From source file:org.openqa.selenium.remote.internal.HttpClientFactory.java
public HttpParams getHttpParams() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoReuseaddr(params, true); HttpConnectionParams.setConnectionTimeout(params, 120 * 1000); HttpConnectionParams.setSoTimeout(params, TIMEOUT_THREE_HOURS); params.setIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, 0); HttpConnectionParams.setStaleCheckingEnabled(params, true); return params; }
From source file:com.adeven.adjustio.RequestHandler.java
private void initInternal() { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, SOCKET_TIMEOUT); httpClient = new DefaultHttpClient(httpParams); }