List of usage examples for org.apache.http.params CoreConnectionPNames SO_TIMEOUT
String SO_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames SO_TIMEOUT.
Click Source Link
From source file:com.puppetlabs.puppetdb.javaclient.impl.DefaultModule.java
@Override protected void configure() { bind(APIPreferences.class).toInstance(preferences); bind(Integer.class).annotatedWith(Names.named(CoreConnectionPNames.CONNECTION_TIMEOUT)) .toInstance(preferences.getConnectTimeout()); bind(Integer.class).annotatedWith(Names.named(CoreConnectionPNames.SO_TIMEOUT)) .toInstance(preferences.getSoTimeout()); bind(Gson.class).toProvider(GsonProvider.class); if (preferences.getCertPEM() != null) bind(SSLSocketFactory.class).toProvider(PEM_SSLSocketFactoryProvider.class).in(Singleton.class); else/*from w ww. j a va 2s .co m*/ bind(SSLSocketFactory.class).toInstance(SSLSocketFactory.getSocketFactory()); bind(HttpConnector.class).to(HttpComponentsConnector.class); bind(PuppetDBClient.class).to(PuppetDBClientImpl.class); }
From source file:com.almende.util.ApacheHttpClient.java
/** * Instantiates a new apache http client. * /* www . j a v a 2 s . c om*/ */ private ApacheHttpClient() { // generate httpclient httpClient = new DefaultHttpClient(); // Set cookie policy and persistent cookieStore try { httpClient.setCookieStore(new MyCookieStore()); } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to initialize persistent cookieStore!", e); } final HttpParams params = httpClient.getParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); httpClient.setParams(params); }
From source file:org.mskcc.cbio.portal.web_api.ConnectionManager.java
/** * Get a HttpClient//from w w w. j a va 2 s .co m * @param timeOut milliseconds * @return */ public static HttpClient getHttpClient(int timeOut) { if (timeOut <= 0) { return new HttpClient(getConnectionManager()); } else { HttpClientParams params = new HttpClientParams(); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut); return new HttpClient(params, getConnectionManager()); } }
From source file:org.hydracache.server.httpd.HttpParamsFactoryTest.java
@Test public void testSocketTimeoutSetting() { HttpParamsFactory factory = new HttpParamsFactory(); int expectedSocketTimeout = 500; factory.setSocketTimeout(expectedSocketTimeout); HttpParams params = factory.create(); assertEquals("Socket timeout is not correctly set", expectedSocketTimeout, params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0)); }
From source file:net.evendanan.android.thumbremote.network.ReusableHttpClientBlocking.java
ReusableHttpClientBlocking(int timeout, String user, String password) { Log.d(TAG, "Creating a new HTTP client"); mHttpClient = new DefaultHttpClient(); if (!TextUtils.isEmpty(password)) { CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); mHttpClient.setCredentialsProvider(credProvider); }// w w w. ja v a2 s . co m mRequest = new HttpGet(); mRequest.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(timeout)); mRequest.getParams().setParameter(CoreConnectionPNames.SO_LINGER, new Integer(timeout / 2)); mRequest.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(timeout)); }
From source file:base.tina.external.http.HttpTask.java
@Override public final void run() throws Exception { if (httpPlugin == null || httpPlugin.url == null) return;/* w w w.j a v a2 s . c o m*/ //#debug base.tina.core.log.LogPrinter.d(null, "-----------" + httpPlugin.url + "-----------"); httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); HttpResponse response; if (httpPlugin.requestData == null && httpPlugin.requestDataInputStream == null) { HttpGet getRequest = new HttpGet(URI.create(httpPlugin.url)); request = getRequest; response = httpClient.execute(getRequest); } else { HttpPost requestPost = new HttpPost(URI.create(httpPlugin.url)); request = requestPost; // request.setHeader("Connention", "close"); if (httpPlugin.requestDataInputStream != null) { InputStream instream = httpPlugin.requestDataInputStream; InputStreamEntity inputStreamEntity = new InputStreamEntity(instream, httpPlugin.dataLength); requestPost.setEntity(inputStreamEntity); } else { InputStream instream = new ByteArrayInputStream(httpPlugin.requestData); InputStreamEntity inputStreamEntity = new InputStreamEntity(instream, httpPlugin.requestData.length); requestPost.setEntity(inputStreamEntity); } response = httpClient.execute(requestPost); } if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { httpPlugin.parseData(EntityUtils.toByteArray(response.getEntity())); commitResult(httpPlugin, CommitAction.WAKE_UP); } else { //#debug error base.tina.core.log.LogPrinter.e(null, "Http error : " + new String(EntityUtils.toByteArray(response.getEntity()))); throw new Exception("Http response code is : " + response.getStatusLine().getStatusCode()); } }
From source file:org.devtcg.five.util.streaming.LocalHttpServer.java
public LocalHttpServer() { super("LocalHttpServer"); mParams = new BasicHttpParams(); mParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); setDaemon(true);/*from w w w .j ava 2s . c om*/ }
From source file:org.xwiki.extension.repository.xwiki.internal.httpclient.DefaultHttpClientFactory.java
@Override public HttpClient createClient(String user, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.configuration.getUserAgent()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // Setup proxy ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); // Setup authentication if (user != null) { httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); }//from ww w . j a v a 2 s .co m return httpClient; }
From source file:se.ginkou.interfaceio.InterfaceServer.java
public static void startServer() throws Exception { // HTTP parameters for the server HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); // Create HTTP protocol processing chain HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { // Use standard server-side protocol interceptors new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry(); reqistry.register("*/datatables", new DataTablesHandler()); reqistry.register("*/loginmodules", new RuleFileHandler()); reqistry.register("*/login", new LoginHandler()); reqistry.register("*", new HttpFileHandler(new File("website"))); reqistry.register("*/ping", new TestHandler()); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) {//from w w w .j av a 2s . c o m @Override public void connected(final NHttpServerConnection conn) { System.out.println(conn + ": connection open"); super.connected(conn); } @Override public void closed(final NHttpServerConnection conn) { System.out.println(conn + ": connection closed"); super.closed(conn); } }; // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory; // // Initialize SSL context // ClassLoader cl = NHttpServer.class.getClassLoader(); // URL url = cl.getResource("my.keystore"); // if (url == null) { // System.out.println("Keystore not found"); // System.exit(1); // } // KeyStore keystore = KeyStore.getInstance("jks"); // keystore.load(url.openStream(), "secret".toCharArray()); // KeyManagerFactory kmfactory = KeyManagerFactory.getInstance( // KeyManagerFactory.getDefaultAlgorithm()); // kmfactory.init(keystore, "secret".toCharArray()); // KeyManager[] keymanagers = kmfactory.getKeyManagers(); // SSLContext sslcontext = SSLContext.getInstance("TLS"); // sslcontext.init(keymanagers, null, null); // connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params); connFactory = new DefaultNHttpServerConnectionFactory(params); // Create server-side I/O event dispatch IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); // Create server-side I/O reactor ListeningIOReactor ioReactor = new DefaultListeningIOReactor(); try { // Listen of the given port ioReactor.listen(new InetSocketAddress(PORT)); // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); }
From source file:de.hybris.platform.mpintgproductcockpit.productcockpit.util.HttpInvoker.java
public String post(final String reqURL, final String reqStr, final String charset, final int timeout) { // Prepare HTTP post final HttpPost post = new HttpPost(reqURL); post.setHeader("Content-Type", "application/json"); // set content type as json and charset final StringEntity reqEntity = new StringEntity(reqStr, ContentType.create("application/json", charset)); post.setEntity(reqEntity);// w w w . j a va2 s. co m // Create HTTP client final HttpClient httpClient = new DefaultHttpClient(); // set connection over time httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(timeout / 2)); // set data loading over time httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(timeout / 2)); // Execute request try { final HttpResponse response = httpClient.execute(post); // get response and return as String final HttpEntity responseEntity = response.getEntity(); return EntityUtils.toString(responseEntity); } catch (final Exception e) { return null; } finally { post.releaseConnection(); } }