Search in sources :

Example 6 with Customer

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

Example 7 with Customer

use of org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer in project camel by apache.

the class CxfRsConsumerSimpleBindingTest method testUpdateVipCustomer.

@Test
public void testUpdateVipCustomer() throws Exception {
    HttpPut put = new HttpPut("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/vip/gold/123");
    StringWriter sw = new StringWriter();
    jaxb.createMarshaller().marshal(new Customer(123, "Raul2"), 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 8 with Customer

use of org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer in project camel by apache.

the class CxfRsConsumerSimpleBindingTest method testMultipartPostWithoutParameters.

@Test
public void testMultipartPostWithoutParameters() throws Exception {
    HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/multipart/withoutParameters");
    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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) StringWriter(java.io.StringWriter) Customer(org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer) HttpResponse(org.apache.http.HttpResponse) File(java.io.File) Test(org.junit.Test)

Aggregations

Customer (org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.Customer)8 HttpResponse (org.apache.http.HttpResponse)7 Test (org.junit.Test)7 StringWriter (java.io.StringWriter)5 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 File (java.io.File)2 CustomerList (org.apache.camel.component.cxf.jaxrs.simplebinding.testbean.CustomerList)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPut (org.apache.http.client.methods.HttpPut)2 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)2 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataHandler (javax.activation.DataHandler)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1