Java Code Examples for org.apache.commons.httpclient.HttpConnectionManager#getParams()
The following examples show how to use
org.apache.commons.httpclient.HttpConnectionManager#getParams() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientFactory.java From olat with Apache License 2.0 | 6 votes |
/** * A HttpClient with basic authentication and no host or port setting. Can only be used to retrieve absolute URLs * * @param user * can be NULL * @param password * can be NULL * @return HttpClient */ public static HttpClient getHttpClientInstance(String user, String password) { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionParams params = connectionManager.getParams(); // wait max 10 seconds to establish connection params.setConnectionTimeout(10000); // a read() call on the InputStream associated with this Socket // will block for only this amount params.setSoTimeout(10000); HttpClient c = new HttpClient(connectionManager); // use basic authentication if available if (user != null && user.length() > 0) { AuthScope authScope = new AuthScope(null, -1, null); Credentials credentials = new UsernamePasswordCredentials(user, password); c.getState().setCredentials(authScope, credentials); } return c; }
Example 2
Source File: HttpClientFactory.java From olat with Apache License 2.0 | 6 votes |
/** * A HttpClient with basic authentication and no host or port setting. Can only be used to retrieve absolute URLs * * @param user * can be NULL * @param password * can be NULL * @return HttpClient */ public static HttpClient getHttpClientInstance(String user, String password) { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionParams params = connectionManager.getParams(); // wait max 10 seconds to establish connection params.setConnectionTimeout(10000); // a read() call on the InputStream associated with this Socket // will block for only this amount params.setSoTimeout(10000); HttpClient c = new HttpClient(connectionManager); // use basic authentication if available if (user != null && user.length() > 0) { AuthScope authScope = new AuthScope(null, -1, null); Credentials credentials = new UsernamePasswordCredentials(user, password); c.getState().setCredentials(authScope, credentials); } return c; }