List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:com.funambol.json.dao.JsonDAOImpl.java
/** * //from w ww. ja va 2 s. co m * @param resourceType */ public JsonDAOImpl(String resourceType) throws JsonConfigException { if (resourceType == null || resourceType.trim().equals("")) { throw new RuntimeException("The resourceType must be not null!"); } try { //Get connection parameters... this.jsonServerUrl = JsonConnectorConfig.getConfigInstance().getJsonServerUrl(); } catch (JsonConfigException e) { throw new JsonConfigException("Error looking up the Configuration File", e); } this.resourceType = resourceType; HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); this.httpClient = new HttpClient(httpConnectionManager); }
From source file:com.polarion.alm.ws.client.internal.connection.CommonsHTTPSender.java
protected void initialize() { MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager(); this.clientProperties = CommonsHTTPClientPropertiesFactory.create(); cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost()); cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections()); // If defined, set the default timeouts // Can be overridden by the MessageContext if (this.clientProperties.getDefaultConnectionTimeout() > 0) { cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout()); }/* www. j av a2 s . co m*/ if (this.clientProperties.getDefaultSoTimeout() > 0) { cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout()); } cm.getParams().setStaleCheckingEnabled(false); this.connectionManager = cm; }
From source file:com.cloud.cluster.ClusterServiceServletImpl.java
private HttpClient getHttpClient() { if (s_client == null) { MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); mgr.getParams().setDefaultMaxConnectionsPerHost(4); // TODO make it configurable mgr.getParams().setMaxTotalConnections(1000); s_client = new HttpClient(mgr); HttpClientParams clientParams = new HttpClientParams(); clientParams.setSoTimeout(_requestTimeoutSeconds * 1000); s_client.setParams(clientParams); }// w w w. j a va 2 s. c o m return s_client; }
From source file:colt.nicity.performance.agent.LatentHttpPump.java
private HttpConnectionManager createConnectionManager(int maxConnections) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); if (maxConnections > 0) { connectionManager.getParams().setMaxTotalConnections(maxConnections); }/*from w w w. j a v a2s. co m*/ return connectionManager; }
From source file:com.thoughtworks.go.agent.service.SslInfrastructureServiceTest.java
private HttpClient httpClientStub() { final HttpClient client = context.mock(HttpClient.class); context.checking(new Expectations() { {//from w w w . jav a 2 s. c o m allowing(client).setHttpConnectionManager(with(any(MultiThreadedHttpConnectionManager.class))); allowing(client).getHttpConnectionManager(); will(returnValue(new MultiThreadedHttpConnectionManager())); } }); return client; }
From source file:fedora.client.FedoraClient.java
public FedoraClient(String baseURL, String user, String pass) throws MalformedURLException { m_baseURL = baseURL;//from w w w . j ava 2 s. co m m_user = user; m_pass = pass; if (!baseURL.endsWith("/")) { m_baseURL += "/"; } URL url = new URL(m_baseURL); m_authScope = new AuthScope(url.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM); m_creds = new UsernamePasswordCredentials(user, pass); m_cManager = new MultiThreadedHttpConnectionManager(); }
From source file:dept_integration.Dept_Integchalan.java
public static String doSend(String STATUS, String TRANS_DATE, String TRANSID, String BANK_REFNO, String BANK_NAME, String CIN) throws Exception { String SCODE = "ihSkaRaA"; String url = "http://wsdl.jhpolice.gov.in/smsresponse.php"; String result = null;// w ww . j ava2 s . c om HttpClient client = null; PostMethod method = null; client = new HttpClient(new MultiThreadedHttpConnectionManager()); method = new PostMethod(url); // method.addRequestHeader("Content-Type","application/xml"); method.addParameter("STATUS", STATUS); // method.addParameter("signature",URLEncoder.encode(b,"UTF-8")); method.addParameter("TRANS_DATE", TRANS_DATE); method.addParameter("TRANSID", TRANSID); method.addParameter("BANK_REFNO", BANK_REFNO); method.addParameter("BANK_NAME", BANK_NAME); method.addParameter("CIN", CIN); method.addParameter("SCODE", SCODE); try { int statusCode = client.executeMethod(method); // System.out.println("lll"+method.getStatusLine().toString()); if (statusCode == -1) { result = "N"; System.err.println("HttpError: " + method.getStatusLine()); } else { result = method.getResponseBodyAsString(); System.out.println(result); //result= result.indexOf(""+mobile_no)==-1 ? "N" : "Y"; } } catch (Exception e) { e.printStackTrace(); System.err.println("Fatal protocol violation: " + e.getMessage()); throw e; } finally { method.abort(); method.releaseConnection(); } return result; }
From source file:it.geosolutions.httpproxy.HTTPProxy.java
/** * Initialize the <code>ProxyServlet</code> * //from w ww . ja v a2s . c o m * @param servletConfig The Servlet configuration passed in by the servlet conatiner */ public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ServletContext context = getServletContext(); String proxyPropPath = context.getInitParameter("proxyPropPath"); proxyConfig = new ProxyConfig(getServletContext(), proxyPropPath); connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(proxyConfig.getSoTimeout()); params.setConnectionTimeout(proxyConfig.getConnectionTimeout()); params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections()); params.setDefaultMaxConnectionsPerHost(proxyConfig.getDefaultMaxConnectionsPerHost()); //setSystemProxy(params); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); // // Check for system proxy usage // try { String proxyHost = System.getProperty("http.proxyHost"); int proxyPort = 80; if (proxyHost != null && !proxyHost.isEmpty()) { try { proxyPort = (System.getProperty("http.proxyPort") != null ? Integer.parseInt(System.getProperty("http.proxyPort")) : proxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } catch (Exception ex) { LOGGER.warning("No proxy port found"); } } } catch (Exception ex) { LOGGER.warning("Exception while setting the system proxy: " + ex.getLocalizedMessage()); } // ////////////////////////////////////////// // Setup the callbacks (in the future this // will be a pluggable lookup). // ////////////////////////////////////////// callbacks = new ArrayList<ProxyCallback>(); callbacks.add(new MimeTypeChecker(proxyConfig)); callbacks.add(new HostNameChecker(proxyConfig)); callbacks.add(new RequestTypeChecker(proxyConfig)); callbacks.add(new MethodsChecker(proxyConfig)); callbacks.add(new HostChecker(proxyConfig)); }
From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java
protected void initialize() { httpChunkStream = !IReportManager.getPreferences().getBoolean("jasperserver.preventChunkedRequests", true); IReportManager.getPreferences().addPreferenceChangeListener(new PreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent pce) { CommonsHTTPSender.this.httpChunkStream = !IReportManager.getPreferences() .getBoolean("jasperserver.preventChunkedRequests", true); }/* w w w . j av a 2s . c om*/ }); MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager(); this.clientProperties = CommonsHTTPClientPropertiesFactory.create(); cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost()); cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections()); // If defined, set the default timeouts // Can be overridden by the MessageContext if (this.clientProperties.getDefaultConnectionTimeout() > 0) { cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout()); } if (this.clientProperties.getDefaultSoTimeout() > 0) { cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout()); } this.connectionManager = cm; }
From source file:edu.ku.brc.helpers.HTTPGetter.java
/** * Performs a "generic" HTTP request and fill member variable with results * use "getDigirResultsetStr" to get the results as a String * * @param url URL to be executed//from ww w. ja va2 s . c o m * @param fileCache the file to place the results * @return returns an error code */ public byte[] doHTTPRequest(final String url, final File fileCache) { byte[] bytes = null; Exception excp = null; status = ErrorCode.NoError; // Create an HttpClient with the MultiThreadedHttpConnectionManager. // This connection manager must be used if more than one thread will // be using the HttpClient. httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); GetMethod method = null; try { method = new GetMethod(url); //log.debug("getting " + method.getURI()); //$NON-NLS-1$ httpClient.executeMethod(method); // get the response body as an array of bytes long bytesRead = 0; if (fileCache == null) { bytes = method.getResponseBody(); bytesRead = bytes.length; } else { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fileCache)); bytes = new byte[4096]; InputStream ins = method.getResponseBodyAsStream(); BufferedInputStream bis = new BufferedInputStream(ins); while (bis.available() > 0) { int numBytes = bis.read(bytes); if (numBytes > 0) { bos.write(bytes, 0, numBytes); bytesRead += numBytes; } } bos.flush(); bos.close(); bytes = null; } log.debug(bytesRead + " bytes read"); //$NON-NLS-1$ } catch (ConnectException ce) { excp = ce; log.error(String.format("Could not make HTTP connection. (%s)", ce.toString())); //$NON-NLS-1$ status = ErrorCode.HttpError; } catch (HttpException he) { excp = he; log.error(String.format("Http problem making request. (%s)", he.toString())); //$NON-NLS-1$ status = ErrorCode.HttpError; } catch (IOException ioe) { excp = ioe; log.error(String.format("IO problem making request. (%s)", ioe.toString())); //$NON-NLS-1$ status = ErrorCode.IOError; } catch (java.lang.IllegalArgumentException ioe) { excp = ioe; log.error(String.format("IO problem making request. (%s)", ioe.toString())); //$NON-NLS-1$ status = ErrorCode.IOError; } catch (Exception e) { excp = e; log.error("Error: " + e); //$NON-NLS-1$ status = ErrorCode.Error; } finally { // always release the connection after we're done if (isThrowingErrors && status != ErrorCode.NoError) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HTTPGetter.class, excp); } if (method != null) method.releaseConnection(); //log.debug("Connection released"); //$NON-NLS-1$ } if (listener != null) { if (status == ErrorCode.NoError) { listener.completed(this); } else { listener.completedWithError(this, status); } } return bytes; }