Search in sources :

Example 81 with HttpPut

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

the class BlobHttpClient method put.

public CloseableHttpResponse put(String table, String body) throws IOException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    String digest = Hex.encodeHexString(Blobs.digest(body));
    String url = Blobs.url(address, table + "/" + digest);
    HttpPut httpPut = new HttpPut(url);
    httpPut.setEntity(new StringEntity(body));
    return httpClient.execute(httpPut);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) HttpPut(org.apache.http.client.methods.HttpPut)

Example 82 with HttpPut

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

the class BlobIntegrationTest method testIndexOnNonBlobTable.

@Test
public void testIndexOnNonBlobTable() throws IOException {
    // this test works only if ES API is enabled
    HttpPut httpPut = new HttpPut(String.format(Locale.ENGLISH, "http://%s:%s/test_no_blobs/default/1", address.getHostName(), address.getPort()));
    String blobData = String.format(Locale.ENGLISH, "{\"content\": \"%s\"}", StringUtils.repeat("a", 1024 * 64));
    httpPut.setEntity(new StringEntity(blobData, ContentType.APPLICATION_OCTET_STREAM));
    CloseableHttpResponse res = httpClient.execute(httpPut);
    assertThat(res.getStatusLine().getStatusCode(), is(201));
    assertThat(res.getStatusLine().getReasonPhrase(), is("Created"));
    assertThat(EntityUtils.toString(res.getEntity()), is("{\"_index\":\"test_no_blobs\",\"_type\":\"default\"," + "\"_id\":\"1\",\"_version\":1,\"_shards\":{\"total\":1,\"successful\":1,\"failed\":0},\"created\":true}"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 83 with HttpPut

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

the class SQLHttpIntegrationTest method upload.

protected String upload(String table, String content) throws IOException {
    String digest = blobDigest(content);
    String url = Blobs.url(address, table, digest);
    HttpPut httpPut = new HttpPut(url);
    httpPut.setEntity(new StringEntity(content));
    CloseableHttpResponse response = httpClient.execute(httpPut);
    assertThat(response.getStatusLine().getStatusCode(), is(201));
    response.close();
    return url;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 84 with HttpPut

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

the class RemoteConsoleAppender method append.

public void append(String content) throws IOException {
    HttpPut putMethod = new HttpPut(consoleUri);
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Appending console to URL -> " + consoleUri);
        }
        putMethod.setEntity(new StringEntity(content, Charset.defaultCharset()));
        HttpService.setSizeHeader(putMethod, content.getBytes().length);
        CloseableHttpResponse response = httpService.execute(putMethod);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got " + response.getStatusLine().getStatusCode());
        }
    } finally {
        putMethod.releaseConnection();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 85 with HttpPut

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

the class HttpClientStackTest method testCreatePutRequest.

public void testCreatePutRequest() throws Exception {
    TestRequest.Put request = new TestRequest.Put();
    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) HttpPut(org.apache.http.client.methods.HttpPut) TestRequest(com.android.volley.mock.TestRequest)

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