use of org.commonjava.indy.client.core.metric.ClientMetrics in project indy by Commonjava.
the class IndyClientHttp method exists.
public boolean exists(final String path, Supplier<Map<String, String>> querySupplier, final int... responseCodes) throws IndyClientException {
HttpHead request = newJsonHead(buildUrl(baseUrl, querySupplier, path));
ClientMetrics metrics = metricManager.register(request);
connect();
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
addLoggingMDCToHeaders(request);
response = client.execute(request, newContext());
final StatusLine sl = response.getStatusLine();
if (validResponseCode(sl.getStatusCode(), responseCodes)) {
return true;
} else if (sl.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
return false;
}
metrics.registerErr(sl);
throw new IndyClientException(sl.getStatusCode(), "Error checking existence of: %s.\n%s", path, new IndyResponseErrorDetails(response));
} catch (final IOException e) {
metrics.registerErr(e);
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
metrics.registerEnd(response);
cleanupResources(request, response, client, metrics);
}
}
use of org.commonjava.indy.client.core.metric.ClientMetrics in project indy by Commonjava.
the class IndyClientHttp method putWithStream.
public void putWithStream(final String path, final InputStream stream, final int... responseCodes) throws IndyClientException {
final HttpPut put = newRawPut(buildUrl(baseUrl, path));
ClientMetrics metrics = metricManager.register(put);
connect();
addLoggingMDCToHeaders(put);
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)) {
metrics.registerErr(sl);
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();
metrics.registerErr(cause);
if (cause instanceof IndyClientException) {
throw (IndyClientException) cause;
}
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} catch (final IOException e) {
metrics.registerErr(e);
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
metrics.registerEnd(response);
cleanupResources(put, response, client, metrics);
}
}
use of org.commonjava.indy.client.core.metric.ClientMetrics in project indy by Commonjava.
the class IndyClientHttp method deleteWithChangelog.
public void deleteWithChangelog(final String path, final String changelog, final int... responseCodes) throws IndyClientException {
HttpDelete delete = newDelete(buildUrl(baseUrl, path));
ClientMetrics metrics = metricManager.register(delete);
connect();
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
addLoggingMDCToHeaders(delete);
delete.setHeader(ArtifactStore.METADATA_CHANGELOG, changelog);
response = client.execute(delete, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
metrics.registerErr(sl);
throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
}
} catch (final IOException e) {
metrics.registerErr(e);
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
metrics.registerEnd(response);
cleanupResources(delete, response, client, metrics);
}
}
use of org.commonjava.indy.client.core.metric.ClientMetrics in project indy by Commonjava.
the class IndyClientHttp method getRaw.
public HttpResources getRaw(final HttpGet req) throws IndyClientException {
ClientMetrics metrics = metricManager.register(req);
connect();
addLoggingMDCToHeaders(req);
CloseableHttpResponse response = null;
try {
final CloseableHttpClient client = newClient();
response = client.execute(req, newContext());
return new HttpResources(req, response, client, metrics);
} catch (final IOException e) {
metrics.registerErr(e);
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
metrics.registerEnd(response);
// DO NOT CLOSE!!!! We're handing off control of the response to the caller!
// closeQuietly( response );
}
}
use of org.commonjava.indy.client.core.metric.ClientMetrics in project indy by Commonjava.
the class IndyClientHttp method delete.
public void delete(final String path, final int... responseCodes) throws IndyClientException {
HttpDelete delete = newDelete(buildUrl(baseUrl, path));
ClientMetrics metrics = metricManager.register(delete);
connect();
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
addLoggingMDCToHeaders(delete);
response = client.execute(delete, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
metrics.registerErr(sl);
throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
}
} catch (final IOException e) {
metrics.registerErr(e);
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
metrics.registerEnd(response);
cleanupResources(delete, response, client, metrics);
}
}
Aggregations