当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientParams类代码示例

本文整理汇总了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;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:19,代码来源:HttpClientFactory.java

示例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());

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HTTPMetadataProvider.java

示例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);
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:35,代码来源:HttpClient.java

示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestRedirects.java

示例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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:TestRedirects.java

示例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;
    }
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:ClusterServiceServletImpl.java

示例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;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:19,代码来源:HttpUtil.java

示例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();
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:51,代码来源:HTTPHC3Impl.java

示例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);
    
}
 
开发者ID:magenm,项目名称:bsming,代码行数:21,代码来源:HttpClientUtil.java

示例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);
        }
    }
}
 
开发者ID:jpbirdy,项目名称:WordsDetection,代码行数:27,代码来源:HttpClient.java

示例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);
    }
}
 
开发者ID:payneteasy,项目名称:superfly,代码行数:24,代码来源:HttpClientFactoryBean.java

示例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");
}
 
开发者ID:pulsarIO,项目名称:realtime-analytics,代码行数:24,代码来源:Simulator.java

示例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);
	}
 
开发者ID:dehuinet,项目名称:minxing_java_sdk,代码行数:18,代码来源:HttpClient.java

示例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);
    }
}
 
开发者ID:apigee,项目名称:java-opensaml2,代码行数:27,代码来源:HTTPMetadataProvider.java

示例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"));
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:22,代码来源:EmbeddedSolrTest.java


注:本文中的org.apache.commons.httpclient.params.HttpClientParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。