Search in sources :

Example 6 with HttpResponse

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

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();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 8 with HttpResponse

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());
}
Also used : Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpGet(org.apache.http.client.methods.HttpGet) StringReader(java.io.StringReader) HttpResponse(org.apache.http.HttpResponse) CustomerList(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList) Test(org.junit.Test)

Example 9 with HttpResponse

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) InputStreamEntity(org.apache.http.entity.InputStreamEntity) Test(org.junit.Test)

Example 10 with HttpResponse

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());
}
Also used : Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

HttpResponse (org.apache.http.HttpResponse)1502 HttpGet (org.apache.http.client.methods.HttpGet)717 Test (org.junit.Test)686 IOException (java.io.IOException)355 TestHttpClient (io.undertow.testutils.TestHttpClient)290 HttpPost (org.apache.http.client.methods.HttpPost)238 HttpClient (org.apache.http.client.HttpClient)237 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)219 HttpEntity (org.apache.http.HttpEntity)192 Header (org.apache.http.Header)178 StringEntity (org.apache.http.entity.StringEntity)138 ArrayList (java.util.ArrayList)104 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)104 InputStream (java.io.InputStream)97 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)81 URI (java.net.URI)77 StatusLine (org.apache.http.StatusLine)76 ClientProtocolException (org.apache.http.client.ClientProtocolException)76 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)71 NameValuePair (org.apache.http.NameValuePair)63