本文整理汇总了Java中org.apache.commons.httpclient.params.HttpConnectionManagerParams.setConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HttpConnectionManagerParams.setConnectionTimeout方法的具体用法?Java HttpConnectionManagerParams.setConnectionTimeout怎么用?Java HttpConnectionManagerParams.setConnectionTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.params.HttpConnectionManagerParams
的用法示例。
在下文中一共展示了HttpConnectionManagerParams.setConnectionTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructHttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
protected HttpClient constructHttpClient()
{
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);
HttpClientParams params = httpClient.getParams();
params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true);
params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true);
if (socketTimeout != null)
{
params.setSoTimeout(socketTimeout);
}
HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();
connectionManagerParams.setMaxTotalConnections(maxTotalConnections);
connectionManagerParams.setDefaultMaxConnectionsPerHost(maxHostConnections);
connectionManagerParams.setConnectionTimeout(connectionTimeout);
return httpClient;
}
示例2: executeMethod
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
private static byte[] executeMethod(HttpMethodBase method, int timeout) throws Exception {
InputStream in = null;
try {
method.addRequestHeader("Connection", "close");
HttpClient client = new HttpClient();
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setConnectionTimeout(timeout);
params.setSoTimeout(timeout);
params.setStaleCheckingEnabled(false);
ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
client.executeMethod(method);
in = method.getResponseBodyAsStream();
byte[] buffer = new byte[BUFFER_SIZE];
int len;
while( (len = in.read(buffer)) > 0) {
baos.write(buffer, 0, len);
}
return baos.toByteArray();
} finally {
if (in != null) {
in.close();
}
}
}
示例3: initHttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
protected void initHttpClient() {
if (MockServer.isTestMode()) {
return;
}
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
diamondConfigure.getPort());
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
// 设置读超时为1分钟,
// [email protected]
params.setSoTimeout(60 * 1000);
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
httpClient.setHostConfiguration(hostConfiguration);
}
示例4: pageExists
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
private static boolean pageExists(@NotNull String url) {
if (new File(url).exists()) {
return true;
}
final HttpClient client = new HttpClient();
final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setSoTimeout(5 * 1000);
params.setConnectionTimeout(5 * 1000);
try {
final HeadMethod method = new HeadMethod(url);
final int rc = client.executeMethod(method);
if (rc == 404) {
return false;
}
}
catch (IllegalArgumentException e) {
return false;
}
catch (IOException ignored) {
}
return true;
}
示例5: FullTextSearchEngine
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
/**
* @param multiThreadedHttpConnectionManager
* The
* @link {@link MultiThreadedHttpConnectionManager} that the fulltext search
* engine will use
* @throws FullTextSearchException
* If an error occured
*/
@Autowired
public FullTextSearchEngine(
@Qualifier("multiThreadedHttpConnectionManager")
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager)
throws FullTextSearchException {
Assert.notNull(multiThreadedHttpConnectionManager,
"multiThreadedHttpConnectionManager can not be null");
HttpConnectionManagerParams p = new HttpConnectionManagerParams();
p.setSoTimeout(0);
p.setConnectionTimeout(0);
multiThreadedHttpConnectionManager.setParams(p);
this.httpClient = new HttpClient(multiThreadedHttpConnectionManager);
if (this.httpClient == null) {
throw new FullTextSearchException(
"Can not instanciate http client with multiThreadedHttpConnectionManager : "
+ multiThreadedHttpConnectionManager);
}
}
示例6: init
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的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);
}
示例7: HttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs, int maxSize) {
connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = connectionManager.getParams();
params.setDefaultMaxConnectionsPerHost(maxConPerHost);
params.setConnectionTimeout(conTimeOutMs);
params.setSoTimeout(soTimeOutMs);
HttpClientParams clientParams = new HttpClientParams();
// 忽略cookie 避免 Cookie rejected 警告
clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
client = new org.apache.commons.httpclient.HttpClient(clientParams, connectionManager);
Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
this.maxSize = maxSize;
// 支持proxy
if (proxyHost != null && !proxyHost.equals("")) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
client.getParams().setAuthenticationPreemptive(true);
if (proxyAuthUser != null && !proxyAuthUser.equals("")) {
client.getState().setProxyCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(proxyAuthUser, proxyAuthPassword));
log("Proxy AuthUser: " + proxyAuthUser);
log("Proxy AuthPassword: " + proxyAuthPassword);
}
}
}
示例8: HttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
int maxSize) {
// MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
HttpConnectionManagerParams params = connectionManager.getParams();
params.setDefaultMaxConnectionsPerHost(maxConPerHost);
params.setConnectionTimeout(conTimeOutMs);
params.setSoTimeout(soTimeOutMs);
HttpClientParams clientParams = new HttpClientParams();
clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
client = new org.apache.commons.httpclient.HttpClient(clientParams,
connectionManager);
Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
}
示例9: loadProxyConfig
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
/**
* Load proxy configuration when proxy config has changed
*/
private void loadProxyConfig(){
connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setSoTimeout(proxyConfig.getSoTimeout());
params.setConnectionTimeout(proxyConfig.getConnectionTimeout());
params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections());
params.setDefaultMaxConnectionsPerHost(proxyConfig
.getDefaultMaxConnectionsPerHost());
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
configureCallbacks();
}
示例10: setConfiguration
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的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));
}
示例11: init
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Create a pool of HTTP connections to use to get the favicons
client = new HttpClient(new MultiThreadedHttpConnectionManager());
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setConnectionTimeout(2000);
params.setSoTimeout(2000);
// Load the default favicon to use when no favicon was found of a remote host
try {
URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
defaultBytes = getImage(resource.toString());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
// Initialize caches.
missesCache = CacheFactory.createCache("Favicon Misses");
hitsCache = CacheFactory.createCache("Favicon Hits");
}
示例12: init
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Create a pool of HTTP connections to use to get the favicons
client = new HttpClient(new MultiThreadedHttpConnectionManager());
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setConnectionTimeout(2000);
params.setSoTimeout(2000);
// Load the default favicon to use when no favicon was found of a remote host
try {
URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
defaultBytes = getImage(resource.toString());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
// Initialize caches.
missesCache = CacheFactory.createCache("Favicon Misses");
hitsCache = CacheFactory.createCache("Favicon Hits");
}
示例13: getHttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
@NotNull
private static HttpClient getHttpClient(@Nullable GithubAuthData.BasicAuth basicAuth) {
final HttpClient client = new HttpClient();
HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setConnectionTimeout(CONNECTION_TIMEOUT); //set connection timeout (how long it takes to connect to remote host)
params.setSoTimeout(CONNECTION_TIMEOUT); //set socket timeout (how long it takes to retrieve data from remote host)
client.getParams().setContentCharset("UTF-8");
// Configure proxySettings if it is required
final HttpConfigurable proxySettings = HttpConfigurable.getInstance();
if (proxySettings.USE_HTTP_PROXY && !StringUtil.isEmptyOrSpaces(proxySettings.PROXY_HOST)) {
client.getHostConfiguration().setProxy(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT);
if (proxySettings.PROXY_AUTHENTICATION) {
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN,
proxySettings.getPlainProxyPassword()));
}
}
if (basicAuth != null) {
client.getParams().setCredentialCharset("UTF-8");
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuth.getLogin(), basicAuth.getPassword()));
}
return client;
}
示例14: RobotsTxtParser
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
public RobotsTxtParser(int timeout, int cacheSize) {
robotsTxtCache = ExpiringLRUMap.create(cacheSize);
int timeToWaitForResponse = (int) (timeout * DateUtils.MILLIS_PER_SECOND);
HttpConnectionManagerParams hmcp = new HttpConnectionManagerParams();
hmcp.setSoTimeout(timeToWaitForResponse);
hmcp.setConnectionTimeout(timeToWaitForResponse);
hcm = new MultiThreadedHttpConnectionManager();
hcm.setParams(hmcp);
client = new HttpClient(hcm);
String proxyHost = FWProps.getStringProperty("http.proxyHost");
int proxyPort = FWProps.getIntegerProperty("http.proxyPort");
if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
}
}
示例15: initHttpClient
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //导入方法依赖的package包/类
protected void initHttpClient() {
if (MockServer.isTestMode()) {
return;
}
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(
diamondConfigure.getDomainNameList().get(
this.domainNamePos.get()), diamondConfigure.getPort());
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.closeIdleConnections(diamondConfigure
.getPollingIntervalTime() * 4000);
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(diamondConfigure
.isConnectionStaleCheckingEnabled());
params.setMaxConnectionsPerHost(hostConfiguration,
diamondConfigure.getMaxHostConnections());
params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
// ���ö���ʱΪ1����,
// [email protected]
params.setSoTimeout(60 * 1000);
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
httpClient.setHostConfiguration(hostConfiguration);
}