本文整理汇总了Java中org.apache.commons.httpclient.MultiThreadedHttpConnectionManager类的典型用法代码示例。如果您正苦于以下问题:Java MultiThreadedHttpConnectionManager类的具体用法?Java MultiThreadedHttpConnectionManager怎么用?Java MultiThreadedHttpConnectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiThreadedHttpConnectionManager类属于org.apache.commons.httpclient包,在下文中一共展示了MultiThreadedHttpConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HttpProtocolHandler
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
/**
* 私有的构造方法
*/
private HttpProtocolHandler() {
// 创建一个线程安全的HTTP连接池
connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);
connectionManager.getParams().setMaxTotalConnections(defaultMaxTotalConn);
IdleConnectionTimeoutThread ict = new IdleConnectionTimeoutThread();
ict.addConnectionManager(connectionManager);
ict.setConnectionTimeout(defaultIdleConnTimeout);
ict.start();
}
示例2: HttpClientTransmitterImpl
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
public HttpClientTransmitterImpl()
{
protocolMap = new TreeMap<String,Protocol>();
protocolMap.put(HTTP_SCHEME_NAME, httpProtocol);
protocolMap.put(HTTPS_SCHEME_NAME, httpsProtocol);
httpClient = new HttpClient();
httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
httpMethodFactory = new StandardHttpMethodFactoryImpl();
jsonErrorSerializer = new ExceptionJsonSerializer();
// Create an HTTP Proxy Host if appropriate system properties are set
httpProxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
httpProxyCredentials = HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword");
httpAuthScope = createProxyAuthScope(httpProxyHost);
// Create an HTTPS Proxy Host if appropriate system properties are set
httpsProxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
httpsProxyCredentials = HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword");
httpsAuthScope = createProxyAuthScope(httpsProxyHost);
}
示例3: constructHttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的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;
}
示例4: getMaxConnectionsPerHost
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
/**
* Gets the maximum number of connections to be used for a particular host config. If
* the value has not been specified for the given host the default value will be
* returned.
*
* @param hostConfiguration The host config.
* @return The maximum number of connections to be used for the given host config.
*
* @see #MAX_HOST_CONNECTIONS
*/
public int getMaxConnectionsPerHost(HostConfiguration hostConfiguration) {
Map m = (Map) getParameter(MAX_HOST_CONNECTIONS);
if (m == null) {
// MAX_HOST_CONNECTIONS have not been configured, using the default value
return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
} else {
Integer max = (Integer) m.get(hostConfiguration);
if (max == null && hostConfiguration != HostConfiguration.ANY_HOST_CONFIGURATION) {
// the value has not been configured specifically for this host config,
// use the default value
return getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
} else {
return (
max == null
? MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS
: max.intValue()
);
}
}
}
示例5: getInputStreamFromUrl
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
public static InputStream getInputStreamFromUrl(final String url, final String user, final String password) {
try {
final Pair<String, Integer> hostAndPort = validateUrl(url);
final HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
final Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
}
// Execute the method.
final GetMethod method = new GetMethod(url);
final int statusCode = httpclient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
return method.getResponseBodyAsStream();
} catch (final Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
示例6: getHttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的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: DiamondSDKManagerImpl
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
public DiamondSDKManagerImpl(int connection_timeout, int require_timeout) throws IllegalArgumentException {
if (connection_timeout < 0)
throw new IllegalArgumentException("连接超时时间设置必须大于0[单位(毫秒)]!");
if (require_timeout < 0)
throw new IllegalArgumentException("请求超时时间设置必须大于0[单位(毫秒)]!");
this.connection_timeout = connection_timeout;
this.require_timeout = require_timeout;
int maxHostConnections = 50;
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
connectionManager.getParams().setStaleCheckingEnabled(true);
this.client = new HttpClient(connectionManager);
// 设置连接超时时间
client.getHttpConnectionManager().getParams().setConnectionTimeout(this.connection_timeout);
// 设置读超时为1分钟
client.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
client.getParams().setContentCharset("UTF-8");
log.info("设置连接超时时间为: " + this.connection_timeout + "毫秒");
}
示例8: initHttpClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
protected void initHttpClient() {
if (MockServer.isTestMode()) {
return;
}
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()),
diamondConfigure.getPort());
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000);
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections());
params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections());
params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
// 设置读超时为1分钟,
// [email protected]
params.setSoTimeout(60 * 1000);
connectionManager.setParams(params);
httpClient = new HttpClient(connectionManager);
httpClient.setHostConfiguration(hostConfiguration);
}
示例9: init
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的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;
}
示例10: processor
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
@Bean
public SAMLProcessorImpl processor() {
HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(httpClient);
HTTPSOAP11Binding soapBinding = new HTTPSOAP11Binding(parserPool());
artifactResolutionProfile.setProcessor(new SAMLProcessorImpl(soapBinding));
VelocityEngine velocityEngine = VelocityFactory.getEngine();
Collection<SAMLBinding> bindings = new ArrayList<>();
bindings.add(new HTTPRedirectDeflateBinding(parserPool()));
bindings.add(new HTTPPostBinding(parserPool(), velocityEngine));
bindings.add(new HTTPArtifactBinding(parserPool(), velocityEngine, artifactResolutionProfile));
bindings.add(new HTTPSOAP11Binding(parserPool()));
bindings.add(new HTTPPAOS11Binding(parserPool()));
return new SAMLProcessorImpl(bindings);
}
示例11: FullTextSearchEngine
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
/**
* @param multiThreadedHttpConnectionManager
* The
* @link {@link MultiThreadedHttpConnectionManager} that the fulltext search
* engine will use
* @throws FullTextSearchException
* If an error occured
*/
@Autowired
public FullTextSearchEngine(
@Qualifier("multiThreadedHttpConnectionManager")
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager)
throws FullTextSearchException {
Assert.notNull(multiThreadedHttpConnectionManager,
"multiThreadedHttpConnectionManager can not be null");
HttpConnectionManagerParams p = new HttpConnectionManagerParams();
p.setSoTimeout(0);
p.setConnectionTimeout(0);
multiThreadedHttpConnectionManager.setParams(p);
this.httpClient = new HttpClient(multiThreadedHttpConnectionManager);
if (this.httpClient == null) {
throw new FullTextSearchException(
"Can not instanciate http client with multiThreadedHttpConnectionManager : "
+ multiThreadedHttpConnectionManager);
}
}
示例12: SolrClient
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
/**
* @param solrUrl
* The solr URL of the server to connect
*/
@Autowired
public SolrClient(@Qualifier("fulltextSearchUrl")
String solrUrl, @Qualifier("multiThreadedHttpConnectionManager")
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager) {
try {
Assert.notNull(solrUrl, "solrClient does not accept null solrUrl");
Assert
.notNull(multiThreadedHttpConnectionManager,
"solrClient does not accept null multiThreadedHttpConnectionManager");
this.multiThreadedHttpConnectionManager = multiThreadedHttpConnectionManager;
this.server = new CommonsHttpSolrServer(new URL(solrUrl),
new HttpClient(multiThreadedHttpConnectionManager));
this.URL = !solrUrl.endsWith("/") ? solrUrl + "/" : solrUrl ;
logger.info("connecting to solr on " + this.URL + "...");
} catch (MalformedURLException e) {
throw new RuntimeException("Error connecting to Solr! : "
+ e.getMessage());
}
}
示例13: testIsAlive
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
@Test
public void testIsAlive() {
assertTrue(fullTextSearchEngine.isAlive());
FullTextSearchEngine fullTextSearchEngineTobadUrl = new FullTextSearchEngine(
new MultiThreadedHttpConnectionManager());
IsolrClient mockSolClient = EasyMock.createMock(IsolrClient.class);
EasyMock.expect(mockSolClient.isServerAlive()).andReturn(false);
EasyMock.replay(mockSolClient);
fullTextSearchEngineTobadUrl.setSolrClient(mockSolClient);
assertFalse(fullTextSearchEngineTobadUrl.isAlive());
EasyMock.verify(mockSolClient);
FullTextSearchEngine fullTextSearchEngineWithNullSolrClient = new FullTextSearchEngine(
new MultiThreadedHttpConnectionManager());
fullTextSearchEngineWithNullSolrClient.setSolrClient(null);
assertFalse(fullTextSearchEngineWithNullSolrClient.isAlive());
}
示例14: init
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的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);
}
示例15: initConfigurationContext
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; //导入依赖的package包/类
private void initConfigurationContext() throws Exception {
HttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
File configFile = new File(DEFAULT_AXIS2_XML);
if (!configFile.exists()) {
configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
configurationContext.setProperty(HTTPConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST, MAX_CONNECTIONS_PER_HOST);
} else {
configurationContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(DEFAULT_CLIENT_REPO, DEFAULT_AXIS2_XML);
}
configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
Map<String, TransportOutDescription> transportsOut =
configurationContext.getAxisConfiguration().getTransportsOut();
for (TransportOutDescription transportOutDescription : transportsOut.values()) {
if (Constants.TRANSPORT_HTTP.equals(transportOutDescription.getName()) ||
Constants.TRANSPORT_HTTPS.equals(transportOutDescription.getName())) {
transportOutDescription.getSender().init(configurationContext, transportOutDescription);
}
}
}