List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.eclipsecon.e4rover.client.production.ProductionServer.java
public ProductionServer() { HttpConnectionManager cm = new MultiThreadedHttpConnectionManager(); cm.getParams().setConnectionTimeout(REQUEST_TIMEOUT); httpClient = new HttpClient(cm); classToURIMap.put(IGame.class, IServerConstants.GAME_FILE_URI); classToURIMap.put(IRobot.class, IServerConstants.ROBOT_FILE_URI); classToURIMap.put(IPlayers.class, IServerConstants.PLAYERS_FILE_URI); classToURIMap.put(IPlayerQueue.class, IServerConstants.QUEUE_FILE_URI); classToURIMap.put(IArenaCamImage.class, IServerConstants.IMAGE_FILE_URI); }
From source file:org.eclipsetrader.yahoo.internal.core.connector.StreamingConnector.java
@Override public void run() { BufferedReader in = null;/*from w w w.j a v a 2s. co m*/ char[] buffer = new char[512]; try { HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); Util.setupProxy(client, Util.streamingFeedHost); HttpMethod method = null; while (!isStopping()) { // Check if the connection was not yet initialized or there are changed in the subscriptions. if (in == null || isSubscriptionsChanged()) { try { if (method != null) { method.releaseConnection(); } if (in != null) { in.close(); } } catch (Exception e) { // We can't do anything at this time, ignore } String[] symbols; synchronized (symbolSubscriptions) { Set<String> s = new HashSet<String>(symbolSubscriptions.keySet()); s.add("MSFT"); symbols = s.toArray(new String[s.size()]); setSubscriptionsChanged(false); if (symbols.length == 0) { break; } } method = Util.getStreamingFeedMethod(symbols); client.executeMethod(method); in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); line = new StringBuilder(); script = new StringBuilder(); inTag = false; inScript = false; fetchLatestSnapshot(client, symbols, false); } if (in.ready()) { int length = in.read(buffer); if (length == -1) { in.close(); in = null; continue; } processIncomingChars(buffer, length); } else { // Check stale data List<String> updateList = new ArrayList<String>(); synchronized (symbolSubscriptions) { long currentTime = System.currentTimeMillis(); for (FeedSubscription subscription : symbolSubscriptions.values()) { long elapsedTime = currentTime - subscription.getIdentifierType().getLastUpdate(); if (elapsedTime >= 60000) { updateList.add(subscription.getIdentifierType().getSymbol()); subscription.getIdentifierType().setLastUpdate(currentTime / 60000 * 60000); } } } if (updateList.size() != 0) { fetchLatestSnapshot(client, updateList.toArray(new String[updateList.size()]), true); } } Thread.sleep(100); } } catch (Exception e) { Status status = new Status(IStatus.ERROR, YahooActivator.PLUGIN_ID, 0, "Error reading data", e); YahooActivator.log(status); } finally { try { if (in != null) { in.close(); } } catch (Exception e) { // We can't do anything at this time, ignore } } }
From source file:org.exist.xquery.modules.httpclient.HTTPClientModule.java
private static HttpClient setupHttpClient() { final HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); final HttpClient client = new HttpClient(httpConnectionManager); //config from file if present final String configFile = System.getProperty("http.configfile"); if (configFile != null) { final Path f = Paths.get(configFile); if (Files.exists(f)) { setConfigFromFile(f, client); } else {/*from www . jav a2 s .c o m*/ LOG.warn("http.configfile '" + f.toAbsolutePath() + "' does not exist!"); } } // Legacy: set the proxy server (if any) from system properties final String proxyHost = System.getProperty("http.proxyHost"); if (proxyHost != null) { //TODO: support for http.nonProxyHosts e.g. -Dhttp.nonProxyHosts="*.devonline.gov.uk|*.devon.gov.uk" final ProxyHost proxy = new ProxyHost(proxyHost, Integer.parseInt(System.getProperty("http.proxyPort"))); client.getHostConfiguration().setProxyHost(proxy); } return client; }
From source file:org.exoplatform.services.common.HttpClientImpl.java
private void setHost(String protocol, String host, int port) throws Exception { MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams para = new HttpConnectionManagerParams(); para.setConnectionTimeout(HTTP_TIMEOUT); para.setDefaultMaxConnectionsPerHost(10); para.setMaxTotalConnections(20);//from w w w.jav a 2s .com para.setStaleCheckingEnabled(true); manager.setParams(para); http = new HttpClient(manager); http.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); http.getParams().setParameter("http.socket.timeout", new Integer(HTTP_TIMEOUT)); http.getParams().setParameter("http.protocol.content-charset", "UTF-8"); http.getParams().setCookiePolicy(CookiePolicy.RFC_2109); http.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); if (port < 0) port = 80; HostConfiguration hostConfig = http.getHostConfiguration(); hostConfig.setHost(host, port, protocol); String proxyHost = System.getProperty("httpclient.proxy.host"); if (proxyHost == null || proxyHost.trim().length() < 1) return; String proxyPort = System.getProperty("httpclient.proxy.port"); hostConfig.setProxy(proxyHost, Integer.parseInt(proxyPort)); String username = System.getProperty("httpclient.proxy.username"); String password = System.getProperty("httpclient.proxy.password"); String ntlmHost = System.getProperty("httpclient.proxy.ntlm.host"); String ntlmDomain = System.getProperty("httpclient.proxy.ntlm.domain"); Credentials ntCredentials; if (ntlmHost == null || ntlmDomain == null) { ntCredentials = new UsernamePasswordCredentials(username, password); } else { ntCredentials = new NTCredentials(username, password, ntlmHost, ntlmDomain); } http.getState().setProxyCredentials(AuthScope.ANY, ntCredentials); }
From source file:org.fcrepo.common.http.WebClient.java
private void configureConnectionManager() { logger.debug("User-Agent is '" + wconfig.getUserAgent() + "'"); logger.debug("Max total connections is " + wconfig.getMaxTotalConn()); logger.debug("Max connections per host is " + wconfig.getMaxConnPerHost()); logger.debug("Connection timeout is " + wconfig.getTimeoutSecs()); logger.debug("Socket Connection timeout is " + wconfig.getSockTimeoutSecs()); logger.debug("Follow redirects? " + wconfig.getFollowRedirects()); logger.debug("Max number of redirects to follow is " + wconfig.getMaxRedirects()); m_cManager = new MultiThreadedHttpConnectionManager(); m_cManager.getParams().setDefaultMaxConnectionsPerHost(wconfig.getMaxConnPerHost()); m_cManager.getParams().setMaxTotalConnections(wconfig.getMaxTotalConn()); m_cManager.getParams().setConnectionTimeout(wconfig.getTimeoutSecs() * 1000); m_cManager.getParams().setSoTimeout(wconfig.getSockTimeoutSecs() * 1000); }
From source file:org.firstopen.singularity.util.HTTPConnector.java
/** * @param url//from w ww. j ava2 s . co m */ public HTTPConnector(String url, NameValuePair[] methodNVPairs) { setUrl(url); setMethodNVPairs(methodNVPairs); httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); }
From source file:org.firstopen.singularity.util.HTTPConnector.java
/** * @param url/*from w ww. j av a2 s.c om*/ */ public HTTPConnector(String url) { /* * System.setProperty( "org.apache.commons.logging.Log", * "org.apache.commons.logging.impl.SimpleLog"); * * System.setProperty( * "org.apache.commons.logging.simplelog.showdatetime", "true"); * * System.setProperty( * "org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); * * System.setProperty( * "org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", * "debug"); */ setUrl(url); httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); }
From source file:org.firstopen.singularity.util.HTTPConnector.java
/** * /*from w ww . j av a 2 s .c om*/ */ public HTTPConnector() { httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpclient.getState().setCookiePolicy(CookiePolicy.RFC2109); }
From source file:org.geoserver.gss.HTTPGSSClientFactory.java
HttpClient getClient() { if (client == null) { client = new HttpClient(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); // setting timeouts (one minute hard coded, TODO: make this configurable) params.setSoTimeout(60 * 1000);//from w w w .ja v a 2 s .c o m params.setConnectionTimeout(60 * 1000); params.setDefaultMaxConnectionsPerHost(1); MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(params); client.setHttpConnectionManager(manager); } return client; }
From source file:org.geoserver.security.iride.service.util.factory.http.HttpClientFactory.java
/** * Return a new {@link HttpClient} object, using a {@link MultiThreadedHttpConnectionManager} configured as follows: * <ul>/*from ww w. j a v a2 s . c o m*/ * <li>The timeout (in milliseconds) for waiting until a connection is established set to {@link #connectionTimeout}, * or {@value #DEFAULT_TIMEOUT} if {@link #connectionTimeout} is not set (i.e.: is {@code null})<br /> * A value of zero means that no timeout is used</li> * <li>The socket timeout (<code>SO_TIMEOUT</code>)(in milliseconds) for waiting data set to {@link #socketTimeout}, * or {@value #DEFAULT_TIMEOUT} if {#link {@link #socketTimeout} is not set (i.e.: is {@code null})<br /> * A value of zero means that no timeout is used</li> * </ul> */ @Override protected final HttpClient newInstance() { final HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(this.connectionTimeout == null ? DEFAULT_TIMEOUT : this.connectionTimeout); params.setSoTimeout(this.socketTimeout == null ? DEFAULT_TIMEOUT : this.socketTimeout); final HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(params); final HttpClient httpClient = new HttpClient(); httpClient.setHttpConnectionManager(manager); return httpClient; }