List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:com.amalto.workbench.utils.HttpClientUtil.java
private static DefaultHttpClient createClient() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECT_TIMEOUT); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT); params.setParameter(CoreConnectionPNames.TCP_NODELAY, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); return new DefaultHttpClient(cm, params); }
From source file:cn.xdf.thinkutils.http.HttpUtils.java
public HttpUtils(int connTimeout, String userAgent) { HttpParams params = new BasicHttpParams(); ConnManagerParams.setTimeout(params, connTimeout); HttpConnectionParams.setSoTimeout(params, connTimeout); HttpConnectionParams.setConnectionTimeout(params, connTimeout); if (TextUtils.isEmpty(userAgent)) { userAgent = OtherUtils.getUserAgent(null); }// w w w .j a v a2s.c o m HttpProtocolParams.setUserAgent(params, userAgent); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(10)); ConnManagerParams.setMaxTotalConnections(params, 10); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, 1024 * 8); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", DefaultSSLSocketFactory.getSocketFactory(), 443)); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_RETRY_TIMES)); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(org.apache.http.HttpRequest httpRequest, HttpContext httpContext) throws org.apache.http.HttpException, IOException { if (!httpRequest.containsHeader(HEADER_ACCEPT_ENCODING)) { httpRequest.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext httpContext) throws org.apache.http.HttpException, IOException { 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 GZipDecompressingEntity(response.getEntity())); return; } } } } }); }
From source file:devza.app.android.droidnetkey.FirewallAction.java
public FirewallAction(Context context, boolean status, boolean refresh) { this.context = context; this.fwstatus = status; this.refresh = refresh; client = new StbFwHttpsClient(this.context); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT); HttpConnectionParams.setSoTimeout(params, TIMEOUT); client.setParams(params);/*from www. ja va 2s .co m*/ if (!refresh) this.context.bindService(new Intent(this.context, ConnectionService.class), mConnection, Context.BIND_AUTO_CREATE); }
From source file:org.frameworkset.spi.remote.http.Client.java
public static HttpParams buildHttpParams() { int so_timeout = conparams.getInt("http.socket.timeout", 30);//?? int CONNECTION_TIMEOUT = conparams.getInt("http.connection.timeout", 30); int CONNECTION_Manager_TIMEOUT = conparams.getInt("http.conn-manager.timeout", 2); int httpsoLinger = conparams.getInt("http.soLinger", -1); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, so_timeout * 1000); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT * 1000); HttpConnectionParams.setLinger(params, httpsoLinger); ConnManagerParams.setTimeout(params, CONNECTION_Manager_TIMEOUT * 1000); // params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, // "org.frameworkset.spi.remote.http.BBossClientConnectionManagerFactory"); return params; }
From source file:org.jinos.transport.HttpTransport.java
/** * Call the service//from w w w . ja v a 2 s .c o m * * @param <T> The return type * @param envelope The request envelope * @param resultClass The class of the result in the response * @param httpHeaders The custom Http headers * @return The response * @throws Exception An exception */ public <T> T call(String reqXMLString, Class<T> resultClass, Map<String, String> httpHeaders) throws Exception { try { long start = System.nanoTime(); HttpPost post = new HttpPost(this.getUrl()); post.setEntity(new StringEntity(reqXMLString)); post.setHeader("Content-type", "text/xml; charset=UTF-8"); if (httpHeaders != null) { for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { post.setHeader(entry.getKey(), entry.getValue()); } } /* if (this.getUsername() != null && this.getPassword() != null) { post.addHeader("Authorization", "Basic " + Base64Encoder.encodeString(this.getUsername() + ":" + this.getPassword())); }*/ HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 6000); /* if (this.isDEBUG()) { Log.i(this.getClass().getSimpleName(), "Request: " + envelope.toString()); }*/ HttpClient client = new DefaultHttpClient(httpParameters); HttpResponse response = client.execute(post); int status = response.getStatusLine().getStatusCode(); Log.i(this.getClass().getSimpleName(), "The server has been replied. " + ((System.nanoTime() - start) / 1000) + "us, status is " + status); start = System.nanoTime(); InputStream is = response.getEntity().getContent(); if (true) { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) { sb.append(line); sb.append("\n"); } Log.i(this.getClass().getSimpleName(), "Response: " + sb.toString()); br.close(); isr.close(); is.close(); is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8")); Log.i(this.getClass().getSimpleName(), "DEBUG mode delay: " + ((System.nanoTime() - start) / 1000) + "us"); start = System.nanoTime(); } /* GenericHandler handler = new GenericHandler(resultClass, this.isDEBUG()); if (status == 200) { handler.parseWithPullParser(is); } else { throw new Exception("Can't parse the response, status: " + status); } Log.i(this.getClass().getSimpleName(), "The reply has been parsed: " + ((System.nanoTime() - start) / 1000) + "us"); */ //return (T) handler.getObject(); return null; } catch (Exception e) { Log.e(this.getClass().getSimpleName(), e.toString(), e); throw e; } }
From source file:io.coldstart.android.API.java
public API() { HttpParams params = new BasicHttpParams(); this.client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); this.mgr = new ThreadSafeClientConnManager(params, registry); this.httpclient = new DefaultHttpClient(mgr, client.getParams()); //Timeout ---------------------------------- HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 20000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 30000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); httpclient.setParams(httpParameters); //Timeout ---------------------------------- }
From source file:net.lmxm.ute.executers.tasks.HttpDownloadTaskExecuter.java
/** * Builds the query params.//from ww w . j a va 2 s . c o m * * @param queryParams the query params * @return the http params */ private HttpParams buildQueryParams(final Map<String, String> queryParams) { final HttpParams params = new BasicHttpParams(); // params.setParameter(arg0, arg1) return params; }
From source file:org.openremote.android.console.util.HTTPUtil.java
/** * Down load file and store it in local context. * /*from ww w. jav a 2s . c o m*/ * @param serverUrl the current server url * @param fileName the file name for downloading * * @return the int */ private static int downLoadFile(Context context, String serverUrl, String fileName) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); HttpClient client = new DefaultHttpClient(params); int statusCode = ControllerException.CONTROLLER_UNAVAILABLE; try { URL uri = new URL(serverUrl); if ("https".equals(uri.getProtocol())) { Scheme sch = new Scheme(uri.getProtocol(), new SelfCertificateSSLSocketFactory(context), uri.getPort()); client.getConnectionManager().getSchemeRegistry().register(sch); } HttpGet get = new HttpGet(serverUrl); SecurityUtil.addCredentialToHttpRequest(context, get); HttpResponse response = client.execute(get); statusCode = response.getStatusLine().getStatusCode(); if (statusCode == Constants.HTTP_SUCCESS) { FileOutputStream fOut = context.openFileOutput(fileName, Context.MODE_PRIVATE); InputStream is = response.getEntity().getContent(); byte buf[] = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { fOut.write(buf, 0, len); } fOut.close(); is.close(); } } catch (MalformedURLException e) { Log.e("OpenRemote-HTTPUtil", "Create URL fail:" + serverUrl); } catch (IllegalArgumentException e) { Log.e("OpenRemote-IllegalArgumentException", "Download file " + fileName + " failed with URL: " + serverUrl, e); } catch (ClientProtocolException cpe) { Log.e("OpenRemote-ClientProtocolException", "Download file " + fileName + " failed with URL: " + serverUrl, cpe); } catch (IOException ioe) { Log.e("OpenRemote-IOException", "Download file " + fileName + " failed with URL: " + serverUrl, ioe); } return statusCode; }
From source file:org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule.java
@Singleton @Provides//w ww . ja va 2s. c o m final HttpParams newBasicHttpParams(HttpUtils utils) { BasicHttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "jclouds/1.0"); if (utils.getConnectionTimeout() > 0) { params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, utils.getConnectionTimeout()); } if (utils.getSocketOpenTimeout() > 0) { params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, utils.getSocketOpenTimeout()); } if (utils.getMaxConnections() > 0) ConnManagerParams.setMaxTotalConnections(params, utils.getMaxConnections()); if (utils.getMaxConnectionsPerHost() > 0) { ConnPerRoute connectionsPerRoute = new ConnPerRouteBean(utils.getMaxConnectionsPerHost()); ConnManagerParams.setMaxConnectionsPerRoute(params, connectionsPerRoute); } HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); return params; }
From source file:jetbrains.teamcilty.github.api.impl.HttpClientWrapperImpl.java
public HttpClientWrapperImpl() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { final String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion(); final HttpParams ps = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(ps); final int timeout = TeamCityProperties.getInteger("teamcity.github.http.timeout", 300 * 1000); HttpConnectionParams.setConnectionTimeout(ps, timeout); HttpConnectionParams.setSoTimeout(ps, timeout); HttpProtocolParams.setUserAgent(ps, "JetBrains TeamCity " + serverVersion); final SchemeRegistry schemaRegistry = SchemeRegistryFactory.createDefault(); final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return !TeamCityProperties.getBoolean("teamcity.github.verify.ssl.certificate"); }//w w w.ja va 2 s.com }); schemaRegistry.register(new Scheme("https", 443, sslSocketFactory)); final DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemaRegistry), ps); setupProxy(httpclient); httpclient.setRoutePlanner(new ProxySelectorRoutePlanner( httpclient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault())); httpclient.addRequestInterceptor(new RequestAcceptEncoding()); httpclient.addResponseInterceptor(new ResponseContentEncoding()); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); myClient = httpclient; }