use of org.apache.http.client.methods.CloseableHttpResponse in project libresonic by Libresonic.
the class PodcastService method doRefreshChannel.
@SuppressWarnings({ "unchecked" })
private void doRefreshChannel(PodcastChannel channel, boolean downloadEpisodes) {
InputStream in = null;
try (CloseableHttpClient client = HttpClients.createDefault()) {
channel.setStatus(PodcastStatus.DOWNLOADING);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(// 2 minutes
2 * 60 * 1000).setSocketTimeout(// 10 minutes
10 * 60 * 1000).build();
HttpGet method = new HttpGet(channel.getUrl());
method.setConfig(requestConfig);
try (CloseableHttpResponse response = client.execute(method)) {
in = response.getEntity().getContent();
Document document = new SAXBuilder().build(in);
Element channelElement = document.getRootElement().getChild("channel");
channel.setTitle(StringUtil.removeMarkup(channelElement.getChildTextTrim("title")));
channel.setDescription(StringUtil.removeMarkup(channelElement.getChildTextTrim("description")));
channel.setImageUrl(getChannelImageUrl(channelElement));
channel.setStatus(PodcastStatus.COMPLETED);
channel.setErrorMessage(null);
podcastDao.updateChannel(channel);
downloadImage(channel);
refreshEpisodes(channel, channelElement.getChildren("item"));
}
} catch (Exception x) {
LOG.warn("Failed to get/parse RSS file for Podcast channel " + channel.getUrl(), x);
channel.setStatus(PodcastStatus.ERROR);
channel.setErrorMessage(getErrorMessage(x));
podcastDao.updateChannel(channel);
} finally {
IOUtils.closeQuietly(in);
}
if (downloadEpisodes) {
for (final PodcastEpisode episode : getEpisodes(channel.getId())) {
if (episode.getStatus() == PodcastStatus.NEW && episode.getUrl() != null) {
downloadEpisode(episode);
}
}
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class SparkInteractiveSessions method getSessionFullLog.
/**
* @param connectUrl : eg http://localhost:8998/sessions
* @param sessionId : session Id
* @return response result
* @throws IOException
*/
public HttpResponse getSessionFullLog(String connectUrl, int sessionId) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(connectUrl + "/" + sessionId + "/log?from=0&size=" + Integer.MAX_VALUE);
httpGet.addHeader("Content-Type", "application/json");
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class SparkInteractiveSessions method getExecutionState.
/**
* get job execution status
*
* @param connectUrl eg http://localhost:8998/sessions
* @param sessionId session id
* @param statementId statement id
* @return response result
* @throws IOException
*/
public HttpResponse getExecutionState(String connectUrl, int sessionId, String statementId) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(connectUrl + "/" + sessionId + "/statements/" + statementId);
httpGet.addHeader("Content-Type", "application/json");
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class SparkInteractiveSessions method executeInSession.
/**
* @param connectUrl : eg http://localhost:8998/sessions
* @param sessionId : session id
* @param code scala or python code segment
* @return response result
* @throws IOException
*/
public HttpResponse executeInSession(String connectUrl, int sessionId, String code) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPost httpPost = new HttpPost(connectUrl + "/" + sessionId + "/statements");
httpPost.addHeader("Content-Type", "application/json");
String jsonString = "{\"code\" : \"" + code + "\"}";
StringEntity postingString = new StringEntity(jsonString);
httpPost.setEntity(postingString);
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class LivyTask method call.
@Override
public String call() throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(path);
httpGet.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();
HttpEntity httpEntity = response.getEntity();
return IOUtils.toString(httpEntity.getContent(), Charset.forName("utf-8"));
}
Aggregations