use of org.apache.http.impl.client.CloseableHttpClient in project goci by EBISPOT.
the class SolrSearchController method dispatchDownloadSearch.
private void dispatchDownloadSearch(String searchString, OutputStream outputStream, boolean efo, String facet, boolean ancestry) throws IOException {
getLog().trace(searchString);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(searchString);
if (System.getProperty("http.proxyHost") != null) {
HttpHost proxy;
if (System.getProperty("http.proxyPort") != null) {
proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
} else {
proxy = new HttpHost(System.getProperty("http.proxyHost"));
}
httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
}
String file = null;
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
String output;
while ((output = br.readLine()) != null) {
JsonProcessingService jsonProcessor = new JsonProcessingService(output, efo, facet, ancestry);
file = jsonProcessor.processJson();
}
EntityUtils.consume(entity);
}
if (file == null) {
//TO DO throw exception here and add error handler
file = "Some error occurred during your request. Please try again or contact the GWAS Catalog team for assistance";
}
PrintWriter outputWriter = new PrintWriter(outputStream);
outputWriter.write(file);
outputWriter.flush();
}
use of org.apache.http.impl.client.CloseableHttpClient in project opennms by OpenNMS.
the class MetadataUtils method fetchGeodata.
public static Map<String, String> fetchGeodata() {
final Map<String, String> ret = new HashMap<>();
final String url = "http://freegeoip.net/xml/";
final CloseableHttpClient httpclient = HttpClients.createDefault();
final HttpGet get = new HttpGet(url);
CloseableHttpResponse response = null;
try {
response = httpclient.execute(get);
final HttpEntity entity = response.getEntity();
final String xml = EntityUtils.toString(entity);
System.err.println("xml = " + xml);
final GeodataResponse geoResponse = JaxbUtils.unmarshal(GeodataResponse.class, xml);
ret.put("external-ip-address", InetAddressUtils.str(geoResponse.getIp()));
ret.put("country-code", geoResponse.getCountryCode());
ret.put("region-code", geoResponse.getRegionCode());
ret.put("city", geoResponse.getCity());
ret.put("zip-code", geoResponse.getZipCode());
ret.put("time-zone", geoResponse.getTimeZone());
ret.put("latitude", geoResponse.getLatitude() == null ? null : geoResponse.getLatitude().toString());
ret.put("longitude", geoResponse.getLongitude() == null ? null : geoResponse.getLongitude().toString());
EntityUtils.consumeQuietly(entity);
} catch (final Exception e) {
LOG.debug("Failed to get GeoIP data from " + url, e);
} finally {
IOUtils.closeQuietly(response);
}
return ret;
}
use of org.apache.http.impl.client.CloseableHttpClient in project api-snippets by TwilioDevEd.
the class Example method main.
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("lookups.twilio.com", 80), new UsernamePasswordCredentials("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "your_auth_token"));
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
try {
HttpGet httpget = new HttpGet("https://lookups.twilio.com/v1/PhoneNumbers/+16502530000/?AddOns=payfone_tcpa_compliance&AddOns.payfone_tcpa_compliance.RightPartyContactedDate=20160101");
System.out.println("Executing request " + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
use of org.apache.http.impl.client.CloseableHttpClient in project voltdb by VoltDB.
the class HTTPBenchmark method runBenchmark.
/**
* Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print Results.
*
* @throws Exception if anything unexpected happens.
*/
public void runBenchmark() throws Exception {
System.out.print(HORIZONTAL_RULE);
System.out.println(" Setup & Initialization");
System.out.println(HORIZONTAL_RULE);
// connect to one or more servers, loop until success
connect(config.servers);
// preload keys if requested
System.out.println();
if (config.preload) {
System.out.println("Preloading data store...");
for (int i = 0; i < config.poolsize; i++) {
client.callProcedure(new NullCallback(), "Put", String.format(processor.KeyFormat, i), processor.generateForStore().getStoreValue());
}
client.drain();
System.out.println("Preloading complete.\n");
}
System.out.print(HORIZONTAL_RULE);
System.out.println(" Starting Benchmark");
System.out.println(HORIZONTAL_RULE);
// setup the HTTP connection pool that will be used by the threads
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(config.threads * 2);
cm.setDefaultMaxPerRoute(config.threads);
CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
String[] servers = config.servers.split(",");
// create/start the requested number of threads
Thread[] kvThreads = new Thread[config.threads];
for (int i = 0; i < config.threads; ++i) {
HttpPost httppost = new HttpPost("http://" + servers[i % servers.length] + ":8080/api/1.0/");
kvThreads[i] = new Thread(new KVThread(httpclient, httppost));
kvThreads[i].start();
}
// Run the benchmark loop for the requested warmup time
System.out.println("Warming up...");
Thread.sleep(1000l * config.warmup);
// signal to threads to end the warmup phase
warmupComplete.set(true);
// Run the benchmark loop for the requested warmup time
System.out.println("\nRunning benchmark...");
Thread.sleep(1000l * config.duration);
// stop the threads
benchmarkComplete.set(true);
// cancel periodic stats printing
// timer.cancel();
// block until all outstanding txns return
client.drain();
// join on the threads
for (Thread t : kvThreads) {
t.join();
}
// print the summary results
printResults();
// close down the client connections
client.close();
}
use of org.apache.http.impl.client.CloseableHttpClient in project selenium-tests by Wikia.
the class GraphApi method deleteTestUser.
private HttpResponse deleteTestUser(String userId) throws IOException, URISyntaxException {
URL url = new URL(getURLdeleteUser(userId));
CloseableHttpClient httpClient = HttpClientBuilder.create().disableAutomaticRetries().build();
HttpDelete httpDelete = getHttpDelete(url);
return httpClient.execute(httpDelete);
}
Aggregations