List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:org.siddhiesb.transport.http.conn.ServerConnFactory.java
public ServerConnFactory(final HttpRequestFactory requestFactory, final ByteBufferAllocator allocator, final org.siddhiesb.transport.http.conn.SSLContextDetails ssl, final Map<InetSocketAddress, org.siddhiesb.transport.http.conn.SSLContextDetails> sslByIPMap, final HttpParams params) { super();//from www.j a v a 2s .c o m this.requestFactory = requestFactory != null ? requestFactory : new DefaultHttpRequestFactory(); this.allocator = allocator != null ? allocator : new HeapByteBufferAllocator(); this.ssl = ssl; this.sslByIPMap = sslByIPMap != null ? new ConcurrentHashMap<InetSocketAddress, org.siddhiesb.transport.http.conn.SSLContextDetails>( sslByIPMap) : null; this.params = params != null ? params : new BasicHttpParams(); }
From source file:edu.cmu.cylab.starslinger.exchange.WebEngine.java
private byte[] doPost(String uri, byte[] requestBody) throws ExchangeException { mCancelable = false;// w w w .j a va 2 s . c o m // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); if (mHttpClient == null) { mHttpClient = new CheckedHttpClient(params, mCtx); } HttpPost httppost = new HttpPost(uri); BasicResponseHandler responseHandler = new BasicResponseHandler(); byte[] reqData = null; HttpResponse response = null; long startTime = SystemClock.elapsedRealtime(); int statCode = 0; String statMsg = ""; String error = ""; try { // Execute HTTP Post Request httppost.addHeader("Content-Type", "application/octet-stream"); httppost.setEntity(new ByteArrayEntity(requestBody)); response = mHttpClient.execute(httppost); reqData = responseHandler.handleResponse(response).getBytes("8859_1"); } catch (UnsupportedEncodingException e) { error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")"; } catch (HttpResponseException e) { // this subclass of java.io.IOException contains useful data for // users, do not swallow, handle properly e.printStackTrace(); statCode = e.getStatusCode(); statMsg = e.getLocalizedMessage(); error = (String.format(mCtx.getString(R.string.error_HttpCode), statCode) + ", \'" + statMsg + "\'"); } catch (java.io.IOException e) { // just show a simple Internet connection error, so as not to // confuse users e.printStackTrace(); error = mCtx.getString(R.string.error_CorrectYourInternetConnection); } catch (RuntimeException e) { error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")"; } catch (OutOfMemoryError e) { error = mCtx.getString(R.string.error_OutOfMemoryError); } finally { long msDelta = SystemClock.elapsedRealtime() - startTime; if (response != null) { StatusLine status = response.getStatusLine(); if (status != null) { statCode = status.getStatusCode(); statMsg = status.getReasonPhrase(); } } Log.d(TAG, uri + ", " + requestBody.length + "b sent, " + (reqData != null ? reqData.length : 0) + "b recv, " + statCode + " code, " + msDelta + "ms"); } if (!TextUtils.isEmpty(error) || reqData == null) { throw new ExchangeException(error); } return reqData; }
From source file:com.prey.net.PreyRestHttpClient.java
private PreyRestHttpClient(Context ctx) { this.ctx = ctx; httpclient = new PreyDefaultHttpClient((DefaultHttpClient) HttpUtils.getNewHttpClient()); httpclientDefault = new PreyDefaultHttpClient((DefaultHttpClient) HttpUtils.getNewHttpClient()); HttpParams params = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 30000; HttpConnectionParams.setConnectionTimeout(params, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 50000; HttpConnectionParams.setSoTimeout(params, timeoutSocket); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF_8"); HttpProtocolParams.setUseExpectContinue(params, false); HttpParams paramsDefault = params;//w ww . j a v a2 s . c om httpclientDefault.setParams(paramsDefault); HttpProtocolParams.setUserAgent(params, getUserAgent()); httpclient.setParams(params); }
From source file:net.potterpcs.recipebook.DownloadImageTask.java
private Bitmap downloadImage(String... urls) { Bitmap bitmap = null;/*from ww w. j av a 2s . co m*/ RecipeData data = ((RecipeBook) parent.getApplication()).getData(); AndroidHttpClient client = AndroidHttpClient.newInstance("A to Z Recipes for Android"); if (data.isCached(urls[0])) { // Retrieve a cached image if we have one String pathName = data.findCacheEntry(urls[0]); Uri pathUri = Uri.fromFile(new File(parent.getCacheDir(), pathName)); try { bitmap = RecipeBook.decodeScaledBitmap(parent, pathUri); } catch (IOException e) { e.printStackTrace(); bitmap = null; } } else { try { // If the image isn't in the cache, we have to go and get it. // First, we set up the HTTP request. HttpGet request = new HttpGet(urls[0]); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, 60000); request.setParams(params); // Let the UI know we're working. publishProgress(25); // Retrieve the image from the network. HttpResponse response = client.execute(request); publishProgress(50); // Create a bitmap to put in the ImageView. byte[] image = EntityUtils.toByteArray(response.getEntity()); bitmap = BitmapFactory.decodeByteArray(image, 0, image.length); publishProgress(75); // Cache the file for offline use, and to lower data usage. File cachePath = parent.getCacheDir(); String cacheFile = "recipecache-" + Long.toString(System.currentTimeMillis()); if (bitmap.compress(Bitmap.CompressFormat.PNG, 0, new FileOutputStream(new File(cachePath, cacheFile)))) { RecipeData appData = ((RecipeBook) parent.getApplication()).getData(); appData.insertCacheEntry(urls[0], cacheFile); } // Log.v(TAG, cacheFile); // We're done! publishProgress(100); } catch (IOException e) { // TODO Maybe a dialog? } } client.close(); return bitmap; }
From source file:com.piusvelte.sonet.core.SonetHttpClient.java
protected static DefaultHttpClient getThreadSafeClient(Context context) { if (sHttpClient == null) { Log.d(TAG, "create http client"); SocketFactory sf;//from w w w . ja va2 s.c o m try { Class<?> sslSessionCacheClass = Class.forName("android.net.SSLSessionCache"); Object sslSessionCache = sslSessionCacheClass.getConstructor(Context.class).newInstance(context); Method getHttpSocketFactory = Class.forName("android.net.SSLCertificateSocketFactory") .getMethod("getHttpSocketFactory", new Class<?>[] { int.class, sslSessionCacheClass }); sf = (SocketFactory) getHttpSocketFactory.invoke(null, CONNECTION_TIMEOUT, sslSessionCache); } catch (Exception e) { Log.e("HttpClientProvider", "Unable to use android.net.SSLCertificateSocketFactory to get a SSL session caching socket factory, falling back to a non-caching socket factory", e); sf = SSLSocketFactory.getSocketFactory(); } SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT); String versionName; try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { throw new RuntimeException(e); } StringBuilder userAgent = new StringBuilder(); userAgent.append(context.getPackageName()); userAgent.append("/"); userAgent.append(versionName); userAgent.append(" ("); userAgent.append("Linux; U; Android "); userAgent.append(Build.VERSION.RELEASE); userAgent.append("; "); userAgent.append(Locale.getDefault()); userAgent.append("; "); userAgent.append(Build.PRODUCT); userAgent.append(")"); if (HttpProtocolParams.getUserAgent(params) != null) { userAgent.append(" "); userAgent.append(HttpProtocolParams.getUserAgent(params)); } HttpProtocolParams.setUserAgent(params, userAgent.toString()); sHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params); } return sHttpClient; }
From source file:bkampfbot.plan.PlanArbeiten.java
public final static boolean finish() throws FatalError { try {//w ww. j ava2 s .c o m // HTTP parameters stores header etc. HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); HttpGet httpget = new HttpGet(Config.getHost() + "arbeitsamt/index"); httpget.setParams(params); HttpResponse response = Control.current.httpclient.execute(httpget); // obtain redirect target Header locationHeader = response.getFirstHeader("location"); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } if (locationHeader != null) { if (locationHeader.getValue() .equalsIgnoreCase((Config.getHost() + "arbeitsamt/serve").toLowerCase())) { try { JSONTokener js = new JSONTokener(Utils.getString("services/serviceData")); JSONObject result = new JSONObject(js); // [truncated] // {"currentTime":43,"fullTime":3600,"urlCancel":"\/arbeitsamt\/cancel","urlFinish":"\/arbeitsamt\/finish","workTotalTime":"1","workFee":"112","workFeeType":"gold","workText":"Die // Kellnerin im Goldenen Igel kommt nach einem langen int seconds = result.getInt("fullTime") - result.getInt("currentTime") + 20; Output.printTabLn("Letzte Arbeit wurde nicht beendet. Schlafe " + Math.round(seconds / 60) + " Minuten.", 1); // cut it into parts to safe session while (seconds > 600) { // sleep for 10 min Control.sleep(6000, 2); seconds -= 600; Control.current.getCharacter(); } Control.sleep(10 * seconds, 2); Utils.visit("arbeitsamt/finish"); } catch (JSONException e) { Output.error(e); return false; } } else if (locationHeader.getValue() .equalsIgnoreCase((Config.getHost() + "arbeitsamt/finish").toLowerCase())) { Utils.visit("arbeitsamt/finish"); } else { Output.println("Es ging was schief.", 0); return false; } } } catch (IOException e) { Output.println("Es ging was schief.", 0); return false; } return true; }
From source file:fr.forexperts.service.DataService.java
private static ArrayList<String[]> getCsvFromUrl(String url) { ArrayList<String[]> data = new ArrayList<String[]>(); try {// w w w . ja v a2 s. c o m HttpGet httpGet = new HttpGet(url); HttpParams httpParameters = new BasicHttpParams(); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); HttpResponse response = httpClient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { String[] price = line.split(","); data.add(price); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return data; }
From source file:de.hshannover.f4.trust.ifmapj.channel.ApacheCoreCommunicationHandler.java
ApacheCoreCommunicationHandler(String url, String user, String pass, SSLSocketFactory sslSocketFactory, HostnameVerifier verifier, int initialConnectionTimeout) throws InitializationException { super(url, user, pass, sslSocketFactory, verifier, initialConnectionTimeout); mBasicHttpParams = new BasicHttpParams(); }
From source file:org.silvertunnel_ng.demo.download_tool.HttpServiceImpl.java
/** * @see HttpService#initHttpClient()//from w ww . ja v a 2 s . c o m */ public void initHttpClient() { try { // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); // create http client ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(ccm, params); // user agent settings if (USER_AGENT != null) { HttpProtocolParams.setUserAgent(httpClient.getParams(), USER_AGENT); } } catch (Throwable t) { logger.log(Level.WARNING, "initHttpClient()", t); } }
From source file:android.core.TestHttpClient.java
public TestHttpClient() { super();// ww w . ja v a 2s .c om this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1) .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1"); this.httpproc = new BasicHttpProcessor(); // Required protocol interceptors this.httpproc.addInterceptor(new RequestContent()); this.httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors this.httpproc.addInterceptor(new RequestConnControl()); this.httpproc.addInterceptor(new RequestUserAgent()); this.httpproc.addInterceptor(new RequestExpectContinue()); this.httpexecutor = new HttpRequestExecutor(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.context = new BasicHttpContext(null); }