List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:com.vk.sdk.api.httpClient.VKHttpClient.java
/** * Creates the http client (if need). Returns reusing client * * @return Prepared client used for API requests loading *///from ww w. j ava 2 s . co m public static VKHttpClient getClient() { if (sInstance == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); Context ctx = VKUIHelper.getApplicationContext(); try { if (ctx != null) { PackageManager packageManager = ctx.getPackageManager(); if (packageManager != null) { PackageInfo info = packageManager.getPackageInfo(ctx.getPackageName(), 0); params.setParameter(CoreProtocolPNames.USER_AGENT, String.format(Locale.US, "%s/%s (%s; Android %d; Scale/%.2f; VK SDK %s; %s)", VKUtil.getApplicationName(ctx), info.versionName, Build.MODEL, Build.VERSION.SDK_INT, ctx.getResources().getDisplayMetrics().density, VKSdkVersion.SDK_VERSION, info.packageName)); } } } catch (Exception ignored) { } sInstance = new VKHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); } return sInstance; }
From source file:com.ratusapparatus.tapsaff.TapsAff.java
protected String doInBackground(String... urls) { String result = ""; try {// w ww . j av a2 s .com Log.i("tapsaffdoInBackground", urls[0]); DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); HttpGet get = new HttpGet(urls[0]); get.setHeader("Content-type", "application/json"); InputStream inputStream = null; HttpResponse response = httpclient.execute(get); HttpEntity entity = response.getEntity(); inputStream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } result = sb.toString(); } catch (Exception e) { Log.e("tapsaff", "getjson", e); } return result; }
From source file:com.phonty.improved.Calls.java
public Calls(String url, Context _context) { context = _context;/*from w w w .java2s .c o m*/ APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); VALUES = new ArrayList<CallItem>(); type = "Calls:"; }
From source file:com.phonty.improved.Rates.java
public Rates(String url, Context _context) { context = _context;/*w w w .j av a 2s .c om*/ APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); VALUES = new ArrayList<PriceItem>(); type = "Calls:"; }
From source file:com.hoccer.api.RESTfulApiTest.java
public RESTfulApiTest() { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); ConnManagerParams.setMaxTotalConnections(httpParams, 100); HttpConnectionParams.setStaleCheckingEnabled(httpParams, true); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); mHttpClient = new HttpClientWithKeystore(cm, httpParams); }
From source file:org.openremote.android.console.net.ORControllerServerSwitcher.java
/** * Detect the groupmembers of current server url *//* ww w. ja v a 2 s .co m*/ public static boolean detectGroupMembers(Context context) { Log.i(LOG_CATEGORY, "Detecting group members with current controller server url " + AppSettingsModel.getCurrentServer(context)); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); HttpClient httpClient = new DefaultHttpClient(params); String url = AppSettingsModel.getSecuredServer(context); HttpGet httpGet = new HttpGet(url + "/rest/servers"); if (httpGet == null) { Log.e(LOG_CATEGORY, "Create HttpRequest fail."); return false; } SecurityUtil.addCredentialToHttpRequest(context, httpGet); // TODO : fix the exception handling in this method -- it is ridiculous. try { URL uri = new URL(url); if ("https".equals(uri.getProtocol())) { Scheme sch = new Scheme(uri.getProtocol(), new SelfCertificateSSLSocketFactory(context), uri.getPort()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } HttpResponse httpResponse = httpClient.execute(httpGet); try { if (httpResponse.getStatusLine().getStatusCode() == Constants.HTTP_SUCCESS) { InputStream data = httpResponse.getEntity().getContent(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document dom = builder.parse(data); Element root = dom.getDocumentElement(); NodeList nodeList = root.getElementsByTagName("server"); int nodeNums = nodeList.getLength(); List<String> groupMembers = new ArrayList<String>(); for (int i = 0; i < nodeNums; i++) { groupMembers.add(nodeList.item(i).getAttributes().getNamedItem("url").getNodeValue()); } Log.i(LOG_CATEGORY, "Detected groupmembers. Groupmembers are " + groupMembers); return saveGroupMembersToFile(context, groupMembers); } catch (IOException e) { Log.e(LOG_CATEGORY, "The data is from ORConnection is bad", e); } catch (ParserConfigurationException e) { Log.e(LOG_CATEGORY, "Cant build new Document builder", e); } catch (SAXException e) { Log.e(LOG_CATEGORY, "Parse data error", e); } } else { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error"); } } catch (IllegalStateException e) { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error", e); } catch (IOException e) { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error", e); } } catch (MalformedURLException e) { Log.e(LOG_CATEGORY, "Create URL fail:" + url); } catch (ConnectException e) { Log.e(LOG_CATEGORY, "Connection refused: " + AppSettingsModel.getCurrentServer(context), e); } catch (ClientProtocolException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (SocketTimeoutException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (IOException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (IllegalArgumentException e) { Log.e(LOG_CATEGORY, "Host name can be null :" + AppSettingsModel.getCurrentServer(context), e); } return false; }
From source file:com.siahmsoft.soundwaper.net.NetManager.java
private static void setupHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, CONNECTION_TIMEOUT); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(MAX_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(httpParams, MAX_CONNECTIONS); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, HTTP_USER_AGENT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpClient = new DefaultHttpClient(cm, httpParams); }
From source file:com.vk.sdkweb.api.httpClient.VKHttpClient.java
/** * Creates the http client (if need). Returns reusing client * * @return Prepared client used for API requests loading */// w w w . j av a 2s . com public static VKHttpClient getClient() { if (sInstance == null) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); Context ctx = VKUIHelper.getTopActivity(); try { if (ctx != null) { PackageManager packageManager = ctx.getPackageManager(); if (packageManager != null) { PackageInfo info = packageManager.getPackageInfo(ctx.getPackageName(), 0); params.setParameter(CoreProtocolPNames.USER_AGENT, String.format(Locale.US, "%s/%s (%s; Android %d; Scale/%.2f; VK SDK %s; %s)", VKUtil.getApplicationName(ctx), info.versionName, Build.MODEL, Build.VERSION.SDK_INT, ctx.getResources().getDisplayMetrics().density, VKSdkVersion.SDK_VERSION, info.packageName)); } } } catch (Exception ignored) { } sInstance = new VKHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); } return sInstance; }
From source file:com.puppetlabs.puppetdb.javaclient.impl.DefaultModule.java
/** * Provides a HttpClient that is configured with the preferences of this module and the * injected <code>sslSocketFactory</code>. * /*from ww w .j av a2 s . co m*/ * @param sslSocketFactory * The injected SSL socket factory * @return The new HttpClient instance */ @Provides public HttpClient provideHttpClient(SSLSocketFactory sslSocketFactory) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, preferences.getConnectTimeout()); HttpConnectionParams.setSoTimeout(params, preferences.getSoTimeout()); DefaultHttpClient httpClient = new DefaultHttpClient(params); if (preferences.getCertPEM() != null) httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", 443, sslSocketFactory)); return httpClient; }
From source file:com.griddynamics.jagger.invoker.http.HttpInvoker.java
@Override protected HttpParams getHttpClientParams(HttpQuery query) { HttpParams clientParams = new BasicHttpParams(); for (Map.Entry<String, Object> clientParam : query.getClientParams().entrySet()) { clientParams.setParameter(clientParam.getKey(), clientParam.getValue()); }/*from ww w . java 2 s . com*/ return clientParams; }