List of usage examples for org.apache.commons.httpclient.params HttpConnectionParams CONNECTION_TIMEOUT
String CONNECTION_TIMEOUT
To view the source code for org.apache.commons.httpclient.params HttpConnectionParams CONNECTION_TIMEOUT.
Click Source Link
From source file:com.braindrainpain.docker.HttpSupport.java
protected HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, this.getSystemProperty("docker.repo.connection.timeout", 10 * 1000)); client.getParams().setSoTimeout(this.getSystemProperty("docker.repo.socket.timeout", 5 * 60 * 1000)); return client; }
From source file:com.ibm.stocator.fs.swift.SwiftAPIDirect.java
/** * GET object//w ww. j a v a 2 s . co m * * @param path path to object * @param authToken authentication token * @param bytesFrom from from * @param bytesTo bytes to * @return SwiftGETResponse that includes input stream and length * @throws IOException if network errors */ public static SwiftGETResponse getObject(Path path, String authToken, long bytesFrom, long bytesTo) throws IOException { GetMethod method = new GetMethod(path.toString()); method.addRequestHeader(new Header("X-Auth-Token", authToken)); if (bytesTo > 0) { final String rangeValue = String.format("bytes=%d-%d", bytesFrom, bytesTo); method.addRequestHeader(new Header(Constants.RANGES_HTTP_HEADER, rangeValue)); } HttpMethodParams methodParams = method.getParams(); methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); methodParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 15000); methodParams.setSoTimeout(60000); method.addRequestHeader(Constants.USER_AGENT_HTTP_HEADER, Constants.STOCATOR_USER_AGENT); final HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method); SwiftInputStreamWrapper httpStream = new SwiftInputStreamWrapper(method); SwiftGETResponse getResponse = new SwiftGETResponse(httpStream, method.getResponseContentLength()); return getResponse; }
From source file:cn.edu.seu.herald.ws.api.impl.AbstractCsvService.java
@Override public void setConnectionTimeout(int timeout) { httpClient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout); }
From source file:com.tw.go.plugin.material.artifactrepository.yum.exec.HttpConnectionChecker.java
HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getSystemProperty("yum.repo.connection.timeout", 10 * 1000)); client.getParams().setSoTimeout(getSystemProperty("yum.repo.socket.timeout", 5 * 60 * 1000)); return client; }
From source file:colt.nicity.performance.agent.LatentHttpPump.java
private org.apache.commons.httpclient.HttpClient createApacheClient(String host, int port, int maxConnections, int socketTimeoutInMillis) { HttpConnectionManager connectionManager = createConnectionManager(maxConnections); org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient( connectionManager);/*from www. j ava 2 s . com*/ client.getParams().setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); client.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); client.getParams().setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); HostConfiguration hostConfiguration = new HostConfiguration(); configureSsl(hostConfiguration, host, port); configureProxy(hostConfiguration); client.setHostConfiguration(hostConfiguration); return client; }
From source file:de.innovationgate.wgaservices.xfire.XFireClientFactoryService.java
private static void addDefaultServiceProperties(Map<String, Object> props) { if (!props.containsKey("mtom-enabled")) { props.put("mtom-enabled", "true"); }//w w w. j a va2 s . co m if (!props.containsKey(HttpTransport.CHUNKING_ENABLED)) { props.put(HttpTransport.CHUNKING_ENABLED, "true"); } if (!props.containsKey(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS)) { HttpClientParams params = new HttpClientParams(); params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 1000 * 5); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 1000 * 60); props.put(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, params); } }
From source file:com.twistbyte.affiliate.HttpUtility.java
/** * Do a get request to the given url and set the header values passed * * @param url//from ww w.ja va 2s.c o m * @param headerValues * @return */ public HttpResult doGet(String url, Map<String, String> headerValues) { String resp = ""; logger.info("url : " + url); GetMethod method = new GetMethod(url); logger.info("Now use connection timeout: " + connectionTimeout); httpclient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, connectionTimeout); if (headerValues != null) { for (Map.Entry<String, String> entry : headerValues.entrySet()) { method.setRequestHeader(entry.getKey(), entry.getValue()); } } HttpResult serviceResult = new HttpResult(); serviceResult.setSuccess(false); serviceResult.setHttpStatus(404); Reader reader = null; try { int result = httpclient.executeMethod(new HostConfiguration(), method, new HttpState()); logger.info("http result : " + result); resp = method.getResponseBodyAsString(); logger.info("response: " + resp); serviceResult.setHttpStatus(result); serviceResult.setBody(resp); serviceResult.setSuccess(200 == serviceResult.getHttpStatus()); } catch (java.net.ConnectException ce) { logger.warn("ConnectException: " + ce.getMessage()); } catch (IOException e) { logger.error("IOException sending request to " + url + " Reason:" + e.getMessage(), e); } finally { method.releaseConnection(); if (reader != null) { try { reader.close(); } catch (IOException e) { } } } return serviceResult; }
From source file:com.jivesoftware.os.jive.utils.http.client.HttpClientFactoryProvider.java
public HttpClientFactory createHttpClientFactory(final Collection<HttpClientConfiguration> configurations) { return new HttpClientFactory() { @Override/* ww w . j a va2s .com*/ public HttpClient createClient(String host, int port) { ApacheHttpClient31BackedHttpClient httpClient = createApacheClient(); HostConfiguration hostConfiguration = new HostConfiguration(); configureSsl(hostConfiguration, host, port, httpClient); configureProxy(hostConfiguration, httpClient); httpClient.setHostConfiguration(hostConfiguration); configureOAuth(httpClient); return httpClient; } private ApacheHttpClient31BackedHttpClient createApacheClient() { HttpClientConfig httpClientConfig = locateConfig(HttpClientConfig.class, HttpClientConfig.newBuilder().build()); HttpConnectionManager connectionManager = createConnectionManager(httpClientConfig); org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient( connectionManager); client.getParams().setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); client.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); client.getParams().setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, httpClientConfig.getSocketTimeoutInMillis() > 0 ? httpClientConfig.getSocketTimeoutInMillis() : 0); client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, httpClientConfig.getSocketTimeoutInMillis() > 0 ? httpClientConfig.getSocketTimeoutInMillis() : 0); return new ApacheHttpClient31BackedHttpClient(client, httpClientConfig.getCopyOfHeadersForEveryRequest()); } @SuppressWarnings("unchecked") private <T> T locateConfig(Class<? extends T> _class, T defaultConfiguration) { for (HttpClientConfiguration configuration : configurations) { if (_class.isInstance(configuration)) { return (T) configuration; } } return defaultConfiguration; } private boolean hasValidProxyUsernameAndPasswordSettings(HttpClientProxyConfig httpClientProxyConfig) { return StringUtils.isNotBlank(httpClientProxyConfig.getProxyUsername()) && StringUtils.isNotBlank(httpClientProxyConfig.getProxyPassword()); } private HttpConnectionManager createConnectionManager(HttpClientConfig config) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); if (config.getMaxConnectionsPerHost() > 0) { connectionManager.getParams() .setDefaultMaxConnectionsPerHost(config.getMaxConnectionsPerHost()); } else { connectionManager.getParams().setDefaultMaxConnectionsPerHost(Integer.MAX_VALUE); } if (config.getMaxConnections() > 0) { connectionManager.getParams().setMaxTotalConnections(config.getMaxConnections()); } return connectionManager; } private void configureOAuth(ApacheHttpClient31BackedHttpClient httpClient) { HttpClientOAuthConfig httpClientOAuthConfig = locateConfig(HttpClientOAuthConfig.class, null); if (httpClientOAuthConfig != null) { String serviceName = httpClientOAuthConfig.getServiceName(); HttpClientConsumerKeyAndSecretProvider consumerKeyAndSecretProvider = httpClientOAuthConfig .getConsumerKeyAndSecretProvider(); String consumerKey = consumerKeyAndSecretProvider.getConsumerKey(serviceName); if (StringUtils.isEmpty(consumerKey)) { throw new RuntimeException( "could create oauth client because consumerKey is null or empty for service:" + serviceName); } String consumerSecret = consumerKeyAndSecretProvider.getConsumerSecret(serviceName); if (StringUtils.isEmpty(consumerSecret)) { throw new RuntimeException( "could create oauth client because consumerSecret is null or empty for service:" + serviceName); } httpClient.setConsumerTokens(consumerKey, consumerSecret); } } private void configureProxy(HostConfiguration hostConfiguration, ApacheHttpClient31BackedHttpClient httpClient) { HttpClientProxyConfig httpClientProxyConfig = locateConfig(HttpClientProxyConfig.class, null); if (httpClientProxyConfig != null) { hostConfiguration.setProxy(httpClientProxyConfig.getProxyHost(), httpClientProxyConfig.getProxyPort()); if (hasValidProxyUsernameAndPasswordSettings(httpClientProxyConfig)) { HttpState state = new HttpState(); state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(httpClientProxyConfig.getProxyUsername(), httpClientProxyConfig.getProxyPassword())); httpClient.setState(state); } } } private void configureSsl(HostConfiguration hostConfiguration, String host, int port, ApacheHttpClient31BackedHttpClient httpClient) throws IllegalStateException { HttpClientSSLConfig httpClientSSLConfig = locateConfig(HttpClientSSLConfig.class, null); if (httpClientSSLConfig != null) { Protocol sslProtocol; if (httpClientSSLConfig.getCustomSSLSocketFactory() != null) { sslProtocol = new Protocol(HTTPS_PROTOCOL, new CustomSecureProtocolSocketFactory( httpClientSSLConfig.getCustomSSLSocketFactory()), SSL_PORT); } else { sslProtocol = Protocol.getProtocol(HTTPS_PROTOCOL); } hostConfiguration.setHost(host, port, sslProtocol); httpClient.setUsingSSL(); } else { hostConfiguration.setHost(host, port); } } }; }
From source file:com.braindrainpain.docker.httpsupport.HttpClientService.java
private HttpClient createHttpClient() { HttpClient client = new HttpClient(); client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, this.getSystemProperty("docker.repo.connection.timeout", 10 * 1000)); client.getParams().setSoTimeout(this.getSystemProperty("docker.repo.socket.timeout", 5 * 60 * 1000)); return client; }
From source file:com.htmlhifive.tools.jslint.engine.download.AbstractDownloadEngineSupport.java
/** * ?url????eclipse?????HttpClient??.<br> * ??//from w w w . j a v a 2s .c o m * {@link AbstractDownloadEngineSupport#getConnectionTimeout()}.<br> * ? {@link AbstractDownloadEngineSupport#getRetryTimes()} * * @param url URL * @return HttpClient */ private HttpClient createHttpClient(String url) { ServiceTracker<IProxyService, IProxyService> proxyTracker = new ServiceTracker<IProxyService, IProxyService>( JSLintPlugin.getDefault().getBundle().getBundleContext(), IProxyService.class, null); boolean useProxy = false; String proxyHost = null; int proxyPort = 0; String userId = null; String password = null; try { proxyTracker.open(); IProxyService service = proxyTracker.getService(); IProxyData[] datas = service.select(new URI(url)); for (IProxyData proxyData : datas) { if (proxyData.getHost() != null) { useProxy = true; proxyHost = proxyData.getHost(); proxyPort = proxyData.getPort(); userId = proxyData.getUserId(); password = proxyData.getPassword(); } } } catch (URISyntaxException e) { throw new RuntimeException(Messages.EM0100.getText(), e); } finally { proxyTracker.close(); } HttpClient client = new HttpClient(); if (useProxy) { client.getHostConfiguration().setProxy(proxyHost, proxyPort); if (StringUtils.isNotEmpty(userId)) { // ????? client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort, "realm"), new UsernamePasswordCredentials(userId, password)); } } client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(getRetryTimes(), true)); client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getConnectionTimeout()); return client; }