org.apache.commons.httpclient.MultiThreadedHttpConnectionManager Java Examples

The following examples show how to use org.apache.commons.httpclient.MultiThreadedHttpConnectionManager. 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: Manager.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private void createHttpClient() {
    Protocol protocol = Protocol.getProtocol("https");
    if (protocol == null) {
        // ZAP: Dont override an existing protocol - it causes problems with ZAP
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", easyhttps);
    }
    initialState = new HttpState();

    MultiThreadedHttpConnectionManager connectionManager =
            new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(1000);
    connectionManager.getParams().setMaxTotalConnections(1000);

    // connectionManager.set

    httpclient = new HttpClient(connectionManager);
    // httpclient.

}
 
Example #3
Source File: HttpConnectionManagerParams.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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()
                );
        }
    }
}
 
Example #4
Source File: SAMLConfig.java    From spring-boot-security-saml-samples with MIT License 6 votes vote down vote up
@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);
}
 
Example #5
Source File: DefaultDiamondSubscriber.java    From diamond with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: DiamondSDKManagerImpl.java    From diamond with Apache License 2.0 6 votes vote down vote up
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("GBK");
    log.info("设置连接超时时间为: " + this.connection_timeout + "毫秒");
}
 
Example #7
Source File: UriUtils.java    From cosmic with Apache License 2.0 6 votes vote down vote up
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;
        }
    }
 
Example #8
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 #9
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 #10
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 #11
Source File: DefaultDiamondSubscriber.java    From diamond with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: DiamondSDKManagerImpl.java    From diamond with Apache License 2.0 6 votes vote down vote up
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("GBK");
    log.info("设置连接超时时间为: " + this.connection_timeout + "毫秒");
}
 
Example #13
Source File: RemoteLogRepositoryBackend.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
private RemoteLogRepositoryBackend()
{

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(CONCURENT_HTTP_CONNECTIONS);

    /*for (int i = 0; i < CONCURENT_HTTP_CONNECTIONS; i++)
    {
        HttpConnection httpConn = new HttpConnection(REPOSITORY_HOST_ADDRESS, REPOSITORY_HOST_PORT);
        httpConn.setHttpConnectionManager(connectionManager);
    }*/
    _httpClient = new HttpClient(connectionManager);
    /*HostConfiguration hc = new HostConfiguration();
    hc.setHost(REPOSITORY_HOST_ADDRESS, REPOSITORY_HOST_PORT);
    _httpClient.setHostConfiguration(hc);*/
    _dlQueue = new DownloadQueue(CONCURENT_DOWNLOADS);
    _upQueue = new UploadQueue(CONCURENT_UPLOADS);
}
 
Example #14
Source File: HttpClientFactory.java    From alfresco-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #15
Source File: UriUtils.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public static InputStream getInputStreamFromUrl(String url, String user, String password) {

        try {
            Pair<String, Integer> hostAndPort = validateUrl(url);
            HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
            if ((user != null) && (password != null)) {
                httpclient.getParams().setAuthenticationPreemptive(true);
                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.
            GetMethod method = new GetMethod(url);
            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 (Exception ex) {
            s_logger.error("Failed to read from URL: " + url);
            return null;
        }
    }
 
Example #16
Source File: HttpClientTransmitterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #17
Source File: ApacheHttp31SLRFactory.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
public ApacheHttp31SLRFactory() {
  	connectionManager = new MultiThreadedHttpConnectionManager();
  	//connectionManager = new ThreadLocalHttpConnectionManager();
  	hostConfiguration = new HostConfiguration();
HttpClientParams params = new HttpClientParams();
  	http = new HttpClient(params,connectionManager);
  	http.setHostConfiguration(hostConfiguration);
  }
 
Example #18
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 #19
Source File: HttpProtocolHandler.java    From shopping with Apache License 2.0 5 votes vote down vote up
/**
 * 私有的构造方法
 */
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();
}
 
Example #20
Source File: RobotApiModule.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
protected RobotConnection provideRobotConnection() {
  HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

  ThreadFactory threadFactory =
      new ThreadFactoryBuilder().setNameFormat("RobotConnection").build();
  return new HttpRobotConnection(
      httpClient, Executors.newFixedThreadPool(NUMBER_OF_THREADS, threadFactory));
}
 
Example #21
Source File: Authentication.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private Authentication(String token, ZeppelinConfiguration conf) {
  MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  client = new HttpClient(connectionManager);
  this.token = token;

  authEnabled = !conf.isAnonymousAllowed();

  userKey = conf.getString("ZEPPELINHUB_USER_KEY",
      ZEPPELINHUB_USER_KEY, "");

  loginEndpoint = getLoginEndpoint(conf);
}
 
Example #22
Source File: CaseServlet.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient client = new HttpClient(httpConnectionManager);

    HttpMethod httpGet = new GetMethod("http://localhost:8080" + req.getContextPath() + "/case/context-propagate");
    int statusCode = client.executeMethod(httpGet);

    try (PrintWriter printWriter = resp.getWriter()) {
        printWriter.write("success: " + statusCode);
    }
}
 
