use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project maven-plugins by apache.
the class DoapUtil method fetchURL.
/**
* Fetch an URL
*
* @param settings the user settings used to fetch the url with an active proxy, if defined.
* @param url the url to fetch
* @throws IOException if any
* @see #DEFAULT_TIMEOUT
* @since 1.1
*/
public static void fetchURL(Settings settings, URL url) throws IOException {
if (url == null) {
throw new IllegalArgumentException("The url is null");
}
if ("file".equals(url.getProtocol())) {
InputStream in = null;
try {
in = url.openStream();
in.close();
in = null;
} finally {
IOUtil.close(in);
}
return;
}
// http, https...
HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(DEFAULT_TIMEOUT);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(DEFAULT_TIMEOUT);
httpClient.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// Some web servers don't allow the default user-agent sent by httpClient
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
if (StringUtils.isNotEmpty(activeProxy.getHost()) && !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost())) {
httpClient.getHostConfiguration().setProxy(activeProxy.getHost(), activeProxy.getPort());
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);
}
}
}
GetMethod getMethod = new GetMethod(url.toString());
try {
int status;
try {
status = httpClient.executeMethod(getMethod);
} catch (SocketTimeoutException e) {
// could be a sporadic failure, one more retry before we give up
status = httpClient.executeMethod(getMethod);
}
if (status != HttpStatus.SC_OK) {
throw new FileNotFoundException(url.toString());
}
} finally {
getMethod.releaseConnection();
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cloudstack by apache.
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;
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cloudstack by apache.
the class UriUtils method getInputStreamFromUrl.
public static InputStream getInputStreamFromUrl(String url, String user, String password) {
try {
Pair<String, Integer> hostAndPort = validateUrl(url);
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
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.
GetMethod method = new GetMethod(url);
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 (Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project hub-alert by blackducksoftware.
the class AuthenticationHandler method artifactBinding.
@Bean
public HTTPArtifactBinding artifactBinding(ParserPool parserPool, VelocityEngine velocityEngine) {
ArtifactResolutionProfileImpl profileImpl = new ArtifactResolutionProfileImpl(new HttpClient(new MultiThreadedHttpConnectionManager()));
profileImpl.setProcessor(new SAMLProcessorImpl(soapBinding()));
return new HTTPArtifactBinding(parserPool, velocityEngine, profileImpl);
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class ECSApiFactory method init.
/**
* Initialize
*/
public void init() {
_log.info(" ECSApiFactory:init ECSApi factory initialization");
_clientMap = new ConcurrentHashMap<String, ECSApi>();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setMaxTotalConnections(_maxConn);
params.setTcpNoDelay(true);
params.setConnectionTimeout(_connTimeout);
params.setSoTimeout(_socketConnTimeout);
_connectionManager = new MultiThreadedHttpConnectionManager();
_connectionManager.setParams(params);
// close idle connections immediately
_connectionManager.closeIdleConnections(0);
HttpClient client = new HttpClient(_connectionManager);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
_clientHandler = new ApacheHttpClientHandler(client);
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 4443));
}
Aggregations