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