use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsAsyncProducerTest method testAddCustomerUniqueResponseCodeWithHttpClientAPI.
@Test
public void testAddCustomerUniqueResponseCodeWithHttpClientAPI() {
Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "?httpClientAPI=true", newExchange -> {
newExchange.setPattern(ExchangePattern.InOut);
Message inMessage = newExchange.getIn();
inMessage.setHeader(Exchange.HTTP_METHOD, "POST");
inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customersUniqueResponseCode");
Customer customer = new Customer();
customer.setId(9999);
customer.setName("HttpClient");
inMessage.setBody(customer);
});
// get the response message
Response response = (Response) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
assertNotNull("The response entity should not be null", response.getEntity());
// check the response code
assertEquals("Get a wrong response code", 201, response.getStatus());
// check the response code from message header
assertEquals("Get a wrong response code", 201, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsAsyncProducerTest method testGetCustomersWithClientProxyAPI.
@Test
public void testGetCustomersWithClientProxyAPI() {
Exchange exchange = template.send("direct://proxy", newExchange -> {
newExchange.setPattern(ExchangePattern.InOut);
Message inMessage = newExchange.getIn();
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomers");
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
inMessage.setBody(null);
});
// get the response message
List<Customer> response = CastUtils.cast((List<?>) exchange.getOut().getBody());
assertNotNull("The response should not be null ", response);
assertTrue("Dan is missing!", response.contains(new Customer(113, "Dan")));
assertTrue("John is missing!", response.contains(new Customer(123, "John")));
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsAsyncProducerTest method testGetCustomerWithHttpCentralClientAPI.
@Test
public void testGetCustomerWithHttpCentralClientAPI() {
Exchange exchange = template.send("direct://http", newExchange -> {
newExchange.setPattern(ExchangePattern.InOut);
Message inMessage = newExchange.getIn();
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
inMessage.setHeader("key", "value");
inMessage.setBody(null);
});
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
assertNotNull("The response should not be null ", response);
assertEquals("Get a wrong customer id ", String.valueOf(response.getId()), "123");
assertEquals("Get a wrong customer name", response.getName(), "John");
assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("Get a wrong header value", "value", exchange.getOut().getHeader("key"));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsSpringConsumerTest method testInvokeCxfRsConsumer.
@Test
public void testInvokeCxfRsConsumer() throws Exception {
String address = "http://localhost:" + port1 + "/CxfRsSpringConsumerInvokeService/customerservice/customers/123";
WebClient wc = WebClient.create(address);
Customer c = wc.accept("application/json").get(Customer.class);
assertEquals(246L, c.getId());
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfOperationExceptionTest method testRestServerDirectlyAddCustomerWithExceptionsTurnedOff.
@Test
public void testRestServerDirectlyAddCustomerWithExceptionsTurnedOff() {
Customer input = new Customer();
input.setName("Donald Duck");
// we cannot convert directly to Customer as we need camel-jaxb
String response = template.requestBodyAndHeader("cxfrs:bean:rsClient?throwExceptionOnFailure=false", input, Exchange.HTTP_METHOD, "POST", String.class);
assertNotNull(response);
assertTrue(response.contains("Problem accessing /CxfOperationExceptionTest/rest"));
}
Aggregations