use of org.apache.http.client.methods.HttpPut in project okhttp by square.
the class OkApacheClientTest method putEmptyEntity.
@Test
public void putEmptyEntity() throws Exception {
server.enqueue(new MockResponse());
final HttpPut put = new HttpPut(server.url("/").url().toURI());
client.execute(put);
RecordedRequest request = server.takeRequest();
assertEquals(0, request.getBodySize());
assertNotNull(request.getBody());
}
use of org.apache.http.client.methods.HttpPut in project gitblit by gitblit.
the class FilestoreServletTest method testUpload.
@Test
public void testUpload() throws Exception {
FileUtils.delete(filestore().getStorageFolder());
filestore().clearFilestoreCache();
RepositoryModel r = gitblit().getRepositoryModel(repoName);
UserModel u = new UserModel("admin");
u.canAdmin = true;
//No upload limit
settings().overrideSetting(Keys.filestore.maxUploadSize, FilestoreManager.UNDEFINED_SIZE);
final BlobInfo blob = new BlobInfo(512 * FileUtils.KB);
final String expectedUploadURL = GitBlitSuite.url + repoLfs + blob.hash;
final String initialUploadURL = GitBlitSuite.url + repoLfs + "batch";
HttpClient client = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(initialUploadURL);
// add request header
request.addHeader(HttpHeaders.ACCEPT, FilestoreServlet.GIT_LFS_META_MIME);
request.addHeader(HttpHeaders.CONTENT_ENCODING, FilestoreServlet.GIT_LFS_META_MIME);
String content = String.format("{%s:%s,%s:[{%s:%s,%s:%d}]}", "\"operation\"", "\"upload\"", "\"objects\"", "\"oid\"", "\"" + blob.hash + "\"", "\"size\"", blob.length);
HttpEntity entity = new ByteArrayEntity(content.getBytes("UTF-8"));
request.setEntity(entity);
HttpResponse response = client.execute(request);
String responseMessage = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
assertEquals(200, response.getStatusLine().getStatusCode());
String expectedContent = String.format("{%s:[{%s:%s,%s:%d,%s:{%s:{%s:%s}}}]}", "\"objects\"", "\"oid\"", "\"" + blob.hash + "\"", "\"size\"", blob.length, "\"actions\"", "\"upload\"", "\"href\"", "\"" + expectedUploadURL + "\"");
assertEquals(expectedContent, responseMessage);
//Now try to upload the binary download
HttpPut putRequest = new HttpPut(expectedUploadURL);
putRequest.setEntity(new ByteArrayEntity(blob.blob));
response = client.execute(putRequest);
responseMessage = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
assertEquals(200, response.getStatusLine().getStatusCode());
//Confirm behind the scenes that it is available
ByteArrayOutputStream savedBlob = new ByteArrayOutputStream();
assertEquals(Status.Available, filestore().downloadBlob(blob.hash, u, r, savedBlob));
assertArrayEquals(blob.blob, savedBlob.toByteArray());
}
use of org.apache.http.client.methods.HttpPut in project iosched by google.
the class HttpClientStackTest method testCreatePutRequestWithBody.
public void testCreatePutRequestWithBody() throws Exception {
TestRequest.PutWithBody request = new TestRequest.PutWithBody();
assertEquals(request.getMethod(), Method.PUT);
HttpUriRequest httpRequest = HttpClientStack.createHttpRequest(request, null);
assertTrue(httpRequest instanceof HttpPut);
}
use of org.apache.http.client.methods.HttpPut in project afinal by yangfuhai.
the class FinalHttp method put.
public void put(String url, Header[] headers, HttpEntity entity, String contentType, AjaxCallBack<? extends Object> callBack) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPut(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, callBack);
}
use of org.apache.http.client.methods.HttpPut in project tdi-studio-se by Talend.
the class RestClient method executePutRequest.
private HttpResponse executePutRequest(String apiURI, String payloadAsString) {
try {
HttpPut putRequest = new HttpPut(bonitaURI + apiURI);
putRequest.addHeader("Content-Type", "application/json");
StringEntity input = new StringEntity(payloadAsString);
input.setContentType("application/json");
putRequest.setEntity(input);
return httpClient.execute(putRequest, httpContext);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Aggregations