use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project openmeetings by apache.
the class AppointmentManager method createHttpClient.
/**
* Returns a new HttpClient with the inbuilt connection manager in this.
*
* @return HttpClient object that was created.
*/
public HttpClient createHttpClient() {
if (connmanager == null) {
connmanager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
connmanager.setParams(params);
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setConnectionManagerTimeout(CONNECTION_MANAGER_TIMEOUT);
return new HttpClient(connmanager);
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project ecf by eclipse.
the class AbstractBulletinBoard method postConnect.
public void postConnect() {
try {
this.url = new URL(getID().toExternalForm());
final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
httpClient = new HttpClient(connectionManager);
} catch (final MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.
the class UriUtils method getInputStreamFromUrl.
public static InputStream getInputStreamFromUrl(final String url, final String user, final String password) {
try {
final Pair<String, Integer> hostAndPort = validateUrl(url);
final HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
final Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
}
// Execute the method.
final GetMethod method = new GetMethod(url);
final int statusCode = httpclient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
return method.getResponseBodyAsStream();
} catch (final Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.
the class UriUtils method checkUrlExistence.
// use http HEAD method to validate url
public static void checkUrlExistence(final String url) {
if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) {
final HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
final HeadMethod httphead = new HeadMethod(url);
try {
if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) {
throw new IllegalArgumentException("Invalid URL: " + url);
}
} catch (final HttpException hte) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
} catch (final IOException ioe) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
}
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cosmic by MissionCriticalCloud.
the class ClusterServiceServletImpl method getHttpClient.
private HttpClient getHttpClient() {
if (s_client == null) {
final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.getParams().setDefaultMaxConnectionsPerHost(4);
// TODO make it configurable
mgr.getParams().setMaxTotalConnections(1000);
s_client = new HttpClient(mgr);
final HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);
s_client.setParams(clientParams);
}
return s_client;
}
Aggregations