本文整理匯總了Java中org.apache.commons.httpclient.HttpConnectionManager類的典型用法代碼示例。如果您正苦於以下問題:Java HttpConnectionManager類的具體用法?Java HttpConnectionManager怎麽用?Java HttpConnectionManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpConnectionManager類屬於org.apache.commons.httpclient包,在下文中一共展示了HttpConnectionManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
* Closes idle connections.
*/
public synchronized void run() {
while (!shutdown) {
Iterator iter = connectionManagers.iterator();
while (iter.hasNext()) {
HttpConnectionManager connectionManager = (HttpConnectionManager) iter.next();
handleCloseIdleConnections(connectionManager);
}
try {
this.wait(timeoutInterval);
} catch (InterruptedException e) {
}
}
// clear out the connection managers now that we're shutdown
this.connectionManagers.clear();
}
示例2: run
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Override
public void run() {
try {
while (!shutdown) {
synchronized (this) {
wait(5000);
for (HttpConnectionManager m : connMgr) {
// Close expired connections
// m.closeExpiredConnections();
// Optionally, close connections
// that have been idle longer than 30 sec
m.closeIdleConnections(30000);
}
}
}
} catch (InterruptedException ex) {
// terminate
}
}
示例3: initConfigurationContext
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的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);
}
}
}
示例4: getHttpClientInstance
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
* A HttpClient with basic authentication and no host or port setting. Can only be used to retrieve absolute URLs
*
* @param user
* can be NULL
* @param password
* can be NULL
* @return HttpClient
*/
public static HttpClient getHttpClientInstance(String user, String password) {
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionParams params = connectionManager.getParams();
// wait max 10 seconds to establish connection
params.setConnectionTimeout(10000);
// a read() call on the InputStream associated with this Socket
// will block for only this amount
params.setSoTimeout(10000);
HttpClient c = new HttpClient(connectionManager);
// use basic authentication if available
if (user != null && user.length() > 0) {
AuthScope authScope = new AuthScope(null, -1, null);
Credentials credentials = new UsernamePasswordCredentials(user, password);
c.getState().setCredentials(authScope, credentials);
}
return c;
}
示例5: run
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
* Closes idle connections.
*/
public synchronized void run() {
while (!shutdown) {
Iterator iter = connectionManagers.iterator();
while (iter.hasNext()) {
HttpConnectionManager connectionManager = (HttpConnectionManager) iter.next();
connectionManager.closeIdleConnections(connectionTimeout);
}
try {
this.wait(timeoutInterval);
} catch (InterruptedException e) {
}
}
// clear out the connection managers now that we're shutdown
this.connectionManagers.clear();
}
示例6: close
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Override
public void close()
{
if(httpClient != null)
{
HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager();
if(connectionManager instanceof MultiThreadedHttpConnectionManager)
{
((MultiThreadedHttpConnectionManager)connectionManager).shutdown();
}
}
}
示例7: IdleConnectionCloser
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
private IdleConnectionCloser(HttpConnectionManager httpConnectionManager)
{
super("FastServletProxyFactory.IdleConnectionCloser");
this.httpConnectionManager = httpConnectionManager;
this.setName("IdleConnectionCloser");
this.setDaemon(true);
this.setPriority(Thread.MIN_PRIORITY);
}
示例8: logCurrentHttpConnection
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public static void logCurrentHttpConnection(HttpClient httpClient, HostConfiguration hostConfiguration, HttpPool poolMode) {
if (Engine.logEngine.isInfoEnabled() && httpClient != null) {
if (poolMode == HttpPool.no) {
Engine.logEngine.info("(HttpUtils) Use a not pooled HTTP connection for " + hostConfiguration.getHost());
} else {
HttpConnectionManager httpConnectionManager = httpClient.getHttpConnectionManager();
if (httpConnectionManager != null && httpConnectionManager instanceof MultiThreadedHttpConnectionManager) {
MultiThreadedHttpConnectionManager mtHttpConnectionManager = (MultiThreadedHttpConnectionManager) httpConnectionManager;
int connections = mtHttpConnectionManager.getConnectionsInPool();
int connectionsForHost = mtHttpConnectionManager.getConnectionsInPool(hostConfiguration);
Engine.logEngine.info("(HttpUtils) Use a " + poolMode.name() + " pool with " + connections + " HTTP connections, " + connectionsForHost + " for " + hostConfiguration.getHost() + "; Getting one ... [for instance " + httpClient.hashCode() + "]");
}
}
}
}
示例9: removeConnectionManager
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
* Removes the connection manager from this class. The idle connections from the connection
* manager will no longer be automatically closed by this class.
*
* @param connectionManager The connection manager to remove
*/
public synchronized void removeConnectionManager(HttpConnectionManager connectionManager) {
if (shutdown) {
throw new IllegalStateException("IdleConnectionTimeoutThread has been shutdown");
}
this.connectionManagers.remove(connectionManager);
}
示例10: httpConnectionManager
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/**
* 使用獨立的連接管理器。
* @param connectionManager 鏈接管理器
* @return
*/
public HttpReq httpConnectionManager(HttpConnectionManager connectionManager) {
httpConnectionManager = connectionManager;
externalConnectionManager = true;
return this;
}
示例11: RequestConnectionHttp
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public void RequestConnectionHttp(String url, String user, String pass, int timeout) throws Exception {
HttpClient client = new HttpClient();
HttpConnectionManager hcm = client.getHttpConnectionManager();
HttpConnectionManagerParams hcmParam = hcm.getParams();
hcmParam.setConnectionTimeout(timeout + 1000);
hcm.setParams(hcmParam);
client.setHttpConnectionManager(hcm);
if (user != null && pass != null) {
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass));
}
GetMethod get = new GetMethod(url);
get.setDoAuthentication(true);
try {
int status = client.executeMethod(get);
if (status != 200) {
System.out.println(status + "\n" + get.getResponseBodyAsString());
throw new Exception("Failed: status=" + status);
}
setLastcrres("OK");
} catch (Exception e) {
setLastcrres(e.getMessage());
System.out.println("HTTP CR OOPS: " + e.getMessage() + "\n");
throw e;
} finally {
get.releaseConnection();
}
}
示例12: interrupt
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public boolean interrupt() {
HttpClient client = savedClient;
if (client != null) {
savedClient = null;
// TODO - not sure this is the best method
final HttpConnectionManager httpConnectionManager = client.getHttpConnectionManager();
if (httpConnectionManager instanceof SimpleHttpConnectionManager) {// Should be true
((SimpleHttpConnectionManager)httpConnectionManager).shutdown();
}
}
return client != null;
}
示例13: testHttpGetWithoutConversion
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
@Test
public void testHttpGetWithoutConversion() throws Exception {
// This is needed as by default there are 2 parallel
// connections to some host and there is nothing that
// closes the http connection here.
// Need to set the httpConnectionManager
HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(5);
context.getComponent("http", HttpComponent.class).setHttpConnectionManager(httpConnectionManager);
String endpointName = "seda:withoutConversion?concurrentConsumers=5";
sendMessagesTo(endpointName, 5);
}
示例14: HttpEndpoint
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams,
HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException {
super(endPointURI, component, httpURI);
this.clientParams = clientParams;
this.httpClientConfigurer = clientConfigurer;
this.httpConnectionManager = httpConnectionManager;
}
示例15: OAuthTokenValidationStubFactory
import org.apache.commons.httpclient.HttpConnectionManager; //導入依賴的package包/類
public OAuthTokenValidationStubFactory(String url, String adminUsername, String adminPassword,
Properties properties) {
this.validateUrl(url);
this.url = url;
this.validateCredentials(adminUsername, adminPassword);
this.basicAuthHeader = new String(Base64.encodeBase64((adminUsername + ":" + adminPassword).getBytes()));
HttpConnectionManager connectionManager = this.createConnectionManager(properties);
this.httpClient = new HttpClient(connectionManager);
}