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