List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:fr.dutra.confluence2wordpress.xmlrpc.CommonsXmlRpcTransportFactory.java
public CommonsXmlRpcTransportFactory(URL url, String proxyHost, int proxyPort, int maxConnections) { this.url = url; HostConfiguration hostConf = new HostConfiguration(); hostConf.setHost(url.getHost(), url.getPort()); if (proxyHost != null && proxyPort != -1) { hostConf.setProxy(proxyHost, proxyPort); }/* www .j ava 2 s . c om*/ HttpConnectionManagerParams connParam = new HttpConnectionManagerParams(); connParam.setMaxConnectionsPerHost(hostConf, maxConnections); connParam.setMaxTotalConnections(maxConnections); MultiThreadedHttpConnectionManager conMgr = new MultiThreadedHttpConnectionManager(); conMgr.setParams(connParam); client = new HttpClient(conMgr); client.setHostConfiguration(hostConf); }
From source file:example.nz.org.take.compiler.userv.main.DUIConvictionInfoSource.java
@Override public ResourceIterator<hasBeenConvictedOfaDUI> fetch(Driver driver) { HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); client.getHttpConnectionManager().getParams().setConnectionTimeout(30000); GetMethod get = new GetMethod(URL); get.setFollowRedirects(true);/*from w ww. ja va2s . c om*/ get.setQueryString(new NameValuePair[] { new NameValuePair("id", driver.getId()) }); try { logger.info("DUI conviction lookup " + get.getURI()); client.executeMethod(get); String response = get.getResponseBodyAsString(); logger.info("DUI conviction lookup result: " + response); if (response != null && "true".equals(response.trim())) { hasBeenConvictedOfaDUI record = new hasBeenConvictedOfaDUI(); record.slot1 = driver; get.releaseConnection(); return new SingletonIterator<hasBeenConvictedOfaDUI>(record); } } catch (Exception e) { logger.error("Error connecting to web service " + URL); } return EmptyIterator.DEFAULT; }
From source file:com.datos.vfs.provider.http.HttpClientFactory.java
/** * Creates a new connection to the server. * @param builder The HttpFileSystemConfigBuilder. * @param scheme The protocol./* w w w .ja v a2s. co m*/ * @param hostname The hostname. * @param port The port number. * @param username The username. * @param password The password * @param fileSystemOptions The file system options. * @return a new HttpClient connection. * @throws FileSystemException if an error occurs. * @since 2.0 */ public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme, final String hostname, final int port, final String username, final String password, final FileSystemOptions fileSystemOptions) throws FileSystemException { HttpClient client; try { final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams connectionMgrParams = mgr.getParams(); client = new HttpClient(mgr); final HostConfiguration config = new HostConfiguration(); config.setHost(hostname, port, scheme); if (fileSystemOptions != null) { final String proxyHost = builder.getProxyHost(fileSystemOptions); final int proxyPort = builder.getProxyPort(fileSystemOptions); if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { config.setProxy(proxyHost, proxyPort); } final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions); if (proxyAuth != null) { final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }); if (authData != null) { final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials( UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null))); final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, proxyCreds); } if (builder.isPreemptiveAuth(fileSystemOptions)) { final HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setAuthenticationPreemptive(true); client.setParams(httpClientParams); } } final Cookie[] cookies = builder.getCookies(fileSystemOptions); if (cookies != null) { client.getState().addCookies(cookies); } } /** * ConnectionManager set methods must be called after the host & port and proxy host & port * are set in the HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams * tries to locate the host configuration. */ connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions)); connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions)); connectionMgrParams.setConnectionTimeout(builder.getConnectionTimeout(fileSystemOptions)); connectionMgrParams.setSoTimeout(builder.getSoTimeout(fileSystemOptions)); client.setHostConfiguration(config); if (username != null) { final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); final AuthScope scope = new AuthScope(hostname, AuthScope.ANY_PORT); client.getState().setCredentials(scope, creds); } } catch (final Exception exc) { throw new FileSystemException("vfs.provider.http/connect.error", exc, hostname); } return client; }
From source file:de.michaeltamm.W3cMarkupValidator.java
/** * Validates the given <code>html</code>. * * @param html a complete HTML document//from w w w . j a va 2 s . com */ public W3cMarkupValidationResult validate(String html) { if (_httpClient == null) { final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); _httpClient = new HttpClient(connectionManager); } final PostMethod postMethod = new PostMethod(_checkUrl); final Part[] data = { // The HTML to validate ... new StringPart("fragment", html, "UTF-8"), new StringPart("prefill", "0", "UTF-8"), new StringPart("doctype", "Inline", "UTF-8"), new StringPart("prefill_doctype", "html401", "UTF-8"), // List Messages Sequentially | Group Error Messages by Type ... new StringPart("group", "0", "UTF-8"), // Show source ... new StringPart("ss", "1", "UTF-8"), // Verbose Output ... new StringPart("verbose", "1", "UTF-8"), }; postMethod.setRequestEntity(new MultipartRequestEntity(data, postMethod.getParams())); try { final int status = _httpClient.executeMethod(postMethod); if (status != 200) { throw new RuntimeException(_checkUrl + " responded with " + status); } final String pathPrefix = _checkUrl.substring(0, _checkUrl.lastIndexOf('/') + 1); final String resultPage = getResponseBody(postMethod).replace("\"./", "\"" + pathPrefix) .replace("src=\"images/", "src=\"" + pathPrefix + "images/") .replace("<script type=\"text/javascript\" src=\"loadexplanation.js\">", "<script type=\"text/javascript\" src=\"" + pathPrefix + "loadexplanation.js\">"); return new W3cMarkupValidationResult(resultPage); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { postMethod.releaseConnection(); } }
From source file:com.twistbyte.affiliate.HttpUtility.java
public HttpUtility() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(50); connectionManager.getParams().setMaxTotalConnections(50); httpclient = new HttpClient(connectionManager); // connect timeout in 8 seconds httpclient.getParams().setParameter("http.connection.timeout", new Integer(8000)); httpclient.getParams().setParameter("http.socket.timeout", new Integer(300000)); Protocol protocol = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", protocol); }
From source file:com.smartitengineering.dao.solr.impl.SingletonRemoteServerFactory.java
@Override public SolrServer getSolrServer() { if (solrServer == null) { try {//ww w.j a v a2s. com HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); CommonsHttpSolrServer commonsHttpClientSolrServer = new CommonsHttpSolrServer( configuration.getUri(), client); commonsHttpClientSolrServer.setAllowCompression(configuration.isAllowCompression()); commonsHttpClientSolrServer.setConnectionTimeout(configuration.getConnectionTimeout()); commonsHttpClientSolrServer .setDefaultMaxConnectionsPerHost(configuration.getDefaultMaxConnectionsPerHost()); commonsHttpClientSolrServer.setFollowRedirects(configuration.isFollowRedirects()); commonsHttpClientSolrServer.setMaxRetries(configuration.getMaxRetries()); commonsHttpClientSolrServer.setMaxTotalConnections(configuration.getMaxTotalConnections()); commonsHttpClientSolrServer.setParser(configuration.getResponseParser()); commonsHttpClientSolrServer.setSoTimeout(configuration.getSocketTimeout()); commonsHttpClientSolrServer.setRequestWriter(new BinaryRequestWriter()); this.solrServer = commonsHttpClientSolrServer; } catch (Exception ex) { logger.error("Could not intialize solr server", ex); } } return solrServer; }
From source file:edu.unc.lib.dl.fedora.FedoraAccessControlService.java
public FedoraAccessControlService() { this.multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); this.httpClient = new HttpClient(this.multiThreadedHttpConnectionManager); this.mapper = new ObjectMapper(); }
From source file:com.cognifide.actions.msg.push.active.PushClientRunnable.java
public PushClientRunnable(Set<PushReceiver> receivers, String serverUrl, String username, String password) throws URISyntaxException { this.receivers = receivers; this.serverUrl = serverUrl; final HttpConnectionManager connManager = new MultiThreadedHttpConnectionManager(); client = new HttpClient(connManager); client.getParams().setAuthenticationPreemptive(true); final Credentials defaultcreds = new UsernamePasswordCredentials(username, password); final URI serverUri = new URI(serverUrl); final int port = serverUri.getPort() == -1 ? 80 : serverUri.getPort(); client.getState().setCredentials(new AuthScope(serverUri.getHost(), port, AuthScope.ANY_REALM), defaultcreds);//from w w w. ja v a 2 s . c o m }
From source file:de.ingrid.iplug.dsc.utils.BwstrLocUtil.java
private HttpClient createHttpClient() { HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyPort") != null) { client.getHostConfiguration().setProxy(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort"))); }/* ww w . j av a2 s . com*/ return client; }
From source file:com.adobe.translation.google.impl.TranslationServiceImpl.java
@Activate protected void activate() { cxMgr = new MultiThreadedHttpConnectionManager(); httpClient = new HttpClient(cxMgr); }