Example #23
Source File: ClientCollection.java    From rome with Apache License 2.0 5 votes vote down vote up
ClientCollection(final String href, final AuthStrategy authStrategy) throws ProponoException {
    super("Standalone connection", "text", href);
    this.authStrategy = authStrategy;
    try {
        httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
        // TODO: make connection timeout configurable
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
    } catch (final Throwable t) {
        throw new ProponoException("ERROR creating HTTPClient", t);
    }
}
 
Example #24
Source File: HttpClientWrapper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * This is meant for system use so you should not be constructing this,
 * use the {@link HttpRESTUtils#makeReusableHttpClient(boolean, int, javax.servlet.http.Cookie[])} instead
 */
public HttpClientWrapper(HttpClient httpClient, 
        MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager,
        HttpState initialHttpState) {
    super();
    this.httpClient = httpClient;
    this.connectionManager = multiThreadedHttpConnectionManager;
    this.initialHttpState = initialHttpState;
}
 
Example #25
Source File: StratosManagerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private StratosManagerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String ccSocketTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT);

    String ccConnectionTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT)
            == null ?
            StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new StratosManagerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf
                (ccSocketTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, Integer.valueOf
                (ccConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize stratos manager service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}
 
Example #26
Source File: RobotApiModule.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
protected RobotConnection provideRobotConnection() {
  HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

  ThreadFactory threadFactory =
      new ThreadFactoryBuilder().setNameFormat("RobotConnection").build();
  return new HttpRobotConnection(
      httpClient, Executors.newFixedThreadPool(NUMBER_OF_THREADS, threadFactory));
}
 
Example #27
Source File: AuthUtilsTest.java    From httpclientAuthHelper with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    MultiThreadedHttpConnectionManager connManag =  new MultiThreadedHttpConnectionManager();

    HttpConnectionManagerParams managParams = connManag.getParams();

    managParams.setConnectionTimeout(10000); // 1
    managParams.setSoTimeout(10000); //2
    client = new HttpClient(connManag);
    client.getParams().setParameter("http.connection-manager.timeout", new Long(10000)); //3


}
 
Example #28
Source File: HTTPProxyAdapter.java    From flex-blazeds with Apache License 2.0 5 votes vote down vote up
/**
 * Sets <code>HTTPConnectionManagerSettings</code>.
 *
 * @param connectionManagerSettings The connection manager settings.
 */
public void setConnectionManagerSettings(HTTPConnectionManagerSettings connectionManagerSettings)
{
    this.connectionManagerSettings = connectionManagerSettings;
    initHttpConnectionManagerParams(connectionManagerSettings);
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionParams);
}
 
Example #29
Source File: AutoscalerCloudControllerClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private AutoscalerCloudControllerClient() {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(AS_CC_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(AS_CC_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    try {
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
        int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants
                .CLOUD_CONTROLLER_DEFAULT_PORT);
        String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
        String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
        int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);

        stub = new CloudControllerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
                cloudControllerClientTimeout);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (Exception e) {
        log.error("Could not initialize cloud controller client", e);
    }
}
 
Example #30
Source File: CloudControllerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private CloudControllerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String ccSocketTimeout = System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT);

    String ccConnectionTimeout =
            System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT) == null ?
                    StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
                    System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new CloudControllerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions()
                .setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf(ccSocketTimeout));
        stub._getServiceClient().getOptions()
                .setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(ccConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize cloud controller service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}