Search in sources :

Example 16 with AbstractHttpEntity

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);
    }
}
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)

Aggregations

AbstractHttpEntity (org.apache.http.entity.AbstractHttpEntity)16 OutputStream (java.io.OutputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)5 GZIPOutputStream (java.util.zip.GZIPOutputStream)4 HttpPost (org.apache.http.client.methods.HttpPost)4 BasicHeader (org.apache.http.message.BasicHeader)3 TestHttpClient (io.undertow.testutils.TestHttpClient)2 ProcessingException (javax.ws.rs.ProcessingException)2 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)2 InputStreamEntity (org.apache.http.entity.InputStreamEntity)2 ChunkedOutputStream (org.apache.http.impl.io.ChunkedOutputStream)2 OutboundMessageContext (org.glassfish.jersey.message.internal.OutboundMessageContext)2 Test (org.junit.Test)2 ReadTimeoutException (org.xnio.channels.ReadTimeoutException)2 HttpContent (com.google.api.client.http.HttpContent)1 StreamingContent (com.google.api.client.util.StreamingContent)1