List of usage examples for org.apache.commons.httpclient HttpClient HttpClient
public HttpClient(HttpClientParams paramHttpClientParams)
From source file:edu.unc.lib.dl.httpclient.HttpClientUtil.java
public static HttpClient getAuthenticatedClient(String urlString, String user, String pass, MultiThreadedHttpConnectionManager connectionManager) { if (urlString == null) { throw new IllegalArgumentException("Cannot create HttpClient for null URL"); }//from ww w . ja v a2 s . c o m HttpClient client; if (connectionManager != null) client = new HttpClient(connectionManager); else client = new HttpClient(); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); client.getState().setCredentials(getAuthenticationScope(urlString), creds); return client; }
From source file:com.netflix.postreview.ClientFactory.java
public static HttpClient getClient() throws HttpProxySettingsException { HttpClient httpClient = new HttpClient(connectionManager); httpClient.getParams().setConnectionManagerTimeout(connectionManagerTimeout); httpClient.getParams().setSoTimeout(dataTimeout); return httpClient; }
From source file:name.chengchao.myhttpclient.version3_1.HttpClient3UtilUseManager.java
/** * ?url?ResponseBody,method=get//from w ww. j ava2 s. com * * @param url exp:http://192.168.1.1:8080/dir/target.html * @return byte[]? */ public static byte[] getDataFromUrl(String url, int timeout) { if (StringUtils.isBlank(url)) { logger.error("url is blank!"); return null; } HttpClient httpClient = new HttpClient(connectionManager); // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(8000); // ? httpClient.getParams().setSoTimeout(timeout); GetMethod method = new GetMethod(url); // fix??? // method.setRequestHeader("Connection", "close"); // ??1 method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false)); try { int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { return method.getResponseBody(); } else { throw new RuntimeException("http request error,return code:" + statusCode + ",msg:" + new String(method.getResponseBody())); } } catch (HttpException e) { method.abort(); logger.error(e.getMessage()); } catch (IOException e) { method.abort(); logger.error(e.getMessage()); } finally { // Release the connection. method.releaseConnection(); } return null; }
From source file:com.smartitengineering.util.rest.client.jersey.cache.CacheableClient.java
private static CacheableClientHandler createDefaultClientHander(ClientConfig clientConfig) { final HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); return new CacheableClientHandler(client, clientConfig); }
From source file:cn.vlabs.duckling.common.http.WebSite.java
public WebSite(String baseurl) { client = new HttpClient(new MultiThreadedHttpConnectionManager()); baseURL = baseurl; }
From source file:net.sourceforge.jcctray.model.HTTPCruise.java
private static HttpClient getClient(Host host) { SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); HttpConnectionManagerParams connParams = new HttpConnectionManagerParams(); connParams.setConnectionTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT)); connParams.setSoTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT)); connectionManager.setParams(connParams); HttpClient client = new HttpClient(connectionManager); client.getParams().setAuthenticationPreemptive(true); if (!StringUtils.isEmptyOrNull(host.getHostName()) && !StringUtils.isEmptyOrNull(host.getPassword())) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(host.getUsername(), host.getPassword());//from w ww .jav a2 s . c om client.getState().setCredentials(new AuthScope(null, -1, null, null), credentials); } return client; }
From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.cas.direct.DirectLoginHttpFacade.java
public DirectLoginHttpFacade(String loginUrl, String serviceUrl) { this.loginUrl = loginUrl; this.serviceUrl = serviceUrl; HttpClientParams params = new HttpClientParams(); params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); this.httpClient = new HttpClient(params); }
From source file:net.sourceforge.jwbf.bots.HttpBot.java
/** * protected because abstract./*from w w w .j a v a2s. co m*/ * */ protected HttpBot() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connectionManager); }
From source file:com.exalead.io.failover.FailoverHttpClient.java
public FailoverHttpClient() { manager = new MonitoredHttpConnectionManager(); client = new HttpClient(manager); client.setParams(new HttpClientParams()); manager.getParams().setStaleCheckingEnabled(false); }
From source file:com.ironiacorp.http.impl.httpclient3.HttpJobRunnerHttpClient3.java
private void setupClient() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); // connectionManager.// maxConnectionsPerHost // maxTotalConnections httpClient = new HttpClient(connectionManager); // http://jakarta.apache.org/httpcomponents/httpclient-3.x/preference-api.html HttpClientParams params = httpClient.getParams(); params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1); params.setParameter("http.socket.timeout", new Integer(60000)); params.setParameter("http.protocol.content-charset", "UTF-8"); params.setCookiePolicy(CookiePolicy.RFC_2109); }