use of org.apache.http.StatusLine in project cdap-ingest by caskdata.
the class RestClientTest method testOkResponseCodeAnalysis.
@Test
public void testOkResponseCodeAnalysis() {
StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK");
when(response.getStatusLine()).thenReturn(statusLine);
RestClient.responseCodeAnalysis(response);
verify(response).getStatusLine();
}
use of org.apache.http.StatusLine in project indy by Commonjava.
the class ReplicationController method getEndpoints.
private List<EndpointView> getEndpoints(final ReplicationDTO dto) throws IndyWorkflowException {
final String apiUrl = dto.getApiUrl();
String url = null;
try {
url = buildUrl(apiUrl, "/stats/all-endpoints");
} catch (final MalformedURLException e) {
throw new IndyWorkflowException("Failed to construct endpoint-retrieval URL from api-base: {}. Reason: {}", e, apiUrl, e.getMessage());
}
final HttpGet req = newGet(url, dto);
CloseableHttpClient client = null;
try {
String siteId = new URL(url).getHost();
client = http.createClient(siteId);
CloseableHttpResponse response = client.execute(req, http.createContext(siteId));
final StatusLine statusLine = response.getStatusLine();
final int status = statusLine.getStatusCode();
if (status == HttpStatus.SC_OK) {
final String json = HttpResources.entityToString(response);
final EndpointViewListing listing = serializer.readValue(json, EndpointViewListing.class);
return listing.getItems();
}
throw new IndyWorkflowException(status, "Endpoint request failed: {}", statusLine);
} catch (final IOException | IndyHttpException e) {
throw new IndyWorkflowException("Failed to retrieve endpoints from: {}. Reason: {}", e, url, e.getMessage());
} finally {
IOUtils.closeQuietly(client);
}
}
use of org.apache.http.StatusLine in project indy by Commonjava.
the class IndyClientHttp method putWithStream.
public void putWithStream(final String path, final InputStream stream, final int... responseCodes) throws IndyClientException {
connect();
final HttpPut put = newRawPut(buildUrl(baseUrl, path));
final CloseableHttpClient client = newClient();
CloseableHttpResponse response = null;
try {
put.setEntity(new InputStreamEntity(stream));
response = client.execute(put, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
throw new ClientProtocolException(new IndyClientException(sl.getStatusCode(), "Error in response from: %s.\n%s", path, new IndyResponseErrorDetails(response)));
}
} catch (final ClientProtocolException e) {
final Throwable cause = e.getCause();
if (cause != null && (cause instanceof IndyClientException)) {
throw (IndyClientException) cause;
}
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
cleanupResources(put, response, client);
}
}
use of org.apache.http.StatusLine in project indy by Commonjava.
the class IndyClientHttp method deleteWithChangelog.
public void deleteWithChangelog(final String path, final String changelog, final int... responseCodes) throws IndyClientException {
connect();
HttpDelete delete = null;
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
delete = newDelete(buildUrl(baseUrl, path));
delete.setHeader(ArtifactStore.METADATA_CHANGELOG, changelog);
response = client.execute(delete, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
}
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
cleanupResources(delete, response, client);
}
}
use of org.apache.http.StatusLine in project indy by Commonjava.
the class IndyClientHttp method delete.
public void delete(final String path, final int... responseCodes) throws IndyClientException {
connect();
HttpDelete delete = null;
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
delete = newDelete(buildUrl(baseUrl, path));
response = client.execute(delete, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
}
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
cleanupResources(delete, response, client);
}
}
Aggregations