本文整理匯總了Java中org.apache.commons.httpclient.params.HttpConnectionManagerParams類的典型用法代碼示例。如果您正苦於以下問題:Java HttpConnectionManagerParams類的具體用法?Java HttpConnectionManagerParams怎麽用?Java HttpConnectionManagerParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpConnectionManagerParams類屬於org.apache.commons.httpclient.params包,在下文中一共展示了HttpConnectionManagerParams類的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: connectHTTP
import org.apache.commons.httpclient.params.HttpConnectionManagerParams; //導入依賴的package包/類
/**
*
* Public Section
*
*/
public void connectHTTP(String strUser, String strPass, String strHost, boolean insecure) {
//Connect WebDAV with credentials
hostConfig = new HostConfiguration();
hostConfig.setHost(strHost);
connectionManager = new MultiThreadedHttpConnectionManager();
connectionManagerParams = new HttpConnectionManagerParams();
connectionManagerParams.setMaxConnectionsPerHost(hostConfig, this.intMaxConnections);
connectionManager.setParams(connectionManagerParams);
client = new HttpClient(connectionManager);
creds = new UsernamePasswordCredentials(strUser, strPass);
client.getState().setCredentials(AuthScope.ANY, creds);
client.setHostConfiguration(hostConfig);
if (insecure) {
Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
}
Status.print("WebDav Connection generated");
}
示例13: 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");
}
示例14: 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;
}
示例15: 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);
}
}