List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.wso2.carbon.mediator.ntlm.NTLMMediator.java
public boolean mediate(MessageContext messageContext) { // Instantiate a new Http Authenticator with NTLM Auth Scheme HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); List<String> authScheme = new ArrayList<String>(); authScheme.add(HttpTransportProperties.Authenticator.NTLM); authenticator.setAuthSchemes(authScheme); // Set the NTLM credentials if (username != null) { authenticator.setUsername(username); } else {//from w ww . ja va2 s.c om authenticator.setUsername((String) messageContext.getProperty("username")); } if (password != null) { authenticator.setPassword(password); } else { authenticator.setPassword((String) messageContext.getProperty("password")); } if (host != null) { authenticator.setHost(host); } else { authenticator.setHost((String) messageContext.getProperty("host")); } if (domain != null) { authenticator.setDomain(domain); } else { authenticator.setDomain((String) messageContext.getProperty("domain")); } // Set the new NTLM authenticator as the authenticator to the Axis2 ServiceClient which // will be set at the underlying HttpClient org.apache.axis2.context.MessageContext axis2MsgCtxt = getAxis2MessageContext(messageContext); axis2MsgCtxt.getOptions().setProperty(HTTPConstants.AUTHENTICATE, authenticator); axis2MsgCtxt.getOptions().setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); //axis2MsgCtxt.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); // Read the MultiThreadedHttpConnectionManager from the cache MultiThreadedHttpConnectionManager connectionManager; String cacheKey = new StringBuilder().append(authenticator.getUsername()).append("@") .append(authenticator.getDomain()).append(":").append(authenticator.getPassword()).toString(); if (connectionManagerCache.containsKey(cacheKey)) { connectionManager = connectionManagerCache.get(cacheKey); } else { connectionManager = connectionManagerCache.put(cacheKey, new MultiThreadedHttpConnectionManager()); } axis2MsgCtxt.getOptions().setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connectionManager); return true; }
From source file:org.wso2.carbon.micro.integrator.core.internal.ServiceComponent.java
private ConfigurationContext getClientConfigurationContext() throws AxisFault { String clientRepositoryLocation = serverConfig.getFirstProperty(CLIENT_REPOSITORY_LOCATION); String clientAxis2XmlLocationn = serverConfig.getFirstProperty(CLIENT_AXIS2_XML_LOCATION); ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn); MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); // Set the default max connections per host int defaultMaxConnPerHost = 500; Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration() .getParameter("defaultMaxConnPerHost"); if (defaultMaxConnPerHostParam != null) { defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue()); }//from ww w .jav a2 s . co m params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost); // Set the max total connections int maxTotalConnections = 15000; Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration() .getParameter("maxTotalConnections"); if (maxTotalConnectionsParam != null) { maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue()); } params.setMaxTotalConnections(maxTotalConnections); params.setSoTimeout(600000); params.setConnectionTimeout(600000); httpConnectionManager.setParams(params); clientConfigContextToReturn.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, httpConnectionManager); // registerHouseKeepingTask(clientConfigContextToReturn); clientConfigContextToReturn.setProperty(ServerConstants.WORK_DIR, serverWorkDir); return clientConfigContextToReturn; }
From source file:org.wso2.carbon.oc.agent.publisher.rt.RTPublisher.java
@Override public void init(OCPublisherConfiguration ocPublisherConfiguration) { // get set config Map<String, String> configMap = ocPublisherConfiguration.getOcPublisherProperties().getPropertyMap(); String username = configMap.get(RTConstants.USERNAME); String password = configMap.get(RTConstants.PASSWORD); this.ocUrl = configMap.get(RTConstants.REPORT_URL); this.interval = Long.parseLong(configMap.get(RTConstants.INTERVAL)); if (StringUtils.isBlank(this.ocUrl)) { throw new IllegalArgumentException("Operations Center URL is unspecified."); }//from w w w.j a v a2 s. c om this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); this.httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); this.httpClient.getParams().setAuthenticationPreemptive(true); logger.info("RTPublisher init done"); }
From source file:org.wso2.carbon.oc.internal.OperationsCenterConnector.java
public OperationsCenterConnector(String ocUrl, String username, String password) { this.ocUrl = ocUrl; if (StringUtils.isBlank(this.ocUrl)) { throw new IllegalArgumentException("Operations Center URL is unspecified."); }/*from ww w.j a v a 2 s .c om*/ this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); this.httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); this.httpClient.getParams().setAuthenticationPreemptive(true); }
From source file:org.wso2.carbon.webapp.authenticator.framework.Utils.OAuthTokenValidationStubFactory.java
/** * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs * * @param properties Properties to configure MultiThreadedHttpConnectionManager * @return An instance of properly configured MultiThreadedHttpConnectionManager *///from w w w . j av a2 s. c o m 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; }
From source file:org.wso2.esb.integration.common.utils.clients.axis2client.ConfigurationContextProvider.java
public ConfigurationContextProvider() { try {//from ww w.j av a2 s.co m MultiThreadedHttpConnectionManager httpConnectionManager; HttpClient httpClient; HttpConnectionManagerParams params; configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem( TestConfigurationProvider.getResourceLocation() + File.separator + "client", null); httpConnectionManager = new MultiThreadedHttpConnectionManager(); params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(25); httpConnectionManager.setParams(params); httpClient = new HttpClient(httpConnectionManager); configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); } catch (AxisFault axisFault) { log.error(axisFault); } }
From source file:org.wso2.siddhi.extension.output.transport.http.HttpOutputTransport.java
@Override public void init(String type, Map<String, String> options, Map<String, String> unmappedDynamicOptions) { if (executorService == null) { int minThread = (options.get(ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) ? Integer.parseInt(options.get(ADAPTER_MIN_THREAD_POOL_SIZE_NAME)) : ADAPTER_MIN_THREAD_POOL_SIZE; int maxThread = (options.get(ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) ? Integer.parseInt(options.get(ADAPTER_MAX_THREAD_POOL_SIZE_NAME)) : ADAPTER_MAX_THREAD_POOL_SIZE; long defaultKeepAliveTime = (options.get(ADAPTER_KEEP_ALIVE_TIME_NAME) != null) ? Integer.parseInt(options.get(ADAPTER_KEEP_ALIVE_TIME_NAME)) : DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; int jobQueSize = (options.get(ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) ? Integer.parseInt(options.get(ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)) : ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; int defaultMaxConnectionsPerHost = (options.get(DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) ? Integer.parseInt(options.get(DEFAULT_MAX_CONNECTIONS_PER_HOST)) : DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST; int maxTotalConnections = (options.get(MAX_TOTAL_CONNECTIONS) != null) ? Integer.parseInt(options.get(MAX_TOTAL_CONNECTIONS)) : DEFAULT_MAX_TOTAL_CONNECTIONS; executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost); connectionManager.getParams().setMaxTotalConnections(maxTotalConnections); }/*from w w w.j ava 2 s . co m*/ }
From source file:org.xwiki.rendering.internal.transformation.linkchecker.DefaultHTTPChecker.java
@Override public void initialize() throws InitializationException { this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // Set our user agent to be a good citizen. this.httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, "XWikiLinkChecker"); // Ignore cookies since this can cause errors in logs and we don't need cookies when checking sites. this.httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); }
From source file:org.xwiki.xwoot.manager.internal.DefaultXWootManager.java
/** * Initializes the HTTP client utility. Called by the component manager when this component is instantiated. * //w w w .j a v a 2 s . c om * @see Initializable#initialize() */ public void initialize() throws InitializationException { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connectionManager); client.getParams().setSoTimeout(2000); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, true)); try { documentBridge = (DocumentAccessBridge) componentManager.lookup(DocumentAccessBridge.class.getName()); } catch (ComponentLookupException e) { throw new InitializationException(e.getMessage()); } }
From source file:org.ybygjy.httpclient.MultiThreadedExample.java
public static void main(String[] args) { // Create an HttpClient with the MultiThreadedHttpConnectionManager. // This connection manager must be used if more than one thread will // be using the HttpClient. HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // Set the default host/protocol for the methods to connect to. // This value will only be used if the methods are not given an absolute URI httpClient.getHostConfiguration().setHost("jakarta.apache.org", 80, "http"); // create an array of URIs to perform GETs on String[] urisToGet = { "/", "/commons/", "/commons/httpclient/", "http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/" }; // create a thread for each URI GetThread[] threads = new GetThread[urisToGet.length]; for (int i = 0; i < threads.length; i++) { GetMethod get = new GetMethod(urisToGet[i]); get.setFollowRedirects(true);// w w w . j av a2 s .c om threads[i] = new GetThread(httpClient, get, i + 1); } // start the threads for (int j = 0; j < threads.length; j++) { threads[j].start(); } }