use of org.apache.http.entity.AbstractHttpEntity in project gradle by gradle.
the class HttpBuildCacheService method store.
@Override
public void store(BuildCacheKey key, final BuildCacheEntryWriter output) throws BuildCacheException {
final URI uri = root.resolve(key.getHashCode());
HttpPut httpPut = new HttpPut(uri);
if (useExpectContinue) {
httpPut.setHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
httpPut.addHeader(HttpHeaders.CONTENT_TYPE, BUILD_CACHE_CONTENT_TYPE);
requestCustomizer.customize(httpPut);
httpPut.setEntity(new AbstractHttpEntity() {
@Override
public boolean isRepeatable() {
return true;
}
@Override
public long getContentLength() {
return output.getSize();
}
@Override
public InputStream getContent() {
throw new UnsupportedOperationException();
}
@Override
public void writeTo(OutputStream outstream) throws IOException {
output.writeTo(outstream);
}
@Override
public boolean isStreaming() {
return false;
}
});
try (HttpClientResponse response = httpClientHelper.performHttpRequest(httpPut)) {
StatusLine statusLine = response.getStatusLine();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Response for PUT {}: {}", safeUri(uri), statusLine);
}
int statusCode = statusLine.getStatusCode();
if (!isHttpSuccess(statusCode)) {
String defaultMessage = String.format("Storing entry at '%s' response status %d: %s", safeUri(uri), statusCode, statusLine.getReasonPhrase());
throwHttpStatusCodeException(statusCode, defaultMessage);
}
} catch (ClientProtocolException e) {
throw wrap(e.getCause());
} catch (IOException e) {
throw wrap(e);
}
}
Aggregations