List of usage examples for org.apache.commons.httpclient SimpleHttpConnectionManager SimpleHttpConnectionManager
SimpleHttpConnectionManager
From source file:net.sourceforge.jcctray.model.HTTPCruise.java
private static HttpClient getClient(Host host) { SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); HttpConnectionManagerParams connParams = new HttpConnectionManagerParams(); connParams.setConnectionTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT)); connParams.setSoTimeout(JCCTraySettings.getInstance().getInt(ISettingsConstants.HTTP_TIMEOUT)); connectionManager.setParams(connParams); HttpClient client = new HttpClient(connectionManager); client.getParams().setAuthenticationPreemptive(true); if (!StringUtils.isEmptyOrNull(host.getHostName()) && !StringUtils.isEmptyOrNull(host.getPassword())) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(host.getUsername(), host.getPassword());//from ww w . j av a 2 s . com client.getState().setCredentials(new AuthScope(null, -1, null, null), credentials); } return client; }
From source file:com.tasktop.c2c.server.common.service.tests.http.MultiUserClientHttpRequestFactoryTest.java
@Before public void before() { requestFactory = new MultiUserClientHttpRequestFactory(); requestFactory.setConnectionManager(new SimpleHttpConnectionManager()); }
From source file:de.ingrid.iplug.opensearch.communication.OSCommunication.java
/** * Send a request with all parameters within the "url"-String. * /* w w w. j a v a 2 s . c om*/ * @param url is the URL to request including the parameters * @return the response of the request */ public InputStream sendRequest(String url) { try { HttpClientParams httpClientParams = new HttpClientParams(); HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager(); httpClientParams.setSoTimeout(30 * 1000); httpConnectionManager.getParams().setConnectionTimeout(30 * 1000); httpConnectionManager.getParams().setSoTimeout(30 * 1000); HttpClient client = new HttpClient(httpClientParams, httpConnectionManager); method = new GetMethod(url); // set a request header // this can change in the result of the response since it might be // interpreted differently //method.addRequestHeader("Accept-Language", language); //"de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"); int status = client.executeMethod(method); if (status == 200) { log.debug("Successfully received: " + url); return method.getResponseBodyAsStream(); } else { log.error("Response code for '" + url + "' was: " + status); return null; } } catch (HttpException e) { log.error("An HTTP-Exception occured when calling: " + url); e.printStackTrace(); } catch (IOException e) { log.error("An IO-Exception occured when calling: " + url); e.printStackTrace(); } return null; }
From source file:com.orange.mmp.net.http.HttpConnectionManager.java
public Connection getConnection() throws MMPNetException { SimpleHttpConnectionManager shcm = new SimpleHttpConnectionManager(); HttpClientParams defaultHttpParams = new HttpClientParams(); defaultHttpParams.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); defaultHttpParams.setParameter(HttpConnectionParams.TCP_NODELAY, true); defaultHttpParams.setParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); defaultHttpParams.setParameter(HttpConnectionParams.SO_LINGER, 0); defaultHttpParams.setParameter(HttpClientParams.MAX_REDIRECTS, 3); defaultHttpParams.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false); HttpClient httpClient2 = new HttpClient(defaultHttpParams, shcm); if (HttpConnectionManager.proxyHost != null) { defaultHttpParams.setParameter("http.route.default-proxy", new HttpHost(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort)); // TODO Host configuration ! if (HttpConnectionManager.proxyHost != null/* && this.useProxy*/) { HostConfiguration config = new HostConfiguration(); config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort); httpClient2.setHostConfiguration(config); } else {// w w w . j a va 2 s.c o m HostConfiguration config = new HostConfiguration(); config.setProxyHost(null); httpClient2.setHostConfiguration(config); } } return new HttpConnection(httpClient2); }
From source file:de.bitzeche.video.transcoding.zencoder.test.ZencoderClientTest.java
public IZencoderClient createClient(ZencoderAPIVersion apiVersion) { ZencoderClient zencoderClient = new ZencoderClient(API_KEY, apiVersion); HttpClient client = new HttpClient(new SimpleHttpConnectionManager()); ApacheHttpClientHandler apacheHttpClientHandler = new ApacheHttpClientHandler(client, new DefaultApacheHttpClientConfig()); ApacheHttpClient httpClient = new ApacheHttpClient(apacheHttpClientHandler); zencoderClient.setHttpClient(httpClient); return zencoderClient; }
From source file:edu.usc.corral.api.Client.java
public Client(String host, int port) { Protocol httpg = new Protocol("httpg", new SocketFactory(), 9443); HostConfiguration hc = new HostConfiguration(); hc.setHost(host, port, httpg);//from www . ja v a 2s . co m connmgr = new SimpleHttpConnectionManager(); httpclient = new HttpClient(); httpclient.setHostConfiguration(hc); httpclient.setHttpConnectionManager(connmgr); }
From source file:analysePortalU.AnalysePortalUData.java
public void analyse() throws HttpException, IOException, ParserConfigurationException, SAXException, TransformerException { Map<String, Map<String, String>> resultMap = new HashMap<String, Map<String, String>>(); Scanner in = new Scanner(getClass().getClassLoader().getResourceAsStream("keywords.txt")); while (in.hasNextLine()) { String keyword = URLEncoder.encode(in.nextLine().trim(), "UTF-8"); int currentPage = 1; boolean moreResults = true; while (moreResults) { String url = "http://www.portalu.de/opensearch/query?q=" + keyword.replace(' ', '+') + "+datatype:metadata+ranking:score&h=" + PAGE_SIZE + "&detail=1&ingrid=1&p=" + currentPage; HttpClientParams httpClientParams = new HttpClientParams(); HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager(); httpClientParams.setSoTimeout(60 * 1000); httpConnectionManager.getParams().setConnectionTimeout(60 * 1000); httpConnectionManager.getParams().setSoTimeout(60 * 1000); HttpClient client = new HttpClient(httpClientParams, httpConnectionManager); HttpMethod method = new GetMethod(url); // set a request header // this can change in the result of the response since it might // be // interpreted differently // method.addRequestHeader("Accept-Language", language); // //"de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"); System.out.println("Query: " + url); int status = client.executeMethod(method); if (status == 200) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(method.getResponseBodyAsStream()); XPathUtils xpath = new XPathUtils(new ConfigurableNamespaceContext()); NodeList results = xpath.getNodeList(doc, "/rss/channel/item"); int numberOfResults = results.getLength(); for (int i = 0; i < results.getLength(); i++) { Node node = results.item(i); String fileIdentifier = xpath.getString(node, ".//*/fileIdentifier/CharacterString"); if (!resultMap.containsKey(fileIdentifier)) { resultMap.put(fileIdentifier, new HashMap<String, String>()); }//from w w w. j a v a 2 s . c o m Map<String, String> currentMap = resultMap.get(fileIdentifier); currentMap.put("uuid", fileIdentifier); currentMap.put("partner", xpath.getString(node, "partner")); currentMap.put("provider", xpath.getString(node, "provider")); currentMap.put("udk-class", xpath.getString(node, "udk-class")); currentMap.put("source", xpath.getString(node, "source")); currentMap.put("url", new URL(xpath.getString(node, "link")).toString()); currentMap.put("title", xpath.getString(node, ".//*/title/CharacterString")); currentMap.put("description", xpath.getString(node, ".//*/abstract/CharacterString")); Node addressNode = xpath.getNode(node, ".//*/contact/idfResponsibleParty"); String addressString = ""; String tmp = xpath.getString(addressNode, "indiviualName/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "organisationName/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/deliveryPoint/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/postalCode/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + " "; tmp = xpath.getString(addressNode, "ontactInfo/CI_Contact/address/CI_Address/city/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/country/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/address/CI_Address/electronicMailAddress/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Email: " + tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/phone/CI_Telephone/voice/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Tel: " + tmp + "\n"; tmp = xpath.getString(addressNode, "contactInfo/CI_Contact/phone/CI_Telephone/facsimile/CharacterString"); if (tmp != null && tmp.length() > 0) addressString += "Fax: " + tmp + "\n"; currentMap.put("pointOfContact", addressString); } if (numberOfResults > 0 && numberOfResults >= PAGE_SIZE) { currentPage++; } else { moreResults = false; } } else { moreResults = false; } } } StringWriter sw = new StringWriter(); ExcelCSVPrinter ecsvp = new ExcelCSVPrinter(sw); boolean fieldsWritten = false; for (String key : resultMap.keySet()) { Map<String, String> result = resultMap.get(key); if (!fieldsWritten) { for (String field : result.keySet()) { ecsvp.print(field); } ecsvp.println(""); fieldsWritten = true; } for (String value : result.values()) { ecsvp.print(value); } ecsvp.println(""); } PrintWriter out = new PrintWriter("result.csv"); out.write(sw.toString()); out.close(); in.close(); System.out.println("Done."); }
From source file:cn.leancloud.diamond.client.processor.ServerAddressProcessor.java
private void initHttpClient() { HostConfiguration hostConfiguration = new HostConfiguration(); SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); connectionManager.closeIdleConnections(5000L); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); connectionManager.setParams(params); configHttpClient = new HttpClient(connectionManager); configHttpClient.setHostConfiguration(hostConfiguration); }
From source file:com.mirth.connect.client.core.UpdateClient.java
public void sendUsageStatistics() throws ClientException { // Only send stats if they haven't been sent in the last 24 hours. long now = System.currentTimeMillis(); Long lastUpdate = client.getUpdateSettings().getLastStatsTime(); if (lastUpdate != null) { long last = lastUpdate; // 86400 seconds in a day if ((now - last) < (86400 * 1000)) { return; }/* w w w.j av a 2 s. c om*/ } List<UsageData> usageData = null; try { usageData = getUsageData(); } catch (Exception e) { throw new ClientException(e); } HttpClientParams httpClientParams = new HttpClientParams(); HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager(); httpClientParams.setSoTimeout(10 * 1000); httpConnectionManager.getParams().setConnectionTimeout(10 * 1000); httpConnectionManager.getParams().setSoTimeout(10 * 1000); HttpClient httpClient = new HttpClient(httpClientParams, httpConnectionManager); PostMethod post = new PostMethod(client.getUpdateSettings().getUpdateUrl() + URL_USAGE_STATISTICS); NameValuePair[] params = { new NameValuePair("serverId", client.getServerId()), new NameValuePair("version", client.getVersion()), new NameValuePair("data", serializer.toXML(usageData)) }; post.setRequestBody(params); try { int statusCode = httpClient.executeMethod(post); if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) { throw new Exception("Failed to connect to update server: " + post.getStatusLine()); } // Save the sent time if sending was successful. UpdateSettings settings = new UpdateSettings(); settings.setLastStatsTime(now); client.setUpdateSettings(settings); } catch (Exception e) { throw new ClientException(e); } finally { post.releaseConnection(); } }
From source file:com.mirth.connect.client.core.UpdateClient.java
public void registerUser(User user) throws ClientException { HttpClientParams httpClientParams = new HttpClientParams(); HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager(); httpClientParams.setSoTimeout(10 * 1000); httpConnectionManager.getParams().setConnectionTimeout(10 * 1000); httpConnectionManager.getParams().setSoTimeout(10 * 1000); HttpClient httpClient = new HttpClient(httpClientParams, httpConnectionManager); PostMethod post = new PostMethod(client.getUpdateSettings().getUpdateUrl() + URL_REGISTRATION); NameValuePair[] params = { new NameValuePair("serverId", client.getServerId()), new NameValuePair("version", client.getVersion()), new NameValuePair("user", serializer.toXML(user)) }; post.setRequestBody(params);/* www .j a v a 2 s .c o m*/ try { int statusCode = httpClient.executeMethod(post); if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) { throw new Exception("Failed to connect to update server: " + post.getStatusLine()); } } catch (Exception e) { throw new ClientException(e); } finally { post.releaseConnection(); } }