use of org.apache.http.impl.client.BasicResponseHandler in project coursera-android by aporter.
the class JSONResponseHandler method handleResponse.
@Override
public List<EarthQuakeRec> handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
List<EarthQuakeRec> result = new ArrayList<EarthQuakeRec>();
String JSONResponse = new BasicResponseHandler().handleResponse(response);
try {
JSONObject object = (JSONObject) new JSONTokener(JSONResponse).nextValue();
JSONArray earthquakes = object.getJSONArray("earthquakes");
for (int i = 0; i < earthquakes.length(); i++) {
JSONObject tmp = (JSONObject) earthquakes.get(i);
result.add(new EarthQuakeRec(tmp.getDouble("lat"), tmp.getDouble("lng"), tmp.getDouble("magnitude")));
}
} catch (JSONException e) {
e.printStackTrace();
}
return result;
}
use of org.apache.http.impl.client.BasicResponseHandler in project musiccabinet by hakko.
the class AbstractMusicBrainzClient method executeWSRequest.
protected String executeWSRequest(WebserviceInvocation invocation, String path, List<NameValuePair> params) throws ApplicationException {
String response = null;
HttpGet httpGet = new HttpGet(getURI(path, params));
httpGet.setHeader(USER_AGENT, CLIENT_INFO);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
long elapsedMs = -currentTimeMillis();
response = httpClient.execute(httpGet, responseHandler);
elapsedMs += currentTimeMillis();
sleep(Math.max(INTERVAL_MS - elapsedMs, 0));
} catch (HttpResponseException e) {
LOG.warn(format("MusicBrainz internal error: %d, %s", e.getStatusCode(), e.getMessage()));
throw new ApplicationException("MusicBrainz internal error!", e);
} catch (IOException e) {
throw new ApplicationException("MusicBrainz communication failed!", e);
} catch (InterruptedException e) {
LOG.warn("MusicBrainz sleep interrupted!", e);
}
webserviceHistoryService.logWebserviceInvocation(invocation);
return response;
}
use of org.apache.http.impl.client.BasicResponseHandler in project libresonic by Libresonic.
the class VersionService method readLatestVersion.
/**
* Resolves the latest available Libresonic version by screen-scraping a web page.
*
* @throws IOException If an I/O error occurs.
*/
private void readLatestVersion() throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build();
HttpGet method = new HttpGet(VERSION_URL + "?v=" + getLocalVersion());
method.setConfig(requestConfig);
String content;
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
content = client.execute(method, responseHandler);
}
Pattern finalPattern = Pattern.compile("LIBRESONIC_FULL_VERSION_BEGIN(.*)LIBRESONIC_FULL_VERSION_END");
Pattern betaPattern = Pattern.compile("LIBRESONIC_BETA_VERSION_BEGIN(.*)LIBRESONIC_BETA_VERSION_END");
try (BufferedReader reader = new BufferedReader(new StringReader(content))) {
String line = reader.readLine();
while (line != null) {
Matcher finalMatcher = finalPattern.matcher(line);
if (finalMatcher.find()) {
latestFinalVersion = new Version(finalMatcher.group(1));
LOG.info("Resolved latest Libresonic final version to: " + latestFinalVersion);
}
Matcher betaMatcher = betaPattern.matcher(line);
if (betaMatcher.find()) {
latestBetaVersion = new Version(betaMatcher.group(1));
LOG.info("Resolved latest Libresonic beta version to: " + latestBetaVersion);
}
line = reader.readLine();
}
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project libresonic by Libresonic.
the class LyricsService method executeGetRequest.
private String executeGetRequest(String url) throws IOException {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(15000).setSocketTimeout(15000).build();
HttpGet method = new HttpGet(url);
method.setConfig(requestConfig);
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
return client.execute(method, responseHandler);
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project libresonic by Libresonic.
the class AudioScrobblerService method executeRequest.
private String[] executeRequest(HttpUriRequest request) throws IOException {
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = client.execute(request, responseHandler);
return response.split("\\n");
}
}
Aggregations