protected HttpClientBuilder setupClientBuilder() { HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultHeaders(Arrays.asList(new BasicHeader(HttpHeaders.USER_AGENT, userAgent))); builder.setDefaultRequestConfig(setupDefaultRequestConfig().build()); if (config.getUsername() != null) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(config.getUsername(), config.getPassword()) ); builder.setDefaultCredentialsProvider(credentialsProvider); } if (config.getSocketOptions() != null) { final SocketOptionsConfig socketOptions = config.getSocketOptions(); SocketConfig socketConfig = SocketConfig.custom() .setSoTimeout(socketOptions.getSoTimeout()) .setSoKeepAlive(socketOptions.isKeepAlive()) .setSndBufSize(socketOptions.getSndBuffSize()) .setRcvBufSize(socketOptions.getRcvBuffSize()) .build(); builder.setDefaultSocketConfig(socketConfig); } if (config.getConnectionPool() != null) { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(config.getConnectionPool().getTimeToLiveSeconds(), TimeUnit.SECONDS); connectionManager.setDefaultMaxPerRoute(config.getConnectionPool().getMaxPerRoute()); connectionManager.setMaxTotal(config.getConnectionPool().getMaxTotal()); builder.setConnectionManager(connectionManager); } return builder; }
public HttpConnectionPoolConfig toConfig() { return new HttpConnectionPoolConfig( getMaxPerRoute() != null ? getMaxPerRoute() : 0, getMaxTotal() != null ? getMaxTotal() : 0, getTimeToLive() != null ? getTimeToLive() : 0 ); } }
public HttpConnectionPoolConfig toConfig() { return new HttpConnectionPoolConfig( getMaxPerRoute() != null ? getMaxPerRoute() : 0, getMaxTotal() != null ? getMaxTotal() : 0, getTimeToLive() != null ? getTimeToLive() : 0 ); } }
protected HttpClientBuilder setupClientBuilder() { HttpClientBuilder builder = HttpClientBuilder.create(); builder.setDefaultHeaders(Arrays.asList(new BasicHeader(HttpHeaders.USER_AGENT, userAgent))); builder.setDefaultRequestConfig(setupDefaultRequestConfig().build()); if (config.getUsername() != null) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(config.getUsername(), config.getPassword()) ); builder.setDefaultCredentialsProvider(credentialsProvider); } if (config.getSocketOptions() != null) { final SocketOptionsConfig socketOptions = config.getSocketOptions(); SocketConfig socketConfig = SocketConfig.custom() .setSoTimeout(socketOptions.getSoTimeout()) .setSoKeepAlive(socketOptions.isKeepAlive()) .setSndBufSize(socketOptions.getSndBuffSize()) .setRcvBufSize(socketOptions.getRcvBuffSize()) .build(); builder.setDefaultSocketConfig(socketConfig); } if (config.getConnectionPool() != null) { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(config.getConnectionPool().getTimeToLiveSeconds(), TimeUnit.SECONDS); connectionManager.setDefaultMaxPerRoute(config.getConnectionPool().getMaxPerRoute()); connectionManager.setMaxTotal(config.getConnectionPool().getMaxTotal()); builder.setConnectionManager(connectionManager); } return builder; }