use of org.apache.http.HttpResponse 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.HttpResponse in project camel by apache.
the class CxfBeanTest method testPostConsumerUniqueResponseCode.
@Test
public void testPostConsumerUniqueResponseCode() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT1 + "/customerservice/customersUniqueResponseCode");
post.addHeader("Accept", "text/xml");
StringEntity entity = new StringEntity(POST2_REQUEST, "ISO-8859-1");
entity.setContentType("text/xml; charset=ISO-8859-1");
post.setEntity(entity);
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
try {
HttpResponse response = httpclient.execute(post);
assertEquals(201, response.getStatusLine().getStatusCode());
String id = getCustomerId("James");
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>" + id + "</id><name>James</name></Customer>", EntityUtils.toString(response.getEntity()));
} finally {
httpclient.close();
}
}
use of org.apache.http.HttpResponse in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testListVipCustomers.
@Test
public void testListVipCustomers() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold");
get.addHeader("Content-Type", "text/xml");
get.addHeader("Accept", "text/xml");
HttpResponse response = httpclient.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
CustomerList cl = (CustomerList) jaxb.createUnmarshaller().unmarshal(new StringReader(EntityUtils.toString(response.getEntity())));
List<Customer> vips = cl.getCustomers();
assertEquals(2, vips.size());
assertEquals(123, vips.get(0).getId());
assertEquals(456, vips.get(1).getId());
}
use of org.apache.http.HttpResponse in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testUploadInputStream.
@Test
public void testUploadInputStream() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_inputstream");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
HttpResponse response = httpclient.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.HttpResponse in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testGetCustomerOnlyHeaders.
@Test
public void testGetCustomerOnlyHeaders() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123");
get.addHeader("Accept", "text/xml");
HttpResponse response = httpclient.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
Customer entity = (Customer) jaxb.createUnmarshaller().unmarshal(response.getEntity().getContent());
assertEquals(123, entity.getId());
}
Aggregations