List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager setDefaultMaxPerRoute
public void setDefaultMaxPerRoute(final int max)
From source file:com.mnxfst.testing.client.TSClientPlanExecCallable.java
public TSClientPlanExecCallable(String hostname, int port, String uri, byte[] testplan) { this.httpHost = new HttpHost(hostname, port); // this.getMethod = new HttpGet(uri.toString()); this.postMethod = new HttpPost(uri.toString()); try {/* www . ja v a 2s . c o m*/ String convertedTestplan = new String(testplan, "UTF-8"); postMethod.setEntity(new StringEntity( TSClient.REQUEST_PARAMETER_TESTPLAN + "=" + URLEncoder.encode(convertedTestplan, "UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding exception. Error: " + e.getMessage()); } // TODO setting? SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager threadSafeClientConnectionManager = new ThreadSafeClientConnManager( schemeRegistry); threadSafeClientConnectionManager.setMaxTotal(20); threadSafeClientConnectionManager.setDefaultMaxPerRoute(20); this.httpClient = new DefaultHttpClient(threadSafeClientConnectionManager); }
From source file:com.mnxfst.testing.client.TSClientPlanResultCollectCallable.java
public TSClientPlanResultCollectCallable(String hostname, int port, String uri) { this.httpHost = new HttpHost(hostname, port); this.getMethod = new HttpGet(uri.toString()); // TODO setting? SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); ThreadSafeClientConnManager threadSafeClientConnectionManager = new ThreadSafeClientConnManager( schemeRegistry);// w ww.j a v a2s .co m threadSafeClientConnectionManager.setMaxTotal(20); threadSafeClientConnectionManager.setDefaultMaxPerRoute(20); this.httpClient = new DefaultHttpClient(threadSafeClientConnectionManager); }
From source file:water.ga.GoogleAnalytics.java
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) { ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(); connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config)); BasicHttpParams params = new BasicHttpParams(); if (isNotEmpty(config.getUserAgent())) { params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent()); }/* ww w .j a v a 2 s . c o m*/ if (isNotEmpty(config.getProxyHost())) { params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort())); } DefaultHttpClient client = new DefaultHttpClient(connManager, params); if (isNotEmpty(config.getProxyUserName())) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword())); client.setCredentialsProvider(credentialsProvider); } return client; }
From source file:org.energy_home.jemma.utils.rest.RestClient.java
private RestClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); // allow working with all hostname server (hostname verification default turned off) sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); schemeRegistry.register(new Scheme("https", 443, sslSocketFactory)); ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(schemeRegistry); // TODO: check for final values // Decrease max total connection to 10 (default is 20) connectionManager.setMaxTotal(10);//from ww w.j a va 2s.c om // Increase default max connection per route to 5 (default is 2) connectionManager.setDefaultMaxPerRoute(10); // // Increase max connections for localhost:80 to 50 // HttpHost localhost = new HttpHost("locahost", 80); // cm.setMaxForRoute(new HttpRoute(localhost), 50); // // Increase max connections for a specific host to 10 // connectionManager.setMaxForRoute(new HttpRoute(httpHost), 10); httpClient = new DefaultHttpClient(connectionManager); httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0); // Default to HTTP 1.0 httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); // The time it takes to open TCP connection. // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, // 15000); // Timeout when server does not send data. httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT); // Some tuning that is not required for bit tests. // httpClient.getParams().setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, // false); // httpClient.getParams().setParameter(CoreConnectionPNames.TCP_NODELAY, // true); httpContext = new BasicHttpContext(); }
From source file:com.itude.mobile.mobbl.core.services.datamanager.handlers.MBRESTServiceDataHandler.java
@Override public MBDocument doLoadDocument(String documentName, MBDocument args) { MBEndPointDefinition endPoint = getEndPointForDocument(documentName); if (endPoint != null) { LOGGER.debug(//from w w w . ja v a2s .com "MBRESTServiceDataHandler:loadDocument " + documentName + " from " + endPoint.getEndPointUri()); String dataString = null; MBDocument responseDoc = null; String body = args.getValueForPath("/*[0]").toString(); try { HttpPost httpPost = new HttpPost(endPoint.getEndPointUri()); // Content-Type must be set because otherwise the MidletCommandProcessor servlet cannot read the XML httpPost.setHeader("Content-Type", "text/xml"); if (body != null) { httpPost.setEntity(new StringEntity(body)); } HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = DEFAULT_TIMEOUTCONNECTION; // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = DEFAULT_TIMEOUT_SOCKET; SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 8080, PlainSocketFactory.getSocketFactory())); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(registry, timeoutConnection, TimeUnit.MILLISECONDS); cm.setMaxTotal(MAX_TOTAL_CONNECTIONS); cm.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE); HttpClient httpClient = new DefaultHttpClient(cm, httpParameters); if (endPoint.getTimeout() > 0) { timeoutSocket = endPoint.getTimeout() * 1000; timeoutConnection = endPoint.getTimeout() * 1000; } HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); if (ALLOW_ANY_CERTIFICATE) allowAnyCertificate(httpClient); HttpResponse httpResponse = httpClient.execute(httpPost); int responseCode = httpResponse.getStatusLine().getStatusCode(); String responseMessage = httpResponse.getStatusLine().getReasonPhrase(); if (responseCode != HttpStatus.SC_OK) { LOGGER.error("MBRESTServiceDataHandler.loadDocument: Received HTTP responseCode=" + responseCode + ": " + responseMessage); } HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream inStream = entity.getContent(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int i = inStream.read(buffer); while (i > -1) { bos.write(buffer, 0, i); i = inStream.read(buffer); } inStream.close(); dataString = new String(bos.toByteArray()); } boolean serverErrorHandled = false; for (MBResultListenerDefinition lsnr : endPoint.getResultListeners()) { if (lsnr.matches(dataString)) { MBResultListener rl = _applicationFactory.createResultListener(lsnr.getName()); rl.handleResult(dataString, args, lsnr); serverErrorHandled = true; } } /* if (delegate.err != nil) { String errorMessage = null; //[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; Log.w("MOBBL","An error ("+errorMessage+") occured while accessing endpoint "+endPoint.getEndPointUri()); throw new NetworkErrorException(MBLocalizationService.getInstance().textForKey((errorMessage); } //[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; */ if (dataString != null) { byte[] data = dataString.getBytes(); responseDoc = MBDocumentFactory.getInstance().getDocumentWithData(data, getDocumentFactoryType(), MBMetadataService.getInstance().getDefinitionForDocumentName(documentName)); } // if the response document is empty and unhandled by endpoint listeners let the user know there is a problem if (!serverErrorHandled && responseDoc == null) { String msg = MBLocalizationService.getInstance() .getTextForKey("The server returned an error. Please try again later"); // if(delegate.err != nil) { // msg = [NSString stringWithFormat:@"%@ %@: %@", msg, delegate.err.domain, delegate.err.code]; // } throw new MBServerErrorException(msg); } } // TODO: clean up exception handling catch (Exception e) { // debug in stead of info because it can contain a password LOGGER.debug("Sent xml:\n" + body); LOGGER.info("Received:\n" + dataString); if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new ItudeRuntimeException(e); } return responseDoc; } else { LOGGER.warn("No endpoint defined for document name " + documentName); return null; } }
From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java
public RasterDirectLayer(List<RasterTile> tiles, int tileWidth, int tileHeight, double tileScale, String style) {//from w ww. ja va 2 s. c o m super(); this.tileScale = tileScale; this.tiles = tiles; if (tileWidth < 1) { tileWidth = 1; } this.tileWidth = tileWidth; if (tileHeight < 1) { tileHeight = 1; } this.tileHeight = tileHeight; this.style = style; ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(); manager.setDefaultMaxPerRoute(10); httpClient = new DefaultHttpClient(manager); }
From source file:org.apache.abdera2.common.protocol.BasicClient.java
/** * Default initialization of the Client Connection Manager, * subclasses may overload this to customize the connection * manager configuration/*from ww w . j a v a2s . c o m*/ */ protected ClientConnectionManager initConnectionManager(SchemeRegistry sr) { ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(sr); cm.setDefaultMaxPerRoute(initDefaultMaxConnectionsPerRoute()); cm.setMaxTotal(initDefaultMaxTotalConnections()); return cm; }
From source file:com.bigdata.rdf.sail.webapp.AbstractProtocolTest.java
protected ClientConnectionManager newInstance() { final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(newSchemeRegistry()); // Increase max total connection to 200 cm.setMaxTotal(200);/*from w w w. j av a 2 s . c o m*/ // Increase default max connection per route to 20 cm.setDefaultMaxPerRoute(20); // Increase max connections for localhost to 50 final HttpHost localhost = new HttpHost("locahost"); cm.setMaxForRoute(new HttpRoute(localhost), 50); return cm; }
From source file:org.apache.abdera2.common.protocol.BasicClient.java
/** * Set the maximum number of connections allowed for a single host. This * is only effective if the Connection Manager implementation used is * a ThreadSafeClientConnManager, otherwise, an IllegalStateException is * thrown. Subclasses can override this method if a different Client * Connection Manager implementation is used that supports setting the * max connections per host.//from ww w . j a va2 s . com */ public <T extends Client> T setMaxConnectionsPerHost(int max) { ClientConnectionManager ccm = client.getConnectionManager(); if (ccm instanceof ThreadSafeClientConnManager) { ThreadSafeClientConnManager cm = (ThreadSafeClientConnManager) ccm; cm.setDefaultMaxPerRoute(max); } else { throw new IllegalStateException(); } return (T) this; }