本文整理汇总了Java中org.apache.commons.httpclient.params.HttpClientParams.setConnectionManagerTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientParams.setConnectionManagerTimeout方法的具体用法?Java HttpClientParams.setConnectionManagerTimeout怎么用?Java HttpClientParams.setConnectionManagerTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.params.HttpClientParams
的用法示例。
在下文中一共展示了HttpClientParams.setConnectionManagerTimeout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
*
* @throws Exception .
*/
private void init() throws Exception {
httpClientManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = httpClientManager.getParams();
params.setStaleCheckingEnabled(true);
params.setMaxTotalConnections(1000);
params.setDefaultMaxConnectionsPerHost(500);
params.setConnectionTimeout(2000);
params.setSoTimeout(3000);
/** 设置从连接池中获取连接超时。*/
HttpClientParams clientParams = new HttpClientParams();
clientParams.setConnectionManagerTimeout(1000);
httpClient = new HttpClient(clientParams, httpClientManager);
}
示例2: getInstanceHttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public HttpClient getInstanceHttpClient() {
HttpClient client = new HttpClient();
HttpClientParams params = client.getParams();
params.setConnectionManagerTimeout(DEFAULT_TIMEOUT);
params.setSoTimeout(DEFAULT_TIMEOUT);
if (Jenkins.getInstance() == null) return client;
ProxyConfiguration proxy = getInstance().proxy;
if (proxy == null) return client;
logger.log(Level.FINE, "Jenkins proxy: {0}:{1}", new Object[]{ proxy.name, proxy.port });
client.getHostConfiguration().setProxy(proxy.name, proxy.port);
String username = proxy.getUserName();
String password = proxy.getPassword();
// Consider it to be passed if username specified. Sufficient?
if (username != null && !"".equals(username.trim())) {
logger.log(Level.FINE, "Using proxy authentication (user={0})", username);
client.getState().setProxyCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
}
return client;
}
示例3: setConfiguration
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* Define client configuration
* @param httpClient instance to configure
*/
private static void setConfiguration(final HttpClient httpClient) {
final HttpConnectionManagerParams httpParams = httpClient.getHttpConnectionManager().getParams();
// define connect timeout:
httpParams.setConnectionTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
// define read timeout:
httpParams.setSoTimeout(NetworkSettings.DEFAULT_SOCKET_READ_TIMEOUT);
// define connection parameters:
httpParams.setMaxTotalConnections(NetworkSettings.DEFAULT_MAX_TOTAL_CONNECTIONS);
httpParams.setDefaultMaxConnectionsPerHost(NetworkSettings.DEFAULT_MAX_HOST_CONNECTIONS);
// set content-encoding to UTF-8 instead of default ISO-8859
final HttpClientParams httpClientParams = httpClient.getParams();
// define timeout value for allocation of connections from the pool
httpClientParams.setConnectionManagerTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
// encoding to UTF-8
httpClientParams.setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
// avoid retries (3 by default):
httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, _httpNoRetryHandler);
// Customize the user agent:
httpClientParams.setParameter(HttpMethodParams.USER_AGENT, System.getProperty(NetworkSettings.PROPERTY_USER_AGENT));
}
示例4: initClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
@Override
public void initClient(final ConnectionSettings settings) {
if (settings == null)
throw new NullPointerException("Internet connection settings cannot be null");
this.settings = settings;
final HttpClientParams clientParams = client.getParams();
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
clientParams.setParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true);
clientParams.setSoTimeout(timeout);
clientParams.setConnectionManagerTimeout(timeout);
clientParams.setHttpElementCharset("UTF-8");
this.client.setHttpConnectionManager(new SimpleHttpConnectionManager(/*true*/));
this.client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
HttpState initialState = new HttpState();
HostConfiguration configuration = new HostConfiguration();
if (settings.getProxyType() == Proxy.Type.SOCKS) { // Proxy stuff happens here
configuration = new HostConfigurationWithStickyProtocol();
Proxy proxy = new Proxy(settings.getProxyType(), // create custom Socket factory
new InetSocketAddress(settings.getProxyURL(), settings.getProxyPort())
);
protocol = new Protocol("http", new ProxySocketFactory(proxy), 80);
} else if (settings.getProxyType() == Proxy.Type.HTTP) { // we use build in HTTP Proxy support
configuration.setProxy(settings.getProxyURL(), settings.getProxyPort());
if (settings.getUserName() != null)
initialState.setProxyCredentials(AuthScope.ANY, new NTCredentials(settings.getUserName(), settings.getPassword(), "", ""));
}
client.setHostConfiguration(configuration);
clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
client.setState(initialState);
}
示例5: getUploadDownloadClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public HttpClient getUploadDownloadClient(boolean forProxy) {
int index = forProxy ? 1 : 0;
if (myUploadDownloadClients[index] == null) {
HttpConnectionManager connManager = new MultiThreadedHttpConnectionManager();
myUploadDownloadClients[index] = new HttpClient(connManager);
HttpClientParams clientParams = new HttpClientParams();
// Set the default timeout in case we have a connection pool starvation to 30sec
clientParams.setConnectionManagerTimeout(30000);
myUploadDownloadClients[index].setParams(clientParams);
}
return myUploadDownloadClients[index];
}
示例6: start
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.info("Starting {}", CcuClient.class.getSimpleName());
super.start();
tclregaScripts = loadTclRegaScripts();
httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
HttpClientParams params = httpClient.getParams();
Long timeout = context.getConfig().getTimeout() * 1000L;
params.setConnectionManagerTimeout(timeout);
params.setSoTimeout(timeout.intValue());
params.setContentCharset("ISO-8859-1");
}
示例7: start
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.info("Starting {}", CcuClient.class.getSimpleName());
super.start();
tclregaScripts = loadTclRegaScripts();
httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
HttpClientParams params = httpClient.getParams();
Long timeout = context.getConfig().getTimeout() * 1000L;
params.setConnectionManagerTimeout(timeout);
params.setSoTimeout(timeout.intValue());
params.setContentCharset("ISO-8859-1");
}
示例8: CommonsHttpTransport
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public CommonsHttpTransport(Settings settings, String host) {
this.settings = settings;
httpInfo = host;
sslEnabled = settings.getNetworkSSLEnabled();
String pathPref = settings.getNodesPathPrefix();
pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));
HttpClientParams params = new HttpClientParams();
params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
settings.getHttpRetries(), false) {
@Override
public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
if (super.retryMethod(method, exception, executionCount)) {
stats.netRetries++;
return true;
}
return false;
}
});
params.setConnectionManagerTimeout(settings.getHttpTimeout());
params.setSoTimeout((int) settings.getHttpTimeout());
// explicitly set the charset
params.setCredentialCharset(StringUtils.UTF_8.name());
params.setContentCharset(StringUtils.UTF_8.name());
HostConfiguration hostConfig = new HostConfiguration();
hostConfig = setupSSLIfNeeded(settings, hostConfig);
hostConfig = setupSocksProxy(settings, hostConfig);
Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
hostConfig = (HostConfiguration) authSettings[0];
try {
hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
} catch (IOException ex) {
throw new EsHadoopTransportException("Invalid target URI " + host, ex);
}
client = new HttpClient(params, new SocketTrackingConnectionManager());
client.setHostConfiguration(hostConfig);
addHttpAuth(settings, authSettings);
completeAuth(authSettings);
HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
// make sure to disable Nagle's protocol
connectionParams.setTcpNoDelay(true);
if (log.isTraceEnabled()) {
log.trace("Opening HTTP transport to " + httpInfo);
}
}
示例9: isValid
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
*/
@SuppressWarnings({ "unchecked", "unused" })
@Override
public boolean isValid(final FormItem formItem, final Map formContext) {
boolean result;
final TextElement textElement = (TextElement) formItem;
if (StringHelper.containsNonWhitespace(textElement.getValue())) {
// Use an HttpClient to fetch a profile information page from ICQ.
final HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
final HttpClientParams httpClientParams = httpClient.getParams();
httpClientParams.setConnectionManagerTimeout(2500);
httpClient.setParams(httpClientParams);
final HttpMethod httpMethod = new GetMethod(ICQ_NAME_VALIDATION_URL);
final NameValuePair uinParam = new NameValuePair(ICQ_NAME_URL_PARAMETER, textElement.getValue());
httpMethod.setQueryString(new NameValuePair[] { uinParam });
// Don't allow redirects since otherwise, we won't be able to get the HTTP 302 further down.
httpMethod.setFollowRedirects(false);
try {
// Get the user profile page
httpClient.executeMethod(httpMethod);
final int httpStatusCode = httpMethod.getStatusCode();
// Looking at the HTTP status code tells us whether a user with the given ICQ name exists.
if (httpStatusCode == HttpStatus.SC_OK) {
// ICQ tells us that a user name is valid if it sends an HTTP 200...
result = true;
} else if (httpStatusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
// ...and if it's invalid, it sends an HTTP 302.
textElement.setErrorKey("form.name.icq.error", null);
result = false;
} else {
// For HTTP status codes other than 200 and 302 we will silently assume that the given ICQ name is valid, but inform the user about this.
textElement.setExampleKey("form.example.icqname.notvalidated", null);
log.warn("ICQ name validation: Expected HTTP status 200 or 301, but got " + httpStatusCode);
result = true;
}
} catch (final Exception e) {
// In case of any exception, assume that the given ICQ name is valid (The opposite would block easily upon network problems), and inform the user about
// this.
textElement.setExampleKey("form.example.icqname.notvalidated", null);
log.warn("ICQ name validation: Exception: " + e.getMessage());
result = true;
}
} else {
result = true;
}
return result;
}
示例10: isValid
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
*/
@SuppressWarnings({ "unchecked" })
@Override
public boolean isValid(final FormItem formItem, final Map formContext) {
boolean result;
final TextElement textElement = (TextElement) formItem;
if (StringHelper.containsNonWhitespace(textElement.getValue())) {
// Use an HttpClient to fetch a profile information page from MSN.
final HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
final HttpClientParams httpClientParams = httpClient.getParams();
httpClientParams.setConnectionManagerTimeout(2500);
httpClient.setParams(httpClientParams);
final HttpMethod httpMethod = new GetMethod(MSN_NAME_VALIDATION_URL);
final NameValuePair idParam = new NameValuePair(MSN_NAME_URL_PARAMETER, textElement.getValue());
httpMethod.setQueryString(new NameValuePair[] { idParam });
// Don't allow redirects since otherwise, we won't be able to get the correct status
httpMethod.setFollowRedirects(false);
try {
// Get the user profile page
httpClient.executeMethod(httpMethod);
final int httpStatusCode = httpMethod.getStatusCode();
// Looking at the HTTP status code tells us whether a user with the given MSN name exists.
if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
// If the user exists, we get a 301...
result = true;
} else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
// ...and if the user doesn't exist, MSN sends a 500.
textElement.setErrorKey("form.name.msn.error", null);
result = false;
} else {
// For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
result = true;
}
} catch (final Exception e) {
// In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about
// this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Exception: " + e.getMessage());
result = true;
}
} else {
result = true;
}
return result;
}
示例11: afterPropertiesSet
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
* Private {@link HttpClient} initialization.
*/
@PostConstruct
private final void afterPropertiesSet()
{
// Client is higher in the hierarchy than manager so set the parameters here
final HttpClientParams clientParams = new HttpClientParams();
clientParams.setConnectionManagerClass(connectionManager.getClass());
clientParams.setConnectionManagerTimeout(connectionTimeout);
clientParams.setSoTimeout(readTimeout);
clientParams.setParameter("http.connection.timeout", new Integer(
connectionTimeout));
// A retry handler for when a connection fails
clientParams.setParameter(HttpMethodParams.RETRY_HANDLER,
new HttpMethodRetryHandler()
{
@Override
public boolean retryMethod(final HttpMethod method,
final IOException exception, final int executionCount)
{
if (executionCount >= retryCount)
{
// Do not retry if over max retry count
return false;
}
if (instanceOf(exception, NoHttpResponseException.class))
{
// Retry if the server dropped connection on us
return true;
}
if (instanceOf(exception, SocketException.class))
{
// Retry if the server reset connection on us
return true;
}
if (instanceOf(exception, SocketTimeoutException.class))
{
// Retry if the read timed out
return true;
}
if (!method.isRequestSent())
{
// Retry if the request has not been sent fully or
// if it's OK to retry methods that have been sent
return true;
}
// otherwise do not retry
return false;
}
});
httpClient.setParams(clientParams);
final HttpConnectionManagerParams connectionManagerParams = connectionManager
.getParams();
connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
connectionManager.setParams(connectionManagerParams);
}
示例12: CommonsHttpTransport
import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public CommonsHttpTransport(Settings settings, String host) {
this.settings = settings;
httpInfo = host;
sslEnabled = settings.getNetworkSSLEnabled();
String pathPref = settings.getNodesPathPrefix();
pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));
HttpClientParams params = new HttpClientParams();
params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
settings.getHttpRetries(), false) {
@Override
public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
if (super.retryMethod(method, exception, executionCount)) {
stats.netRetries++;
return true;
}
return false;
}
});
params.setConnectionManagerTimeout(settings.getHttpTimeout());
params.setSoTimeout((int) settings.getHttpTimeout());
// explicitly set the charset
params.setCredentialCharset(StringUtils.UTF_8.name());
params.setContentCharset(StringUtils.UTF_8.name());
HostConfiguration hostConfig = new HostConfiguration();
hostConfig = setupSSLIfNeeded(settings, hostConfig);
hostConfig = setupSocksProxy(settings, hostConfig);
Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
hostConfig = (HostConfiguration) authSettings[0];
try {
hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
} catch (IOException ex) {
throw new EsHadoopTransportException("Invalid target URI " + host, ex);
}
client = new HttpClient(params, new SocketTrackingConnectionManager());
client.setHostConfiguration(hostConfig);
addHttpAuth(settings, authSettings);
completeAuth(authSettings);
HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
// make sure to disable Nagle's protocol
connectionParams.setTcpNoDelay(true);
this.headers = new HeaderProcessor(settings);
if (log.isTraceEnabled()) {
log.trace("Opening HTTP transport to " + httpInfo);
}
}