List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager
public PoolingClientConnectionManager()
From source file:com.autonomy.aci.client.transport.impl.HttpClientFactory.java
/** * Creates an instance of <tt>DefaultHttpClient</tt> with a <tt>ThreadSafeClientConnManager</tt>. * @return an implementation of the <tt>HttpClient</tt> interface. */// ww w.java 2 s .c o m public HttpClient createInstance() { LOGGER.debug("Creating a new instance of DefaultHttpClient with configuration -> {}", toString()); // Create the connection manager which will be default create the necessary schema registry stuff... final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(maxTotalConnections); connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute); // Set the HTTP connection parameters (These are in the HttpCore JavaDocs, NOT the HttpClient ones)... final HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, connectionTimeout); HttpConnectionParams.setLinger(params, linger); HttpConnectionParams.setSocketBufferSize(params, socketBufferSize); HttpConnectionParams.setSoKeepalive(params, soKeepAlive); HttpConnectionParams.setSoReuseaddr(params, soReuseAddr); HttpConnectionParams.setSoTimeout(params, soTimeout); HttpConnectionParams.setStaleCheckingEnabled(params, staleCheckingEnabled); HttpConnectionParams.setTcpNoDelay(params, tcpNoDelay); // Create the HttpClient and configure the compression interceptors if required... final DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, params); if (useCompression) { httpClient.addRequestInterceptor(new RequestAcceptEncoding()); httpClient.addResponseInterceptor(new DeflateContentEncoding()); } return httpClient; }
From source file:de.drv.dsrv.spoc.web.service.impl.FachverfahrenRequestServiceImpl.java
/** * Konstruktor.// ww w.jav a 2s . c o m * * @param maxConnections * die maximale Anzahl von gleichzeitigen HTTP-Verbindungen, die * vom Service insgesamt zu Fachverfahren aufgebaut werden; wenn * die Grenze erreicht wird, werden weitere Verbindungen * geblockt, bis eine Connection frei wird * @param maxConnectionsPerRoute * die maximale Anzahl von gleichzeitigen HTTP-Verbindungen, die * vom Service zu einer bestimmten Route (entspricht einem * Server) aufgebaut werden; wenn die Grenze erreicht wird, * werden weitere Verbindungen geblockt, bis eine Connection frei * wird * @param soapFaultString * Text des SOAP-Fehlers * @param responseHandler * Handler zur Verarbeitung der Antworten des Fachverfahrens * @param extraJaxbMarshaller * JAXB-Marshaller * @param spocNutzdatenManager * Manager zum ZUgriff auf die Nutzerdaten * * @throws IllegalArgumentException * wenn <code>maxConnections</code> oder * <code>maxConnectionsPerRoute</code> kleiner als 0 sind */ public FachverfahrenRequestServiceImpl(final int maxConnections, final int maxConnectionsPerRoute, final String soapFaultString, final SpocResponseHandler responseHandler, final ExtraJaxbMarshaller extraJaxbMarshaller, final SpocNutzdatenManager spocNutzdatenManager) { this.soapFaultString = soapFaultString; final PoolingClientConnectionManager conman = new PoolingClientConnectionManager(); conman.setMaxTotal(maxConnections); conman.setDefaultMaxPerRoute(maxConnectionsPerRoute); this.httpClient = new DefaultHttpClient(conman); this.httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8.name()); this.responseHandler = responseHandler; this.extraJaxbMarshaller = extraJaxbMarshaller; this.spocNutzdatenManager = spocNutzdatenManager; }
From source file:it.polimi.deib.csparql_rest_api.RSP_services_csparql_API.java
public RSP_services_csparql_API(String serverAddress) { super();//from w w w. jav a2 s . com this.serverAddress = serverAddress; cm = new PoolingClientConnectionManager(); client = new DefaultHttpClient(cm); gson = new Gson(); }
From source file:com.ibm.cnxdevs.cloud.apimanagement.sample.APIThrottlingSample.java
private HttpClient prepareHttpClient(String username, String password) { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); httpClient = new DefaultHttpClient(cm); SSLUtil.wrapHttpClient((DefaultHttpClient) httpClient); return httpClient; }
From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql.java
/** * Returns an RDFService for a remote repository * @param String - URI of the read SPARQL endpoint for the knowledge base * @param String - URI of the update SPARQL endpoint for the knowledge base * @param String - URI of the default write graph within the knowledge base. * this is the graph that will be written to when a graph * is not explicitly specified. * /*from ww w . ja v a 2s . c o m*/ * The default read graph is the union of all graphs in the * knowledge base */ public RDFServiceSparql(String readEndpointURI, String updateEndpointURI, String defaultWriteGraphURI) { this.readEndpointURI = readEndpointURI; this.updateEndpointURI = updateEndpointURI; PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(50); this.httpClient = new DefaultHttpClient(cm); testConnection(); }
From source file:org.jboss.as.test.integration.jaxrs.validator.BeanValidationIntegrationTestCase.java
@Test public void testInvalidResponse() throws Exception { DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager()); HttpGet get = new HttpGet(url + "myjaxrs/validate/11"); HttpResponse result = client.execute(get); result = client.execute(get);//from www. ja v a2s.co m Assert.assertEquals("Return value constraint violated", 500, result.getStatusLine().getStatusCode()); }
From source file:org.bonitasoft.engine.api.HTTPServerAPI.java
public HTTPServerAPI(final Map<String, String> parameters) { // initialize httpclient in the constructor to avoid incompatibility when running tests: // java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLS10Context not a SSLContext if (httpclient == null) { httpclient = new DefaultHttpClient(new PoolingClientConnectionManager()); }//from ww w. j a va 2s . c om serverUrl = parameters.get(SERVER_URL); applicationName = parameters.get(APPLICATION_NAME); basicAuthenticationActive = "true".equalsIgnoreCase(parameters.get(BASIC_AUTHENTICATION_ACTIVE)); basicAuthenticationUserName = parameters.get(BASIC_AUTHENTICATION_USERNAME); basicAuthenticationPassword = parameters.get(BASIC_AUTHENTICATION_PASSWORD); }
From source file:net.opentsdb.search.ElasticSearch.java
/** * Initializes the search plugin, setting up the HTTP client pool and config * options./*from ww w.j a va2 s .c o m*/ * @param tsdb The TSDB to which we belong * @return null if successful, otherwise it throws an exception * @throws IllegalArgumentException if a config value is invalid * @throws NumberFormatException if a config value is invalid */ @Override public void initialize(final TSDB tsdb) { config = new ESPluginConfig(tsdb.getConfig()); setConfiguration(); // setup a connection pool for reuse PoolingClientConnectionManager http_pool = new PoolingClientConnectionManager(); http_pool.setDefaultMaxPerRoute(config.getInt("tsd.search.elasticsearch.pool.max_per_route")); http_pool.setMaxTotal(config.getInt("tsd.search.elasticsearch.pool.max_total")); httpClient = new FailoverHttpClient(http_pool); // start worker threads indexers = new SearchIndexer[index_threads]; for (int i = 0; i < index_threads; i++) { indexers[i] = new SearchIndexer(); indexers[i].start(); } }
From source file:at.orz.arangodb.http.HttpManager.java
public void init() { // ConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); cm.setMaxTotal(configure.getMaxTotalConnection()); // Params//from w ww. j ava2 s. co m HttpParams params = new BasicHttpParams(); if (configure.getConnectionTimeout() >= 0) { HttpConnectionParams.setConnectionTimeout(params, configure.getConnectionTimeout()); } if (configure.getTimeout() >= 0) { HttpConnectionParams.setSoTimeout(params, configure.getTimeout()); } // Client client = new DefaultHttpClient(cm, params); // TODO KeepAlive Strategy // Proxy if (configure.getProxyHost() != null && configure.getProxyPort() != 0) { HttpHost proxy = new HttpHost(configure.getProxyHost(), configure.getProxyPort(), "http"); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } // Basic Auth //if (configure.getUser() != null && configure.getPassword() != null) { //AuthScope scope = AuthScope.ANY; // TODO //this.credentials = new UsernamePasswordCredentials(configure.getUser(), configure.getPassword()); //client.getCredentialsProvider().setCredentials(scope, credentials); //} // Retry Handler client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(configure.getRetryCount(), false)); }