Search in sources :

Example 21 with HttpPut

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 22 with HttpPut

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());
}
Also used : UserModel(com.gitblit.models.UserModel) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) RepositoryModel(com.gitblit.models.RepositoryModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 23 with HttpPut

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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPut(org.apache.http.client.methods.HttpPut) TestRequest(com.android.volley.mock.TestRequest)

Example 24 with 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);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpPut(org.apache.http.client.methods.HttpPut)

Example 25 with HttpPut

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);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpPut(org.apache.http.client.methods.HttpPut) ClientProtocolException(org.apache.http.client.ClientProtocolException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) IOException(java.io.IOException)

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