Search in sources :

Example 76 with CloseableHttpResponse

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);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RequestConfig(org.apache.http.client.config.RequestConfig) SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.jdom.Element) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.jdom.Document) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode)

Example 77 with CloseableHttpResponse

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 78 with CloseableHttpResponse

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 79 with CloseableHttpResponse

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 80 with CloseableHttpResponse

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"));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)536 HttpGet (org.apache.http.client.methods.HttpGet)242 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)171 StringEntity (org.apache.http.entity.StringEntity)127 JsonNode (com.fasterxml.jackson.databind.JsonNode)125 Test (org.junit.Test)125 HttpPost (org.apache.http.client.methods.HttpPost)107 IOException (java.io.IOException)105 HttpEntity (org.apache.http.HttpEntity)103 Deployment (org.activiti.engine.test.Deployment)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)57 InputStream (java.io.InputStream)53 HttpPut (org.apache.http.client.methods.HttpPut)50 Task (org.activiti.engine.task.Task)41 URI (java.net.URI)36 StatusLine (org.apache.http.StatusLine)34 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)34 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)31 BufferedReader (java.io.BufferedReader)30