@Override public void close() { if (log.isTraceEnabled()) { log.trace("Closing HTTP transport to " + httpInfo); } HttpConnectionManager manager = client.getHttpConnectionManager(); if (manager instanceof SocketTrackingConnectionManager) { try { ((SocketTrackingConnectionManager) manager).close(); } catch (NullPointerException npe) { // ignore } catch (Exception ex) { // log - not much else to do log.warn("Exception closing underlying HTTP manager", ex); } } }
@Override public HttpClient create() throws Exception { HttpClient client = new HttpClient(); if (soTimeout >= 0) { client.getParams().setSoTimeout(soTimeout); } if (connTimeout >= 0) { client.getHttpConnectionManager().getParams().setConnectionTimeout(connTimeout); } return client; }
/** * Uses the post method to send a url with arguments by http, this method can call RESTful Api. * * @param url the http url * @param timeout milliseconds to wait for the server to respond before giving up * @param processInputStream the response body stream processor */ public static void post(String url, Integer timeout, IProcessInputStream processInputStream) throws IOException { Preconditions.checkNotNull(timeout, "timeout"); Preconditions.checkNotNull(processInputStream, "processInputStream"); PostMethod postMethod = new PostMethod(url); try { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout); int statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream inputStream = postMethod.getResponseBodyAsStream(); processInputStream.process(inputStream); } else { throw new IOException("Failed to perform POST request. Status code: " + statusCode); } } finally { postMethod.releaseConnection(); } }
getHttpConnectionManager(), hostconfig, this.params,
completeAuth(authSettings); HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
private void resolveHttpParams(HttpParams params) { if (params != null) { if (params.getProxy() != null) { InetSocketAddress socketAddress = (InetSocketAddress) params .getProxy().address(); httpClient.getHostConfiguration().setProxy( socketAddress.getHostName(), socketAddress.getPort()); } if (params.getSSLContext() != null) { Protocol.registerProtocol("https", new Protocol("https", new SSLProtocolSocketFactory(params.getSSLContext()), 443)); } httpClient.getHttpConnectionManager().getParams() .setConnectionTimeout(params.getConnectTimeout()); } }
@Override public void close() { if(httpClient != null) { HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager(); if(connectionManager instanceof MultiThreadedHttpConnectionManager) { ((MultiThreadedHttpConnectionManager)connectionManager).shutdown(); } } }
/** * Return the HttpConnectionManagerParams object of the underlying HttpClient. This enables you to configure options * not explicitly exposed by the AbderaClient */ public HttpConnectionManagerParams getHttpConnectionManagerParams() { return client.getHttpConnectionManager().getParams(); }
public JumpToCodeClient(Configuration configuration) { this.configuration = configuration; this.client = new HttpClient(); // client.getHttpConnectionManager().getParams().setConnectionTimeout(150); locationInfoCache = CacheBuilder.newBuilder().maximumSize(5000).expireAfterAccess(15, TimeUnit.MINUTES).build(); locationSourceCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(15, TimeUnit.MINUTES).build(); ideCache = CacheBuilder.newBuilder().maximumSize(1).expireAfterWrite(10, TimeUnit.SECONDS).build(); }
/** * Shutdown hook that closes the underlying {@link HttpConnectionManager}'s connection pool, if any. */ public void destroy() { HttpConnectionManager connectionManager = getHttpClient().getHttpConnectionManager(); if (connectionManager instanceof MultiThreadedHttpConnectionManager) { ((MultiThreadedHttpConnectionManager) connectionManager).shutdown(); } }
protected HttpConnection getConnection() { return client.getHttpConnectionManager().getConnection( client.getHostConfiguration() ); }
/** * Return the maximum number of connections allowed for the client */ public AbderaClient setMaxConnectionsTotal(int max) { client.getHttpConnectionManager().getParams() .setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, max); return this; }
@Override public void destroy() throws Exception { HttpConnectionManager connectionManager = getHttpClient().getHttpConnectionManager(); if (connectionManager instanceof MultiThreadedHttpConnectionManager) { ((MultiThreadedHttpConnectionManager) connectionManager).shutdown(); } }
/** * Sets the maximum number of connections allowed for the underlying HttpClient. * * @param maxTotalConnections the maximum number of connections allowed * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setMaxTotalConnections(int) */ public void setMaxTotalConnections(int maxTotalConnections) { if (maxTotalConnections <= 0) { throw new IllegalArgumentException("maxTotalConnections must be a positive value"); } getHttpClient().getHttpConnectionManager().getParams().setMaxTotalConnections(maxTotalConnections); }
/** * Sets the timeout until a connection is etablished. A value of 0 means <em>never</em> timeout. * * @param timeout the timeout value in milliseconds * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setConnectionTimeout(int) */ public void setConnectionTimeout(int timeout) { if (timeout < 0) { throw new IllegalArgumentException("timeout must be a non-negative value"); } getHttpClient().getHttpConnectionManager().getParams().setConnectionTimeout(timeout); }
/** * Set the socket read timeout for the underlying HttpClient. A value of 0 means <em>never</em> timeout. * * @param timeout the timeout value in milliseconds * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int) */ public void setReadTimeout(int timeout) { if (timeout < 0) { throw new IllegalArgumentException("timeout must be a non-negative value"); } getHttpClient().getHttpConnectionManager().getParams().setSoTimeout(timeout); }
/** * Sets the maximum number of connections allowed for the underlying HttpClient. * * @param maxTotalConnections the maximum number of connections allowed * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setMaxTotalConnections(int) */ public void setMaxTotalConnections(int maxTotalConnections) { if (maxTotalConnections <= 0) { throw new IllegalArgumentException("maxTotalConnections must be a positive value"); } getHttpClient().getHttpConnectionManager().getParams().setMaxTotalConnections(maxTotalConnections); }
/** @since 2.0 */ @Override public void closeCommunicationLink() { if (getClient() != null) { final HttpConnectionManager mgr = getClient().getHttpConnectionManager(); if (mgr instanceof MultiThreadedHttpConnectionManager) { ((MultiThreadedHttpConnectionManager) mgr).shutdown(); } } }
ClientCollection(final String href, final AuthStrategy authStrategy) throws ProponoException { super("Standalone connection", "text", href); this.authStrategy = authStrategy; try { httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // TODO: make connection timeout configurable httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); } catch (final Throwable t) { throw new ProponoException("ERROR creating HTTPClient", t); } }
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException { config = (XmlRpcHttpClientConfig) pRequest.getConfig(); method = newPostMethod(config); super.initHttpHeaders(pRequest); if (config.getConnectionTimeout() != 0) client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout()); if (config.getReplyTimeout() != 0) client.getHttpConnectionManager().getParams().setSoTimeout(config.getReplyTimeout()); method.getParams().setVersion(HttpVersion.HTTP_1_1); }