List of usage examples for org.apache.http.impl.conn BasicHttpClientConnectionManager BasicHttpClientConnectionManager
public BasicHttpClientConnectionManager()
From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java
@PostConstruct public void start() { _jsonMapper = new ObjectMapper(); _jsonMapper.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE); _xmlMapper = new XmlMapper(); _connectionManager = new BasicHttpClientConnectionManager(); _limiter = RateLimiter.create(_apiRateLimit); if (_apiRateLimit > 9) { _log.warn("API rate limit set to {}, greater than default rate limit of 9 queries/second"); }/*from w w w . j a v a2s . c om*/ }
From source file:com.haulmont.cuba.web.security.idp.IdpSessionPingConnector.java
public void pingIdpSessionServer(String idpSessionId) { log.debug("Ping IDP session {}", idpSessionId); String idpBaseURL = webIdpConfig.getIdpBaseURL(); if (!idpBaseURL.endsWith("/")) { idpBaseURL += "/"; }/*w w w .j ava 2 s . c o m*/ String idpSessionPingUrl = idpBaseURL + "service/ping"; HttpPost httpPost = new HttpPost(idpSessionPingUrl); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType()); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity( Arrays.asList(new BasicNameValuePair("idpSessionId", idpSessionId), new BasicNameValuePair( "trustedServicePassword", webIdpConfig.getIdpTrustedServicePassword())), StandardCharsets.UTF_8); httpPost.setEntity(formEntity); HttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(); HttpClient client = HttpClientBuilder.create().setConnectionManager(connectionManager).build(); try { HttpResponse httpResponse = client.execute(httpPost); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode == 410) { // we have to logout user log.debug("IDP session is expired {}", idpSessionId); if (userSessionSource.checkCurrentUserSession()) { authenticationService.logout(); UserSession userSession = userSessionSource.getUserSession(); throw new NoUserSessionException(userSession.getId()); } } if (statusCode != 200) { log.warn("IDP respond status {} on session ping", statusCode); } } catch (IOException e) { log.warn("Unable to ping IDP {} session {}", idpSessionPingUrl, idpSessionId, e); } finally { connectionManager.shutdown(); } }
From source file:com.cloudera.livy.client.http.LivyConnection.java
LivyConnection(URI uri, final HttpConf config) { HttpClientContext ctx = HttpClientContext.create(); int port = uri.getPort() > 0 ? uri.getPort() : 8998; String path = uri.getPath() != null ? uri.getPath() : ""; this.uriRoot = path + "/clients"; RequestConfig reqConfig = new RequestConfig() { @Override// w w w .j a v a 2s.com public int getConnectTimeout() { return (int) config.getTimeAsMs(CONNETION_TIMEOUT); } @Override public int getSocketTimeout() { return (int) config.getTimeAsMs(SOCKET_TIMEOUT); } }; HttpClientBuilder builder = HttpClientBuilder.create().disableAutomaticRetries().evictExpiredConnections() .evictIdleConnections(config.getTimeAsMs(CONNECTION_IDLE_TIMEOUT), TimeUnit.MILLISECONDS) .setConnectionManager(new BasicHttpClientConnectionManager()) .setConnectionReuseStrategy(new DefaultConnectionReuseStrategy()).setDefaultRequestConfig(reqConfig) .setMaxConnTotal(1).setUserAgent("livy-client-http"); this.server = uri; this.client = builder.build(); this.mapper = new ObjectMapper(); }
From source file:com.spotify.ffwd.signalfx.SignalFxOutputPlugin.java
@Override public Module module(final Key<PluginSink> key, final String id) { return new OutputPluginModule(id) { @Provides/*from ww w . j a v a2s . c om*/ Supplier<AggregateMetricSender> sender() { final Collection<OnSendErrorHandler> handlers = ImmutableList.of(metricError -> { log.error(metricError.toString()); }); return () -> { final SignalFxEndpoint endpoint = new SignalFxEndpoint(); final HttpDataPointProtobufReceiverFactory dataPoints = new HttpDataPointProtobufReceiverFactory( endpoint).setVersion(2); BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(); SocketConfig socketConfigWithSoTimeout = SocketConfig.copy(connectionManager.getSocketConfig()) .setSoTimeout(soTimeout).build(); connectionManager.setSocketConfig(socketConfigWithSoTimeout); dataPoints.setHttpClientConnectionManager(connectionManager); final EventReceiverFactory events = new HttpEventProtobufReceiverFactory(endpoint); final AuthToken auth = new StaticAuthToken(authToken); return new AggregateMetricSender(sourceName, dataPoints, events, auth, handlers); }; } @Override protected void configure() { final Key<SignalFxPluginSink> sinkKey = Key.get(SignalFxPluginSink.class, Names.named("signalfxSink")); bind(sinkKey).to(SignalFxPluginSink.class).in(Scopes.SINGLETON); install(wrapPluginSink(sinkKey, key)); expose(key); } }; }
From source file:org.metaservice.core.AbstractDispatcher.java
protected void sendDataByLoad(URI metadata, Collection<Statement> generatedStatements, Set<Statement> loadedStatements) throws MetaserviceException { StringWriter stringWriter = new StringWriter(); try {/*from w w w . ja va2s .co m*/ NTriplesWriter nTriplesWriter = new NTriplesWriter(stringWriter); Repository inferenceRepository = createTempRepository(true); RepositoryConnection inferenceRepositoryConnection = inferenceRepository.getConnection(); LOGGER.debug("Start inference..."); inferenceRepositoryConnection.add(loadedStatements); inferenceRepositoryConnection.add(generatedStatements); LOGGER.debug("Finished inference"); List<Statement> filteredStatements = getGeneratedStatements(inferenceRepositoryConnection, loadedStatements); nTriplesWriter.startRDF(); for (Statement statement : filteredStatements) { nTriplesWriter.handleStatement(statement); } nTriplesWriter.endRDF(); inferenceRepositoryConnection.close(); inferenceRepository.shutDown(); Executor executor = Executor.newInstance(HttpClientBuilder.create() .setConnectionManager(new BasicHttpClientConnectionManager()).build()); executor.execute(Request.Post(config.getSparqlEndpoint() + "?context-uri=" + metadata.toString()) .bodyStream(new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8")), ContentType.create("text/plain", Charset.forName("UTF-8")))); } catch (RDFHandlerException | IOException | RepositoryException e) { throw new MetaserviceException(e); } }
From source file:org.apache.gobblin.http.ApacheHttpClient.java
private HttpClientConnectionManager getHttpConnManager(Config config) { HttpClientConnectionManager httpConnManager; String connMgrStr = config.getString(HTTP_CONN_MANAGER); switch (ConnManager.valueOf(connMgrStr.toUpperCase())) { case BASIC:// w w w.j av a 2 s .c o m httpConnManager = new BasicHttpClientConnectionManager(); break; case POOLING: PoolingHttpClientConnectionManager poolingConnMgr = new PoolingHttpClientConnectionManager(); poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN)); poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN)); httpConnManager = poolingConnMgr; break; default: throw new IllegalArgumentException(connMgrStr + " is not supported"); } LOG.info("Using " + httpConnManager.getClass().getSimpleName()); return httpConnManager; }
From source file:org.thoughtcrime.securesms.mms.MmsConnection.java
protected CloseableHttpClient constructHttpClient() throws IOException { RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000) .setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build(); return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()) .setRedirectStrategy(new LaxRedirectStrategy()).setUserAgent("Android-Mms/2.0") .setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config) .build();//w w w . j ava2 s . co m }
From source file:gobblin.writer.http.AbstractHttpWriterBuilder.java
public B fromConfig(Config config) { config = config.withFallback(FALLBACK); RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT) .setSocketTimeout(config.getInt(REQUEST_TIME_OUT_MS_KEY)) .setConnectTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY)) .setConnectionRequestTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY)).build(); getHttpClientBuilder().setDefaultRequestConfig(requestConfig); if (config.hasPath(STATIC_SVC_ENDPOINT)) { try {//from w ww.j a va 2 s. c om svcEndpoint = Optional.of(new URI(config.getString(AbstractHttpWriterBuilder.STATIC_SVC_ENDPOINT))); } catch (URISyntaxException e) { throw new RuntimeException(e); } } String connMgrStr = config.getString(HTTP_CONN_MANAGER); switch (ConnManager.valueOf(connMgrStr.toUpperCase())) { case BASIC: httpConnManager = new BasicHttpClientConnectionManager(); break; case POOLING: PoolingHttpClientConnectionManager poolingConnMgr = new PoolingHttpClientConnectionManager(); poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN)); poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN)); httpConnManager = poolingConnMgr; break; default: throw new IllegalArgumentException(connMgrStr + " is not supported"); } LOG.info("Using " + httpConnManager.getClass().getSimpleName()); return typedSelf(); }
From source file:act.installer.bing.BingSearchResults.java
public BingSearchResults(String accountKeyFilepath) { this.cacheOnly = false; this.bingCacheMongoDB = new BingCacheMongoDB(BING_CACHE_HOST, BING_CACHE_MONGO_PORT, BING_CACHE_MONGO_DATABASE);//from ww w . ja v a 2 s .co m this.basicConnManager = new BasicHttpClientConnectionManager(); try { this.accountKey = getAccountKey(accountKeyFilepath); } catch (IOException e) { String msg = String.format("Bing Searcher could not find account key at %s", accountKeyFilepath); LOGGER.error(msg); throw new RuntimeException(msg); } }