org.apache.commons.httpclient.HttpConnectionManager Java Examples

The following examples show how to use org.apache.commons.httpclient.HttpConnectionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicAuthEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #2
Source File: HttpClientFactory.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: HttpClientFactory.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: BasicAuthEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #5
Source File: IdleConnectionTimeoutThread.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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();
}
 
Example #6
Source File: HttpFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/** @since 2.0 */
@Override
public void closeCommunicationLink() {
    if (getClient() != null) {
        final HttpConnectionManager mgr = getClient().getHttpConnectionManager();
        if (mgr instanceof MultiThreadedHttpConnectionManager) {
            ((MultiThreadedHttpConnectionManager) mgr).shutdown();
        }
    }
}
 
Example #7
Source File: TableSizeReader.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public TableSizeReader(Executor executor, HttpConnectionManager connectionManager,
    ControllerMetrics controllerMetrics, PinotHelixResourceManager helixResourceManager) {
  _executor = executor;
  _connectionManager = connectionManager;
  _controllerMetrics = controllerMetrics;
  _helixResourceManager = helixResourceManager;
}
 
Example #8
Source File: SegmentValidator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public SegmentValidator(PinotHelixResourceManager pinotHelixResourceManager, ControllerConf controllerConf,
    Executor executor, HttpConnectionManager connectionManager, ControllerMetrics controllerMetrics,
    boolean isLeaderForTable) {
  _pinotHelixResourceManager = pinotHelixResourceManager;
  _controllerConf = controllerConf;
  _executor = executor;
  _connectionManager = connectionManager;
  _controllerMetrics = controllerMetrics;
  _isLeaderForTable = isLeaderForTable;
}
 
Example #9
Source File: APIFactory.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Create an HTTP connection.
 * 
 * @return A HTTP connection.
 */
private static HttpClient createHttpClient(HttpConnectionManager manager) {
  HttpClient client = new HttpClient(manager);
  client.getParams().setParameter(
      HttpMethodParams.USER_AGENT,
      "WPCleaner (+http://en.wikipedia.org/wiki/User:NicoV/Wikipedia_Cleaner/Documentation)");
  return client;
}
 
Example #10
Source File: IdleConnectionTimeoutThread.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: OAuthTokenValidationStubFactory.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 */
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances " +
                "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties.getProperty("MaxConnectionsPerHost");
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " +
                    "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties.getProperty("MaxTotalConnections");
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " +
                    "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}
 
Example #12
Source File: OAuthTokenValidationStubFactory.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: FileServiceDataSetCRUD.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * get CSV file from remote Url
 *
 * @param url
 * @return
 * @throws HttpException
 * @throws IOException
 */
byte[] getCSVFile(String url) throws HttpException, IOException {
	logger.debug("IN");
	HttpClient client = new HttpClient();
	HttpConnectionManager conManager = client.getHttpConnectionManager();

	// Cancel, proxy settings made on server
	// logger.debug("Setting proxy");
	// client.getHostConfiguration().setProxy("192.168.10.1", 3128);
	// HttpState state = new HttpState();
	// state.setProxyCredentials(null, null, new UsernamePasswordCredentials("", ""));
	// client.setState(state);
	// logger.debug("proxy set");
	// cancel

	GetMethod httpGet = new GetMethod(url);
	int statusCode = client.executeMethod(httpGet);
	logger.debug("Status code after request to remote URL is " + statusCode);
	byte[] response = httpGet.getResponseBody();

	if (response == null) {
		logger.warn("Response of remote URL is empty");
	}

	httpGet.releaseConnection();
	logger.debug("OUT");
	return response;
}
 
Example #14
Source File: AbstractHttpClient.java    From alfresco-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void close()
{
   if(httpClient != null)
   {
       HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager();
       if(connectionManager instanceof MultiThreadedHttpConnectionManager)
       {
           ((MultiThreadedHttpConnectionManager)connectionManager).shutdown();
       }
   }
    
}
 
Example #15
Source File: IdleConnectionMonitorThread.java    From RestServices with Apache License 2.0 4 votes vote down vote up
public IdleConnectionMonitorThread(HttpConnectionManager connMgr, long intervalMillis, long maxIdleTimeMillis) {
	super();
	this.connMgr = connMgr;
	this.intervalMillis = intervalMillis;
	this.maxIdleTimeMillis = maxIdleTimeMillis;
}
 
Example #16
Source File: ProxyContext.java    From flex-blazeds with Apache License 2.0 4 votes vote down vote up
public HttpConnectionManager getConnectionManager()
{
    return connectionManager;
}
 
Example #17
Source File: ProxyContext.java    From flex-blazeds with Apache License 2.0 4 votes vote down vote up
public void setConnectionManager(HttpConnectionManager connectionManager)
{
    this.connectionManager = connectionManager;
}
 
Example #18
Source File: ServerTableSizeReader.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public ServerTableSizeReader(Executor executor, HttpConnectionManager connectionManager) {
  _executor = executor;
  _connectionManager = connectionManager;
}
 
Example #19
Source File: MultiGetRequest.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * @param executor executor service to use for making parallel requests
 * @param connectionManager http connection manager to use.
 */
public MultiGetRequest(Executor executor, HttpConnectionManager connectionManager) {
  _executor = executor;
  _connectionManager = connectionManager;
}
 
Example #20
Source File: TraceeHttpClientDecorator.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public synchronized HttpConnectionManager getHttpConnectionManager() {
	return delegate.getHttpConnectionManager();
}
 
Example #21
Source File: TraceeHttpClientDecorator.java    From tracee with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public synchronized void setHttpConnectionManager(HttpConnectionManager httpConnectionManager) {
	delegate.setHttpConnectionManager(httpConnectionManager);
}
 
Example #22
Source File: IdleConnectionTimeoutThread.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Adds a connection manager to be handled by this class.  
 * {@link HttpConnectionManager#closeIdleConnections(long)} will be called on the connection
 * manager every {@link #setTimeoutInterval(long) timeoutInterval} milliseconds.
 * 
 * @param connectionManager The connection manager to add
 */
public synchronized void addConnectionManager(HttpConnectionManager connectionManager) {
    if (shutdown) {
        throw new IllegalStateException("IdleConnectionTimeoutThread has been shutdown");
    }
    this.connectionManagers.add(connectionManager);
}
 
Example #23
Source File: IdleConnectionTimeoutThread.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Handles calling {@link HttpConnectionManager#closeIdleConnections(long) closeIdleConnections()}
 * and doing any other cleanup work on the given connection mangaer.
 * @param connectionManager The connection manager to close idle connections for
 */
protected void handleCloseIdleConnections(HttpConnectionManager connectionManager) {
    connectionManager.closeIdleConnections(connectionTimeout);
}