本文整理汇总了Java中org.apache.commons.httpclient.params.HttpClientParams类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientParams类的具体用法?Java HttpClientParams怎么用?Java HttpClientParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientParams类属于org.apache.commons.httpclient.params包,在下文中一共展示了HttpClientParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructHttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的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: HTTPMetadataProvider
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
/**
* Constructor.
*
* @param metadataURL the URL to fetch the metadata
* @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
*
* @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
* the URL
*/
@Deprecated
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
super();
try {
metadataURI = new URI(metadataURL);
} catch (URISyntaxException e) {
throw new MetadataProviderException("Illegal URL syntax", e);
}
HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(requestTimeout);
httpClient = new HttpClient(clientParams);
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout);
authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());
}
示例3: HttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
/**
* Creates an instance of HttpClient using the given
* {@link HttpClientParams parameter set}.
*
* @param params The {@link HttpClientParams parameters} to use.
*
* @see HttpClientParams
*
* @since 3.0
*/
public HttpClient(HttpClientParams params) {
super();
if (params == null) {
throw new IllegalArgumentException("Params may not be null");
}
this.params = params;
this.httpConnectionManager = null;
Class clazz = params.getConnectionManagerClass();
if (clazz != null) {
try {
this.httpConnectionManager = (HttpConnectionManager) clazz.newInstance();
} catch (Exception e) {
LOG.warn("Error instantiating connection manager class, defaulting to"
+ " SimpleHttpConnectionManager",
e);
}
}
if (this.httpConnectionManager == null) {
this.httpConnectionManager = new SimpleHttpConnectionManager();
}
if (this.httpConnectionManager != null) {
this.httpConnectionManager.getParams().setDefaults(this.params);
}
}
示例4: testRelativeRedirect
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
public void testRelativeRedirect() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(new RelativeRedirectService());
this.client.getParams().setBooleanParameter(
HttpClientParams.REJECT_RELATIVE_REDIRECT, false);
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals("/relativelocation/", httpget.getPath());
assertEquals(host, httpget.getURI().getHost());
assertEquals(port, httpget.getURI().getPort());
assertEquals(new URI("http://" + host + ":" + port + "/relativelocation/", false),
httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例5: testRejectRelativeRedirect
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
public void testRejectRelativeRedirect() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(new RelativeRedirectService());
this.client.getParams().setBooleanParameter(
HttpClientParams.REJECT_RELATIVE_REDIRECT, true);
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
assertEquals(new URI("/oldlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例6: getHttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
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;
}
示例7: init
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
private synchronized void init() {
client = new HttpClient(new MultiThreadedHttpConnectionManager());
HttpClientParams params = client.getParams();
if (encode != null && !encode.trim().equals("")) {
params.setParameter("http.protocol.content-charset", encode);
params.setContentCharset(encode);
}
if (timeout > 0) {
params.setSoTimeout(timeout);
}
if (null != proxy) {
HostConfiguration hc = new HostConfiguration();
hc.setProxy(proxy.getHost(), proxy.getPort());
client.setHostConfiguration(hc);
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword()));
}
initialized = true;
}
示例8: setConnectionAuthorization
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
/**
* Extracts all the required authorization for that particular URL request
* and sets it in the <code>HttpMethod</code> passed in.
*
* @param client the HttpClient object
*
* @param u
* <code>URL</code> of the URL request
* @param authManager
* the <code>AuthManager</code> containing all the authorisations for
* this <code>UrlConfig</code>
*/
private void setConnectionAuthorization(HttpClient client, URL u, AuthManager authManager) {
HttpState state = client.getState();
if (authManager != null) {
HttpClientParams params = client.getParams();
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()){
log.debug(username + " > D="+ username + " D="+domain+" R="+realm);
}
state.setCredentials(
new AuthScope(u.getHost(),u.getPort(),
realm.length()==0 ? null : realm //"" is not the same as no realm
,AuthScope.ANY_SCHEME),
// NT Includes other types of Credentials
new NTCredentials(
username,
auth.getPass(),
localHost,
domain
));
// We have credentials - should we set pre-emptive authentication?
if (canSetPreEmptive){
log.debug("Setting Pre-emptive authentication");
params.setAuthenticationPreemptive(true);
}
} else {
state.clearCredentials();
if (canSetPreEmptive){
params.setAuthenticationPreemptive(false);
}
}
} else {
state.clearCredentials();
}
}
示例9: init
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的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);
}
示例10: HttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的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);
}
}
}
示例11: configureHttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
protected void configureHttpClient() throws IOException, GeneralSecurityException {
httpClient.getParams().setAuthenticationPreemptive(isAuthenticationPreemptive());
initCredentials();
initSocketFactory();
initProtocolIfNeeded();
if (httpConnectionManager != null) {
httpClient.setHttpConnectionManager(httpConnectionManager);
}
List<Header> headers = getDefaultHeaders();
httpClient.getHostConfiguration().getParams().setParameter(HostParams.DEFAULT_HEADERS, headers);
httpClient.getParams().setParameter(HttpClientParams.USER_AGENT,
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19");
httpClient.getParams().setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
httpClient.getParams().setConnectionManagerTimeout(connectionManagerTimeout);
httpClient.getParams().setSoTimeout(soTimeout);
if (connectionTimeout >= 0) {
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
}
}
示例12: init
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
private void init() {
initList(m_ipList, ipFilePath);
initList(m_uaList, uaFilePath);
initList(m_itemList, itmFilePath);
initList(m_tsList,tsFilePath);
initList(m_siteList,siteFilePath);
initList(m_dsList,dsFilePath);
initGUIDList();
String finalURL = "";
if (batchMode) {
finalURL = BATCH_URL;
} else {
finalURL = URL;
}
m_payload = readFromResource();
HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(60000);
m_client = new HttpClient(clientParams);
m_method = new PostMethod(NODE + finalURL + EVENTTYPE);
m_method.setRequestHeader("Connection", "Keep-Alive");
m_method.setRequestHeader("Accept-Charset", "UTF-8");
}
示例13: HttpClient
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的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);
}
示例14: HTTPMetadataProvider
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
/**
* Constructor.
*
* @param metadataURL the URL to fetch the metadata
* @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond
*
* @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from
* the URL
*/
public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException {
super();
try {
metadataURI = new URI(metadataURL);
maintainExpiredMetadata = true;
HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(requestTimeout);
httpClient = new HttpClient(clientParams);
authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort());
// 24 hours
maxCacheDuration = 60 * 60 * 24;
} catch (URISyntaxException e) {
throw new MetadataProviderException("Illegal URL syntax", e);
}
}
示例15: setUp
import org.apache.commons.httpclient.params.HttpClientParams; //导入依赖的package包/类
@Override
public void setUp() throws Exception
{
KeyStoreParameters keyStoreParameters = new KeyStoreParameters("SSL Key Store", "JCEKS", null, "ssl-keystore-passwords.properties", "ssl.keystore");
KeyStoreParameters trustStoreParameters = new KeyStoreParameters("SSL Trust Store", "JCEKS", null, "ssl-truststore-passwords.properties", "ssl.truststore");
SSLEncryptionParameters sslEncryptionParameters = new SSLEncryptionParameters(keyStoreParameters, trustStoreParameters);
ClasspathKeyResourceLoader keyResourceLoader = new ClasspathKeyResourceLoader();
HttpClientFactory httpClientFactory = new HttpClientFactory(SecureCommsType.getType("https"), sslEncryptionParameters, keyResourceLoader, null, null, "localhost", 8080,
8443, 40, 40, 0);
StringBuilder sb = new StringBuilder();
sb.append("/solr/admin/cores");
this.baseUrl = sb.toString();
httpClient = httpClientFactory.getHttpClient();
HttpClientParams params = httpClient.getParams();
params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
}