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


Java HttpClientParams.setParameter方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.params.HttpClientParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientParams.setParameter方法的具体用法?Java HttpClientParams.setParameter怎么用?Java HttpClientParams.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.params.HttpClientParams的用法示例。


在下文中一共展示了HttpClientParams.setParameter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: setConfiguration

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * Define client configuration
 * @param httpClient instance to configure
 */
private static void setConfiguration(final HttpClient httpClient) {
    final HttpConnectionManagerParams httpParams = httpClient.getHttpConnectionManager().getParams();
    // define connect timeout:
    httpParams.setConnectionTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // define read timeout:
    httpParams.setSoTimeout(NetworkSettings.DEFAULT_SOCKET_READ_TIMEOUT);

    // define connection parameters:
    httpParams.setMaxTotalConnections(NetworkSettings.DEFAULT_MAX_TOTAL_CONNECTIONS);
    httpParams.setDefaultMaxConnectionsPerHost(NetworkSettings.DEFAULT_MAX_HOST_CONNECTIONS);

    // set content-encoding to UTF-8 instead of default ISO-8859
    final HttpClientParams httpClientParams = httpClient.getParams();
    // define timeout value for allocation of connections from the pool
    httpClientParams.setConnectionManagerTimeout(NetworkSettings.DEFAULT_CONNECT_TIMEOUT);
    // encoding to UTF-8
    httpClientParams.setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8");
    // avoid retries (3 by default):
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, _httpNoRetryHandler);
    
    // Customize the user agent:
    httpClientParams.setParameter(HttpMethodParams.USER_AGENT, System.getProperty(NetworkSettings.PROPERTY_USER_AGENT));
}
 
开发者ID:JMMC-OpenDev,项目名称:jMCS,代码行数:28,代码来源:Http.java

示例3: initClient

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
@Override
public void initClient(final ConnectionSettings settings) {
    if (settings == null)
        throw new NullPointerException("Internet connection settings cannot be null");
    this.settings = settings;
    final HttpClientParams clientParams = client.getParams();
    clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    clientParams.setParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true);
    clientParams.setSoTimeout(timeout);
    clientParams.setConnectionManagerTimeout(timeout);
    clientParams.setHttpElementCharset("UTF-8");
    this.client.setHttpConnectionManager(new SimpleHttpConnectionManager(/*true*/));
    this.client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);

    HttpState initialState = new HttpState();
    HostConfiguration configuration = new HostConfiguration();
    if (settings.getProxyType() == Proxy.Type.SOCKS) { // Proxy stuff happens here

        configuration = new HostConfigurationWithStickyProtocol();

        Proxy proxy = new Proxy(settings.getProxyType(), // create custom Socket factory
                new InetSocketAddress(settings.getProxyURL(), settings.getProxyPort())
        );
        protocol = new Protocol("http", new ProxySocketFactory(proxy), 80);

    } else if (settings.getProxyType() == Proxy.Type.HTTP) { // we use build in HTTP Proxy support          
        configuration.setProxy(settings.getProxyURL(), settings.getProxyPort());
        if (settings.getUserName() != null)
            initialState.setProxyCredentials(AuthScope.ANY, new NTCredentials(settings.getUserName(), settings.getPassword(), "", ""));
    }
    client.setHostConfiguration(configuration);

    clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);

    client.setState(initialState);
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:37,代码来源:DownloadClient.java

示例4: buildClient

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has
 * been created.
 * 
 * @return the created client.
 */
public HttpClient buildClient() {
    if (httpsProtocolSocketFactory != null) {
        Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443));
    }

    HttpClientParams clientParams = new HttpClientParams();
    clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication());
    clientParams.setContentCharset(getContentCharSet());
    clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            connectionRetryAttempts, false));

    HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams();
    connMgrParams.setConnectionTimeout(getConnectionTimeout());
    connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost());
    connMgrParams.setMaxTotalConnections(getMaxTotalConnections());
    connMgrParams.setReceiveBufferSize(getReceiveBufferSize());
    connMgrParams.setSendBufferSize(getSendBufferSize());
    connMgrParams.setTcpNoDelay(isTcpNoDelay());

    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    connMgr.setParams(connMgrParams);

    HttpClient httpClient = new HttpClient(clientParams, connMgr);

    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        httpClient.setHostConfiguration(hostConfig);

        if (proxyUsername != null) {
            AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort);
            UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername,
                    proxyPassword);
            httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
        }
    }

    return httpClient;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:HttpClientBuilder.java

