Search in sources :

Example 1 with HttpClientResponse

use of org.gradle.internal.resource.transport.http.HttpClientResponse 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);
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) ClientProtocolException(org.apache.http.client.ClientProtocolException) StatusLine(org.apache.http.StatusLine) HttpClientResponse(org.gradle.internal.resource.transport.http.HttpClientResponse) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity)

Example 2 with HttpClientResponse

use of org.gradle.internal.resource.transport.http.HttpClientResponse in project gradle by gradle.

the class HttpBuildCacheService method load.

@Override
public boolean load(BuildCacheKey key, BuildCacheEntryReader reader) throws BuildCacheException {
    final URI uri = root.resolve("./" + key.getHashCode());
    HttpGet httpGet = new HttpGet(uri);
    httpGet.addHeader(HttpHeaders.ACCEPT, BUILD_CACHE_CONTENT_TYPE + ", */*");
    requestCustomizer.customize(httpGet);
    try (HttpClientResponse response = httpClientHelper.performHttpRequest(httpGet)) {
        StatusLine statusLine = response.getStatusLine();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Response for GET {}: {}", safeUri(uri), statusLine);
        }
        int statusCode = statusLine.getStatusCode();
        if (isHttpSuccess(statusCode)) {
            reader.readFrom(response.getContent());
            return true;
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            return false;
        } else {
            String defaultMessage = String.format("Loading entry from '%s' response status %d: %s", safeUri(uri), statusCode, statusLine.getReasonPhrase());
            return throwHttpStatusCodeException(statusCode, defaultMessage);
        }
    } catch (IOException e) {
        throw wrap(e);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpGet(org.apache.http.client.methods.HttpGet) HttpClientResponse(org.gradle.internal.resource.transport.http.HttpClientResponse) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

IOException (java.io.IOException)2 URI (java.net.URI)2 StatusLine (org.apache.http.StatusLine)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 HttpClientResponse (org.gradle.internal.resource.transport.http.HttpClientResponse)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPut (org.apache.http.client.methods.HttpPut)1 AbstractHttpEntity (org.apache.http.entity.AbstractHttpEntity)1