use of org.apache.http.HttpResponse in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testMultipartPostWithParametersAndPayload.
@Test
public void testMultipartPostWithParametersAndPayload() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/multipart/123?query=abcd");
MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.STRICT);
builder.addBinaryBody("part1", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
builder.addBinaryBody("part2", new File(this.getClass().getClassLoader().getResource("java.jpg").toURI()), ContentType.create("image/jpeg"), "java.jpg");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
builder.addTextBody("body", sw.toString(), ContentType.create("text/xml", Consts.UTF_8));
post.setEntity(builder.build());
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 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.HttpResponse in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testNewCustomerOnlyBody.
@Test
public void testNewCustomerOnlyBody() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers");
StringWriter sw = new StringWriter();
jaxb.createMarshaller().marshal(new Customer(123, "Raul"), sw);
post.setEntity(new StringEntity(sw.toString()));
post.addHeader("Content-Type", "text/xml");
post.addHeader("Accept", "text/xml");
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 testUploadDataHandler.
@Test
public void testUploadDataHandler() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_datahandler");
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 CxfRsRouterTest method testGetCustomer.
@Test
public void testGetCustomer() throws Exception {
HttpGet get = new HttpGet("http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/123");
get.addHeader("Accept", "application/json");
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
try {
HttpResponse response = httpclient.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}", EntityUtils.toString(response.getEntity()));
} finally {
httpclient.close();
}
}
Aggregations