use of org.apache.http.HttpEntity in project spark by perwendel.
the class SparkTestUtil method doMethod.
public UrlResponse doMethod(String requestMethod, String path, String body, boolean secureConnection, String acceptType, Map<String, String> reqHeaders) throws IOException {
HttpUriRequest httpRequest = getHttpRequest(requestMethod, path, body, secureConnection, acceptType, reqHeaders);
HttpResponse httpResponse = httpClient.execute(httpRequest);
UrlResponse urlResponse = new UrlResponse();
urlResponse.status = httpResponse.getStatusLine().getStatusCode();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
urlResponse.body = EntityUtils.toString(entity);
} else {
urlResponse.body = "";
}
Map<String, String> headers = new HashMap<>();
Header[] allHeaders = httpResponse.getAllHeaders();
for (Header header : allHeaders) {
headers.put(header.getName(), header.getValue());
}
urlResponse.headers = headers;
return urlResponse;
}
use of org.apache.http.HttpEntity 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.HttpEntity 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.HttpEntity in project tdi-studio-se by Talend.
the class paloconnection method logout.
// Logouts the current palo User
public void logout() throws paloexception {
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("sid", this.strToken));
try {
HttpEntity entity = sendToServer(qparams, "/server/logout");
CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
// CsvReader csv = new CsvReader(sendToServer(qparams, "/server/logout").getContent(),
// Charset.defaultCharset());
csv.setQuoteChar('"');
csv.readNext();
csv.close();
entity.consumeContent();
// paloHttpClient.getConnectionManager().shutdown();
} catch (Exception e) {
throw new paloexception(e.getMessage());
}
}
use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.
the class paloconnection method getRulefunctions.
public String getRulefunctions() throws paloexception {
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("sid", getPaloToken()));
try {
StringBuilder sb = new StringBuilder();
HttpEntity entity = sendToServer(qparams, "/rule/functions");
CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
csv.setQuoteChar('"');
while (csv.readNext()) {
sb.append(csv.get(0));
}
csv.close();
entity.consumeContent();
return sb.toString();
} catch (Exception e) {
throw new paloexception(e.getMessage());
}
}
Aggregations