List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.geotools.data.ows.MultithreadedHttpClient.java
public MultithreadedHttpClient() { connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(30000);// w w w . ja va 2 s.c o m params.setConnectionTimeout(30000); params.setMaxTotalConnections(6); params.setDefaultMaxConnectionsPerHost(6); connectionManager.setParams(params); client = new HttpClient(connectionManager); applySystemProxySettings(); }
From source file:org.geowebcache.util.HttpClientBuilder.java
/** * uses the configuration of this builder to generate a HttpClient * /*w w w . j a v a2s. c o m*/ * @return the generated HttpClient */ public HttpClient buildClient() { HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(backendTimeoutMillis); params.setConnectionTimeout(backendTimeoutMillis); if (concurrency > 0) { params.setMaxTotalConnections(concurrency); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, concurrency); } connectionManager.setParams(params); HttpClient httpClient = new HttpClient(connectionManager); if (authscope != null && httpcredentials != null) { httpClient.getState().setCredentials(authscope, httpcredentials); httpClient.getParams().setAuthenticationPreemptive(true); } if (proxyUrl != null) { httpClient.getHostConfiguration().setProxy(proxyUrl.getHost(), proxyUrl.getPort()); if (proxycredentials != null) { httpClient.getState().setProxyCredentials(new AuthScope(proxyUrl.getHost(), proxyUrl.getPort()), proxycredentials); } } return httpClient; }
From source file:org.glite.slcs.caclient.impl.CMPClient.java
private HttpClient createHttpClient(String keystorePath, String keystorePassword, String truststorePath, URL caURL) throws SLCSException { Protocol protocol = null;/*from w w w .ja v a2 s . c om*/ int port = caURL.getPort(); if (caURL.getProtocol().equals("http")) { if (port == -1) { port = 80; } protocol = new Protocol("http", new DefaultProtocolSocketFactory(), port); } else if (caURL.getProtocol().equals("https")) { if (port == -1) { port = 443; } try { ExtendedProtocolSocketFactory psf = new ExtendedProtocolSocketFactory(keystorePath, keystorePassword, truststorePath); protocol = new Protocol("https", psf, port); } catch (Exception e) { throw new SLCSException("Error in generating the secure http client", e); } } else { throw new SLCSException("Protocol defined in CAClient.CAUrl is not supported! Use http or https."); } // create HTTP client MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); client.getHostConfiguration().setHost(caURL.getHost(), port, protocol); return client; }
From source file:org.hydracache.client.transport.HttpTransport.java
public HttpTransport() { // FIXME Make this more IoC and configurable. MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(10); connectionManagerParams.setMaxTotalConnections(100); connectionManager.setParams(connectionManagerParams); this.httpClient = new HttpClient(connectionManager); }
From source file:org.iavante.sling.gad.transcoder.impl.TranscoderServiceImpl.java
public int sendConversionTask3(String conversionType, String sourceLocation, String targetLocation, String notificationUrl, String externalStorageServer, String externalStorageUrl, String params, String ds_custom_props) { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); List authPrefs = new ArrayList(2); Credentials defaultcreds;/* w w w . ja v a2 s. c o m*/ authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials(transcodingServerUser, transcodingServerPassword); // Set client connection params MultiThreadedHttpConnectionManager connManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connParams = connManager.getParams(); connParams.setConnectionTimeout(800); HttpClient client = new HttpClient(connManager); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); if (log.isInfoEnabled()) log.info("Sending conversion task"); Node convTypeNode = null; try { convTypeNode = rootNode.getNode(baseRepoDir + "/" + COMPONENTS_FOLDER + "/" + TRANSCODER_FOLDER) .getNode(conversionType); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } String executable = null; try { executable = convTypeNode.getProperty("command").getValue().getString(); if (params == null) { params = convTypeNode.getProperty("params").getValue().getString(); } if (ds_custom_props == null) { ds_custom_props = ""; } } catch (ValueFormatException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (PathNotFoundException e) { e.printStackTrace(); } catch (RepositoryException e) { e.printStackTrace(); } PostMethod post = new PostMethod(sendConversionUrl); //post.getParams().setParameter("http.socket.timeout", new Integer(50)); post.setDoAuthentication(true); NameValuePair[] data = { new NameValuePair("source_location", sourceLocation), new NameValuePair("target_location", targetLocation), new NameValuePair("executable", executable), new NameValuePair("params", params), new NameValuePair("ds_custom_props", ds_custom_props), new NameValuePair("notification_url", notificationUrl), new NameValuePair("extern_storage_server", externalStorageServer), new NameValuePair("sling:resourceType", "gad/job"), new NameValuePair("extern_storage_url", externalStorageUrl) }; post.setRequestBody(data); post.setDoAuthentication(true); int status = 0; int intentos = 0; while ((status != 201) && (intentos < 2)) { try { client.executeMethod(post); status = post.getStatusCode(); log.info("Conversion sent. Status code: " + status); } catch (HttpException e1) { log.error("Excepcion: HttpException"); e1.printStackTrace(); post.releaseConnection(); return status; } catch (IOException e1) { log.error("Excepcion: IOexception"); e1.printStackTrace(); post.releaseConnection(); return status; } finally { intentos++; } } post.releaseConnection(); return status; }
From source file:org.intalio.tempo.workflow.tas.nuxeo.NuxeoStorageStrategy.java
/** * Everything we need to do to have an authenticated http client * /*w ww.j a v a2 s. c o m*/ * @throws URIException */ private void initHttpClient() throws URIException { httpclient = new HttpClient(); HostConfiguration hostConfig = new HostConfiguration(); org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(getNuxeoRestUrl(), false); hostConfig.setHost(uri); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); int maxHostConnections = 20; params.setMaxConnectionsPerHost(hostConfig, maxHostConnections); connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); httpclient.setHostConfiguration(hostConfig); Credentials creds = new UsernamePasswordCredentials(userName, password); AuthScope authScope = new AuthScope(hostConfig.getHost(), hostConfig.getPort()); httpclient.getState().setCredentials(authScope, creds); httpclient.getParams().setAuthenticationPreemptive(true); }
From source file:org.intalio.tempo.workflow.tas.sling.SlingStorageStrategy.java
public void init() throws HttpException, IOException { HostConfiguration hostConfig = new HostConfiguration(); // hostConfig.setHost("www.somehost.com"); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); int maxHostConnections = 20; params.setMaxConnectionsPerHost(hostConfig, maxHostConnections); connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); Credentials creds = new UsernamePasswordCredentials(userName, password); httpclient.getState().setCredentials(AuthScope.ANY, creds); httpclient.setHostConfiguration(hostConfig); MkColMethod col = new MkColMethod(getUploadFolder()); int ret = httpclient.executeMethod(col); log.debug(MessageFormatter.format("Created folder {0} in sling: {1}", getUploadFolder(), ret)); }
From source file:org.j2free.http.QueuedHttpCallService.java
/** * Enables this service.//ww w .ja v a 2 s . c om * * @param corePoolSize * @param maxPoolSize The max number of threads * @param threadIdle How long a thread can be idle before terminating it * @param connectTimeout How long to wait for a connection * @param socketTimeout How long to wait for an operation * @throws IllegalStateException if called when the service is already running */ public QueuedHttpCallService(int corePoolSize, int maxPoolSize, long threadIdle, int connectTimeout, int socketTimeout) { if (maxPoolSize < 0) maxPoolSize = Integer.MAX_VALUE; executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, threadIdle, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(100)); executor.allowCoreThreadTimeOut(true); // allow the threads to timeout if unused executor.prestartCoreThread(); // start up just one thread connectionManager = new MultiThreadedHttpConnectionManager(); // Configure the ConnectionManager HttpConnectionManagerParams cmParams = connectionManager.getParams(); cmParams.setConnectionTimeout(connectTimeout * 1000); cmParams.setSoTimeout(socketTimeout * 1000); cmParams.setMaxTotalConnections(maxPoolSize); httpClient = new HttpClient(connectionManager); }
From source file:org.jaggeryjs2.xhr.XMLHttpRequest.java
public XMLHttpRequest() { try {// w w w . j av a2 s. c om // To ignore the hostname verification in http client side when org.wso2.ignoreHostnameVerification is set // This system variable should not be set in product environment due to security reasons String ignoreHostnameVerification = System.getProperty("org.wso2.ignoreHostnameVerification"); if (ignoreHostnameVerification != null && "true".equalsIgnoreCase(ignoreHostnameVerification)) { Protocol protocolWithoutHostNameVerification = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), HTTPS_DEFAULT_PORT); Protocol.registerProtocol("https", protocolWithoutHostNameVerification); } httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); ProxyHost proxyConfig = getProxyConfig(); if (proxyConfig != null) { httpClient.getHostConfiguration().setProxyHost(proxyConfig); } } catch (IOException e) { log.error(e); } catch (GeneralSecurityException e) { log.error(e); } xhr = new XMLHttpRequest(httpClient); }
From source file:org.jahia.services.notification.HttpClientServiceTest.java
private void initClient() { // instantiate HttpClient HttpClientParams params = new HttpClientParams(); params.setAuthenticationPreemptive(true); params.setCookiePolicy("ignoreCookies"); HttpConnectionManagerParams cmParams = new HttpConnectionManagerParams(); cmParams.setConnectionTimeout(15000); cmParams.setSoTimeout(60000);/*from ww w. j a va 2 s. c o m*/ MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); httpConnectionManager.setParams(cmParams); httpClientService = new HttpClientService(); httpClientService.setHttpClient(new HttpClient(params, httpConnectionManager)); }