@Override public String toString() { final StringBuilder msg = new StringBuilder(getClass().getSimpleName()).append("["); if (hasConnectTimeout()) { msg.append("connect timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSoTimeout()) { msg.append("socket timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSndBuffSize()) { msg.append("send buffer size = ").append(getSndBuffSize()).append(" "); } if (hasRcvBuffSize()) { msg.append("receive buffer size = ").append(getRcvBuffSize()).append(" "); } msg.append("keep alive = ").append(isKeepAlive()).append("]"); return msg.toString(); }
@Override public String toString() { final StringBuilder msg = new StringBuilder(getClass().getSimpleName()).append("["); if (hasConnectTimeout()) { msg.append("connect timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSoTimeout()) { msg.append("socket timeout = ").append(getSoTimeout()).append(" ms "); } if (hasSndBuffSize()) { msg.append("send buffer size = ").append(getSndBuffSize()).append(" "); } if (hasRcvBuffSize()) { msg.append("receive buffer size = ").append(getRcvBuffSize()).append(" "); } msg.append("keep alive = ").append(isKeepAlive()).append("]"); return msg.toString(); }
/** * Configure the socket with the given socket options. This should be done before the socket is connected. * The connection timeout is not configurable - it must be used when connecting the socket. * * @param socket A not connected socket * @param options The socket options. If null, no socket options will be configured. */ public static void configureSocketOptions(Socket socket, SocketOptionsConfig options) throws SocketException { if (options != null) { if (options.isKeepAlive()) { socket.setKeepAlive(true); } if (options.hasSoTimeout()) { socket.setSoTimeout(options.getSoTimeout()); } if (options.hasSndBuffSize()) { socket.setSendBufferSize(options.getSndBuffSize()); } if (options.hasRcvBuffSize()) { socket.setReceiveBufferSize(options.getRcvBuffSize()); } } }
/** * Configure the socket with the given socket options. This should be done before the socket is connected. * The connection timeout is not configurable - it must be used when connecting the socket. * * @param socket A not connected socket * @param options The socket options. If null, no socket options will be configured. */ public static void configureSocketOptions(Socket socket, SocketOptionsConfig options) throws SocketException { if (options != null) { if (options.isKeepAlive()) { socket.setKeepAlive(true); } if (options.hasSoTimeout()) { socket.setSoTimeout(options.getSoTimeout()); } if (options.hasSndBuffSize()) { socket.setSendBufferSize(options.getSndBuffSize()); } if (options.hasRcvBuffSize()) { socket.setReceiveBufferSize(options.getRcvBuffSize()); } } }
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; }
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; }