示例5: createHttpClient

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public static HttpClient createHttpClient() {
	HttpClient result = null;
	try {

		result = new HttpClient();
		// 使用多緒HttpClient
		MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
		HttpConnectionManagerParams managerParams = httpConnectionManager
				.getParams();
		managerParams.setDefaultMaxConnectionsPerHost(100);
		managerParams.setMaxTotalConnections(200);
		// 連線超時
		managerParams.setConnectionTimeout(5 * 1000);
		// 讀取超時
		managerParams.setSoTimeout(5 * 1000);
		//
		result.setHttpConnectionManager(httpConnectionManager);
		//
		HttpClientParams params = result.getParams();
		// http.protocol.content-charset
		params.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
		// 失敗 retry 3 次
		params.setParameter(HttpMethodParams.RETRY_HANDLER,
				new DefaultHttpMethodRetryHandler(3, false));

	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:31,代码来源:BenchmarkHttpClient3Test.java

示例6: HttpClientManager

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/** */
private HttpClientManager (String userAgent) {
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _client = new HttpClient(_connectionManager);
    HttpClientParams params = _client.getParams();
    params.setParameter(HttpMethodParams.SO_TIMEOUT, new Integer(30000));
    params.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
    params.setParameter(HttpClientParams.COOKIE_POLICY, CookiePolicy.RFC_2109);
    params.setParameter(HttpMethodParams.USER_AGENT, userAgent + "/HttpClientManager");
    _client.setParams(params);
}
 
开发者ID:reuven,项目名称:modelingcommons,代码行数:12,代码来源:HttpClientManager.java

示例7: addDefaultHeader

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public static void addDefaultHeader(HttpClient httpClient, boolean removeHeader, String headerName,
                                    String headervalue) {
    HttpClientParams clientParams = httpClient.getParams();
    HashSet<Header> headerSet = (HashSet<Header>) clientParams.getParameter(HTTP_DEFAULT_HEADERS);
    if (headerSet == null) {
        headerSet = new HashSet<Header>();
        clientParams.setParameter(HTTP_DEFAULT_HEADERS, headerSet);
    }
    Header header1 = new Header(headerName, headervalue);
    if (!headerSet.contains(header1) && !removeHeader) {
        headerSet.add(header1);
    } else if (headerSet.contains(header1) && removeHeader) {
        headerSet.remove(header1);
    }
}
 
开发者ID:DovAmir,项目名称:httpclientAuthHelper,代码行数:16,代码来源:AuthUtils.java

示例8: setReadTimeout

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * 超时时间
 * @param second
 */
public void setReadTimeout(int second){
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setParameter("http.connection.timeout", second);
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:9,代码来源:CommonsHttpInvokerRequestExecutor.java

示例9: CommonsHttpTransport

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public CommonsHttpTransport(Settings settings, String host) {
    this.settings = settings;
    httpInfo = host;
    sslEnabled = settings.getNetworkSSLEnabled();

    String pathPref = settings.getNodesPathPrefix();
    pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            settings.getHttpRetries(), false) {

        @Override
        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (super.retryMethod(method, exception, executionCount)) {
                stats.netRetries++;
                return true;
            }
            return false;
        }
    });

    params.setConnectionManagerTimeout(settings.getHttpTimeout());
    params.setSoTimeout((int) settings.getHttpTimeout());
    // explicitly set the charset
    params.setCredentialCharset(StringUtils.UTF_8.name());
    params.setContentCharset(StringUtils.UTF_8.name());

    HostConfiguration hostConfig = new HostConfiguration();

    hostConfig = setupSSLIfNeeded(settings, hostConfig);
    hostConfig = setupSocksProxy(settings, hostConfig);
    Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
    hostConfig = (HostConfiguration) authSettings[0];

    try {
        hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
    } catch (IOException ex) {
        throw new EsHadoopTransportException("Invalid target URI " + host, ex);
    }
    client = new HttpClient(params, new SocketTrackingConnectionManager());
    client.setHostConfiguration(hostConfig);

    addHttpAuth(settings, authSettings);
    completeAuth(authSettings);

    HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
    // make sure to disable Nagle's protocol
    connectionParams.setTcpNoDelay(true);

    if (log.isTraceEnabled()) {
        log.trace("Opening HTTP transport to " + httpInfo);
    }
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:55,代码来源:CommonsHttpTransport.java

示例10: prepareHttpClient

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
private void prepareHttpClient() {
    client = new HttpClient();
    HttpClientParams params = client.getParams();
    params.setParameter("http.useragent", "Opera/9.80 (X11; Linux x86_64; U) Presto/2.12.388 Version/12.11");
    client.setParams(params);
}
 
开发者ID:faramir,项目名称:ZawodyWeb,代码行数:7,代码来源:LanguageLA.java

示例11: afterPropertiesSet

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * Private {@link HttpClient} initialization.
 */
@PostConstruct
private final void afterPropertiesSet()
{
	// Client is higher in the hierarchy than manager so set the parameters here
	final HttpClientParams clientParams = new HttpClientParams();
	clientParams.setConnectionManagerClass(connectionManager.getClass());
	clientParams.setConnectionManagerTimeout(connectionTimeout);
	clientParams.setSoTimeout(readTimeout);
	clientParams.setParameter("http.connection.timeout", new Integer(
			connectionTimeout));
	// A retry handler for when a connection fails
	clientParams.setParameter(HttpMethodParams.RETRY_HANDLER,
			new HttpMethodRetryHandler()
			{
				@Override
				public boolean retryMethod(final HttpMethod method,
						final IOException exception, final int executionCount)
				{
					if (executionCount >= retryCount)
					{
						// Do not retry if over max retry count
						return false;
					}
					if (instanceOf(exception, NoHttpResponseException.class))
					{
						// Retry if the server dropped connection on us
						return true;
					}
					if (instanceOf(exception, SocketException.class))
					{
						// Retry if the server reset connection on us
						return true;
					}
					if (instanceOf(exception, SocketTimeoutException.class))
					{
						// Retry if the read timed out
						return true;
					}
					if (!method.isRequestSent())
					{
						// Retry if the request has not been sent fully or
						// if it's OK to retry methods that have been sent
						return true;
					}
					// otherwise do not retry
					return false;
				}
			});
	httpClient.setParams(clientParams);

	final HttpConnectionManagerParams connectionManagerParams = connectionManager
			.getParams();
	connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
	connectionManager.setParams(connectionManagerParams);
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:59,代码来源:HttpClientTemplate.java

示例12: CommonsHttpTransport

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public CommonsHttpTransport(Settings settings, String host) {
    this.settings = settings;
    httpInfo = host;
    sslEnabled = settings.getNetworkSSLEnabled();

    String pathPref = settings.getNodesPathPrefix();
    pathPrefix = (StringUtils.hasText(pathPref) ? addLeadingSlashIfNeeded(StringUtils.trimWhitespace(pathPref)) : StringUtils.trimWhitespace(pathPref));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(
            settings.getHttpRetries(), false) {

        @Override
        public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) {
            if (super.retryMethod(method, exception, executionCount)) {
                stats.netRetries++;
                return true;
            }
            return false;
        }
    });

    params.setConnectionManagerTimeout(settings.getHttpTimeout());
    params.setSoTimeout((int) settings.getHttpTimeout());
    // explicitly set the charset
    params.setCredentialCharset(StringUtils.UTF_8.name());
    params.setContentCharset(StringUtils.UTF_8.name());

    HostConfiguration hostConfig = new HostConfiguration();

    hostConfig = setupSSLIfNeeded(settings, hostConfig);
    hostConfig = setupSocksProxy(settings, hostConfig);
    Object[] authSettings = setupHttpOrHttpsProxy(settings, hostConfig);
    hostConfig = (HostConfiguration) authSettings[0];

    try {
        hostConfig.setHost(new URI(escapeUri(host, sslEnabled), false));
    } catch (IOException ex) {
        throw new EsHadoopTransportException("Invalid target URI " + host, ex);
    }
    client = new HttpClient(params, new SocketTrackingConnectionManager());
    client.setHostConfiguration(hostConfig);

    addHttpAuth(settings, authSettings);
    completeAuth(authSettings);

    HttpConnectionManagerParams connectionParams = client.getHttpConnectionManager().getParams();
    // make sure to disable Nagle's protocol
    connectionParams.setTcpNoDelay(true);

    this.headers = new HeaderProcessor(settings);

    if (log.isTraceEnabled()) {
        log.trace("Opening HTTP transport to " + httpInfo);
    }
}
 
开发者ID:elastic,项目名称:elasticsearch-hadoop,代码行数:57,代码来源:CommonsHttpTransport.java


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