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


Java HttpClientParams.setSoTimeout方法代码示例

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


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

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

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

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

示例7: getInstanceHttpClient

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
public HttpClient getInstanceHttpClient() {
    HttpClient client = new HttpClient();

    HttpClientParams params = client.getParams();
    params.setConnectionManagerTimeout(DEFAULT_TIMEOUT);
    params.setSoTimeout(DEFAULT_TIMEOUT);

    if (Jenkins.getInstance() == null) return client;

    ProxyConfiguration proxy = getInstance().proxy;
    if (proxy == null) return client;

    logger.log(Level.FINE, "Jenkins proxy: {0}:{1}", new Object[]{ proxy.name, proxy.port });
    client.getHostConfiguration().setProxy(proxy.name, proxy.port);
    String username = proxy.getUserName();
    String password = proxy.getPassword();

    // Consider it to be passed if username specified. Sufficient?
    if (username != null && !"".equals(username.trim())) {
        logger.log(Level.FINE, "Using proxy authentication (user={0})", username);
        client.getState().setProxyCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(username, password));
    }
    
    return client;
}
 
开发者ID:nishio-dens,项目名称:bitbucket-pullrequest-builder-plugin,代码行数:27,代码来源:ApiClient.java

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

示例9: start

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
	logger.info("Starting {}", CcuClient.class.getSimpleName());
	super.start();

	tclregaScripts = loadTclRegaScripts();

	httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
	HttpClientParams params = httpClient.getParams();
	Long timeout = context.getConfig().getTimeout() * 1000L;
	params.setConnectionManagerTimeout(timeout);
	params.setSoTimeout(timeout.intValue());
	params.setContentCharset("ISO-8859-1");
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:18,代码来源:CcuClient.java

示例10: MineralOccurrenceDownloadService

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
@Autowired
public MineralOccurrenceDownloadService(HttpServiceCaller httpServiceCaller,
                                 WFSGetFeatureMethodMaker methodMaker) {
    super(httpServiceCaller, methodMaker);

    client=new HttpClient();
    HttpClientParams clientParams=new HttpClientParams();
    clientParams.setSoTimeout(DEFAULT_TIMEOUT);//VT 2 hours

    client.setParams(clientParams);
}
 
开发者ID:AuScope,项目名称:detcrc-portal,代码行数:12,代码来源:MineralOccurrenceDownloadService.java

示例11: start

import org.apache.commons.httpclient.params.HttpClientParams; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
    logger.info("Starting {}", CcuClient.class.getSimpleName());
    super.start();

    tclregaScripts = loadTclRegaScripts();

    httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
    HttpClientParams params = httpClient.getParams();
    Long timeout = context.getConfig().getTimeout() * 1000L;
    params.setConnectionManagerTimeout(timeout);
    params.setSoTimeout(timeout.intValue());
    params.setContentCharset("ISO-8859-1");
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:CcuClient.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);

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

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

示例14: 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.setSoTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。