List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager
public PoolingHttpClientConnectionManager()
From source file:dal.arris.RequestArrisAlter.java
public RequestArrisAlter(Integer deviceId, Autenticacao autenticacao, String frequency) throws UnsupportedEncodingException, IOException { Autenticacao a = AuthFactory.getEnd(); String auth = a.getUser() + ":" + a.getPassword(); String url = a.getLink() + "capability/execute?capability=" + URLEncoder.encode("\"getLanWiFiInfo\"", "UTF-8") + "&deviceId=" + deviceId + "&input=" + URLEncoder.encode(frequency, "UTF-8"); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(1);/* w ww .j a v a2 s .c o m*/ cm.setDefaultMaxPerRoute(1); HttpHost localhost = new HttpHost("10.200.6.150", 80); cm.setMaxPerRoute(new HttpRoute(localhost), 50); // Cookies RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build(); CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm) .setDefaultRequestConfig(globalConfig).build(); byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8"))); String authHeader = "Basic " + new String(encodedAuth); // CloseableHttpClient httpclient = HttpClients.createDefault(); try { HttpGet httpget = new HttpGet(url); httpget.setHeader(HttpHeaders.AUTHORIZATION, authHeader); httpget.setHeader(HttpHeaders.CONTENT_TYPE, "text/html"); httpget.setHeader("Cookie", "JSESSIONID=aaazqNDcHoduPbavRvVUv; AX-CARE-AGENTS-20480=HECDMIAKJABP"); RequestConfig localConfig = RequestConfig.copy(globalConfig).setCookieSpec(CookieSpecs.STANDARD_STRICT) .build(); HttpGet httpGet = new HttpGet("/"); httpGet.setConfig(localConfig); // httpget.setHeader(n); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to bother about connection release if (entity != null) { InputStream instream = entity.getContent(); try { instream.read(); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); } // do something useful with the response } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw ex; } finally { // Closing the input stream will trigger connection release instream.close(); } } } finally { response.close(); for (Header allHeader : response.getAllHeaders()) { System.out.println("Nome: " + allHeader.getName() + " Valor: " + allHeader.getValue()); } } } finally { httpclient.close(); } httpclient.close(); }
From source file:de.micromata.genome.tpsb.httpClient.HttpClientTestBuilder.java
public HttpClientTestBuilder createHttpClient() { PoolingHttpClientConnectionManager conManager = new PoolingHttpClientConnectionManager(); conManager.setMaxTotal(maxTotalConnection); conManager.setDefaultMaxPerRoute(maxPerHostConnection); final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeout) .setSocketTimeout(readTimeout).build(); final HttpClientBuilder httpClientBuilder = HttpClients.custom().setConnectionManager(conManager) // .setDefaultRequestConfig(requestConfig); httpClient = httpClientBuilder.build(); return getBuilder(); }
From source file:fi.csc.kapaVirtaAS.VirtaClient.java
public VirtaClient(ASConfiguration conf) { cm = new PoolingHttpClientConnectionManager(); Integer poolSize = new Integer(conf.getAdapterServiceConnectionPoolSize()); cm.setMaxTotal(poolSize != null ? poolSize.intValue() : 10); client = HttpClients.custom().setConnectionManager(cm).build(); }
From source file:ca.islandora.alpaca.http.client.StaticTokenRequestInterceptor.java
/** * Convenience factory method./* w w w . ja va 2s.co m*/ * * @param interceptor the interceptor to use, presumably an instance of {@link StaticTokenRequestInterceptor} * @return a default-configuration {@link HttpClient} that is wrapped with this interceptor */ public static HttpClient defaultClient(final StaticTokenRequestInterceptor interceptor) { final PoolingHttpClientConnectionManager connMan = new PoolingHttpClientConnectionManager(); return HttpClientBuilder.create().setConnectionManager(connMan).setConnectionManagerShared(true) .addInterceptorFirst(interceptor).build(); }
From source file:com.arcbees.vcs.util.HttpClientWrapperImpl.java
private CloseableHttpClient initHttpClient() { RequestConfig requestConfig = getRequestConfig(); String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion(); connectionManager = new PoolingHttpClientConnectionManager(); return HttpClientBuilder.create().useSystemProperties().addInterceptorFirst(new RequestAcceptEncoding()) .addInterceptorFirst(new ResponseContentEncoding()) .setRetryHandler(new DefaultHttpRequestRetryHandler(RETRY_COUNT, true)) .setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig) .setUserAgent("JetBrains TeamCity " + serverVersion).build(); }
From source file:org.terasology.telemetry.TelemetryEmitter.java
private static HttpClientAdapter getDefaultAdapter(URL url) { // Make a new client with custom concurrency rules PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(); manager.setDefaultMaxPerRoute(50);//from w ww . java 2s . co m // Make the client CloseableHttpClient client = HttpClients.custom().setConnectionManager(manager).build(); // Build the adapter return ApacheHttpClientAdapter.builder().url(url.toString()).httpClient(client).build(); }
From source file:com.github.triceo.robozonky.ApiProvider.java
private static ResteasyClientBuilder newResteasyClientBuilder() { final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); final CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().setConnectionManager(cm).build(); final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(closeableHttpClient); final ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder().httpEngine(engine); clientBuilder.providerFactory(ApiProvider.RESTEASY); return clientBuilder; }
From source file:piecework.content.concrete.RemoteContentProvider.java
@PostConstruct public void init() { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100);//from ww w.j a v a 2 s. c o m this.client = HttpClients.custom().setConnectionManager(cm).build(); }
From source file:com.arrow.acs.client.api.ConnectionManager.java
private ConnectionManager() { connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(maxTotalConnections); connectionManager.setDefaultMaxPerRoute(maxPerRouteConnections); restartExpiredTimer();/*from www . jav a 2 s .c om*/ }
From source file:com.kurtraschke.wsf.gtfsrealtime.WSFRealtimeModule.java
@Override protected void configure() { bind(HttpClientConnectionManager.class).toInstance(new PoolingHttpClientConnectionManager()); bind(ScheduledExecutorService.class).toInstance(Executors.newSingleThreadScheduledExecutor()); bind(CalendarServiceData.class).toProvider(CalendarServiceDataProvider.class).in(Scopes.SINGLETON); bind(GtfsRelationalDao.class).toProvider(GtfsRelationalDaoProvider.class).in(Scopes.SINGLETON); bind(TimeZone.class).annotatedWith(AgencyTimeZone.class).toProvider(AgencyTimeZoneProvider.class) .in(Scopes.SINGLETON);// w ww . j av a 2 s . c om }