Search in sources :

Example 1 with HttpPut

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

the class CxfBeanTest method testPutConsumer.

@Test
public void testPutConsumer() throws Exception {
    HttpPut put = new HttpPut("http://localhost:" + PORT1 + "/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.setEntity(entity);
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.close();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 2 with HttpPut

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

the class CxfRsConsumerSimpleBindingTest method testUpdateCustomerBodyAndHeaders.

@Test
public void testUpdateCustomerBodyAndHeaders() throws Exception {
    HttpPut put = new HttpPut("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
    StringWriter sw = new StringWriter();
    jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
    put.setEntity(new StringEntity(sw.toString()));
    put.addHeader("Content-Type", "text/xml");
    put.addHeader("Accept", "text/xml");
    HttpResponse response = httpclient.execute(put);
    assertEquals(200, response.getStatusLine().getStatusCode());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) StringWriter(java.io.StringWriter) Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 3 with HttpPut

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

the class CxfRsConsumerTest method testPutConsumer.

@Test
public void testPutConsumer() throws Exception {
    HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
    StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
    entity.setContentType("text/xml; charset=ISO-8859-1");
    put.addHeader("test", "header1;header2");
    put.setEntity(entity);
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.close();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 4 with HttpPut

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

the class CxfRsConsumerWithBeanTest method sendPutRequest.

private void sendPutRequest(String uri) throws Exception {
    HttpPut put = new HttpPut(uri);
    StringEntity entity = new StringEntity("string");
    entity.setContentType("text/plain");
    put.setEntity(entity);
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    try {
        HttpResponse response = httpclient.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("c20string", EntityUtils.toString(response.getEntity()));
    } finally {
        httpclient.close();
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 5 with HttpPut

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

the class Client method put.

/**
   * Send a PUT request
   * @param cluster the cluster definition
   * @param path the path or URI
   * @param headers the HTTP headers to include, <tt>Content-Type</tt> must be
   * supplied
   * @param content the content bytes
   * @return a Response object with response detail
   * @throws IOException
   */
public Response put(Cluster cluster, String path, Header[] headers, byte[] content) throws IOException {
    HttpPut method = new HttpPut(path);
    try {
        method.setEntity(new InputStreamEntity(new ByteArrayInputStream(content), content.length));
        HttpResponse resp = execute(cluster, method, headers, path);
        headers = resp.getAllHeaders();
        content = getResponseBody(resp);
        return new Response(resp.getStatusLine().getStatusCode(), headers, content);
    } finally {
        method.releaseConnection();
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

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