Search in sources :

Example 86 with HttpPut

use of org.apache.http.client.methods.HttpPut 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);
    httpPut.addHeader(HttpHeaders.CONTENT_TYPE, BUILD_CACHE_CONTENT_TYPE);
    addDiagnosticHeaders(httpPut);
    httpPut.setEntity(new AbstractHttpEntity() {

        @Override
        public boolean isRepeatable() {
            return true;
        }

        @Override
        public long getContentLength() {
            return -1;
        }

        @Override
        public InputStream getContent() throws IOException, UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void writeTo(OutputStream outstream) throws IOException {
            output.writeTo(outstream);
        }

        @Override
        public boolean isStreaming() {
            return false;
        }
    });
    CloseableHttpResponse response = null;
    try {
        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)) {
            throwHttpStatusCodeException(statusCode, String.format("Storing entry at '%s' response status %d: %s", safeUri(uri), statusCode, statusLine.getReasonPhrase()));
        }
    } catch (UnknownHostException e) {
        throw new UncheckedException(e);
    } catch (IOException e) {
        // Right now, everything is considered recoverable.
        throw new BuildCacheException(String.format("Unable to store entry at '%s'", safeUri(uri)), e);
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) 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) StatusLine(org.apache.http.StatusLine) UncheckedException(org.gradle.internal.UncheckedException) BuildCacheException(org.gradle.caching.BuildCacheException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity)

Example 87 with HttpPut

use of org.apache.http.client.methods.HttpPut in project gradle by gradle.

the class HttpResourceUploader method upload.

public void upload(LocalResource resource, URI destination) throws IOException {
    HttpPut method = new HttpPut(destination);
    final RepeatableInputStreamEntity entity = new RepeatableInputStreamEntity(resource, ContentType.APPLICATION_OCTET_STREAM);
    method.setEntity(entity);
    CloseableHttpResponse response = null;
    try {
        response = http.performHttpRequest(method);
        if (!http.wasSuccessful(response)) {
            throw new IOException(String.format("Could not PUT '%s'. Received status code %s from server: %s", destination, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
        }
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 88 with HttpPut

use of org.apache.http.client.methods.HttpPut in project SmartAndroidSource by jaychou2012.

the class AbstractAjaxCallback method httpPut.

private void httpPut(String url, Map<String, String> headers, Map<String, Object> params, AjaxStatus status) throws ClientProtocolException, IOException {
    AQUtility.debug("put", url);
    HttpEntityEnclosingRequestBase req = new HttpPut(url);
    httpEntity(url, req, headers, params, status);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpPut(org.apache.http.client.methods.HttpPut)

Example 89 with HttpPut

use of org.apache.http.client.methods.HttpPut in project musicbrainz-android by jdamcd.

the class MusicBrainzWebClient method put.

private void put(String url) throws IOException {
    HttpPut put = new HttpPut(url);
    HttpResponse response = httpClient.execute(put);
    response.getEntity().consumeContent();
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 90 with HttpPut

use of org.apache.http.client.methods.HttpPut in project Talon-for-Twitter by klinker24.

the class TwitLongerHelper method updateTwitlonger.

/**
     * Updates the status on twitlonger to include the tweet id from Twitter.
     * Helpful for threading.
     * @param status Object with the shortened text and the id
     * @param tweetId tweet id of the status posted to twitter
     * @return true if the update is sucessful
     */
public boolean updateTwitlonger(TwitLongerStatus status, long tweetId) {
    try {
        HttpClient client = new DefaultHttpClient();
        HttpPut put = new HttpPut(PUT_URL + status.getId());
        put.addHeader("X-API-KEY", TWITLONGER_API_KEY);
        put.addHeader("X-Auth-Service-Provider", SERVICE_PROVIDER);
        put.addHeader("X-Verify-Credentials-Authorization", getAuthrityHeader(twitter));
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("twitter_status_id", tweetId + ""));
        put.setEntity(new UrlEncodedFormEntity(nvps));
        HttpResponse response = client.execute(put);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        if (rd.readLine() != null) {
            Log.v("twitlonger", "updated the status successfully");
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) InputStreamReader(java.io.InputStreamReader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

HttpPut (org.apache.http.client.methods.HttpPut)153 StringEntity (org.apache.http.entity.StringEntity)89 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)40 HttpResponse (org.apache.http.HttpResponse)29 Test (org.junit.Test)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)27 Deployment (org.activiti.engine.test.Deployment)27 HttpPost (org.apache.http.client.methods.HttpPost)19 HttpGet (org.apache.http.client.methods.HttpGet)17 IOException (java.io.IOException)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 HttpEntity (org.apache.http.HttpEntity)13 URI (java.net.URI)12 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)12 HttpHead (org.apache.http.client.methods.HttpHead)11 Execution (org.activiti.engine.runtime.Execution)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)9