/** * Returns the runtime information as a JSON string. * * @return the runtime information * @throws IOException * if reading the response body fails */ private String getRuntimeInfo(String hostUrl) throws IOException { HttpGet get = new HttpGet(UrlSupport.concat(hostUrl, "/info/components.json")); HttpResponse response = null; try { response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) return null; return EntityUtils.toString(response.getEntity()); } finally { httpClient.close(response); } }
/** * Closes any http connections kept open by this http response. */ protected void closeConnection(HttpResponse response) { if (response != null) client.close(response); }
response = client.execute(httpRequest); StatusLine status = response.getStatusLine(); if (Arrays.asList(expectedHttpStatus).contains(status.getStatusCode())) {
.<Either<String, Option<File>>> runner(get).run(handleDownloadResponse(src, dst));
/** * Wait for a certain status of a resource. * * @return either an exception or the status code of the last http response */ public static Either<Exception, Integer> waitForResource(final TrustedHttpClient http, final URI resourceUri, final int expectedStatus, final long timeout, final long pollingInterval) { long now = 0L; while (true) { final HttpHead head = new HttpHead(resourceUri); final Either<Exception, Integer> result = http.<Integer> run(head).apply(getStatusCode); for (final Integer status : result.right()) { if (eq(status, expectedStatus) || now >= timeout) { return right(status); } else if (now < timeout) { if (!sleep(pollingInterval)) { return left(new Exception("Interrupted")); } else { now = now + pollingInterval; } } } for (Exception e : result.left()) { return left(e); } } } }
@Override public Either<Exception, A> apply(Function<HttpResponse, A> responseHandler) { HttpResponse response = null; try { response = client.execute(httpUriRequest); return right(responseHandler.apply(response)); } catch (Exception e) { return left(e); } finally { if (response != null) { client.close(response); } } } };
if (!START_WORKFLOW.equals(job.getOperation())) setCurrentJob(job.toJob()); response = client.execute(post); responseStatusCode = response.getStatusLine().getStatusCode(); if (responseStatusCode == HttpStatus.SC_NO_CONTENT) { logger.warn("Unable to dispatch job {}", job.getId(), e); } finally { client.close(response); setCurrentJob(null);