use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsAsyncProducerTest method testGetCustomerWithCxfRsEndpoint.
@Test
public void testGetCustomerWithCxfRsEndpoint() {
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, "GET");
inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
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));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsAsyncProducerTest method testProducer422Response.
@Test
public void testProducer422Response() {
Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", newExchange -> {
newExchange.setPattern(ExchangePattern.InOut);
Message message = newExchange.getIn();
message.setHeader(Exchange.HTTP_METHOD, "POST");
message.setHeader(Exchange.HTTP_PATH, "/customerservice/customers");
Customer customer = new Customer();
customer.setId(8888);
customer.setName("");
message.setBody(customer);
});
assertNotNull("Expect the exception here", exchange.getException());
assertThat("Exception should be a CxfOperationException", exchange.getException(), instanceOf(CxfOperationException.class));
CxfOperationException cxfOperationException = CxfOperationException.class.cast(exchange.getException());
assertThat("CXF operation exception has correct response code", cxfOperationException.getStatusCode(), is(422));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsProducerClientFactoryCacheTest method doRunTest.
private void doRunTest(ProducerTemplate template, final int clientPort) {
Exchange exchange = template.send("direct://http", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.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("clientPort", clientPort);
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));
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsProducerTest method testSuppressGetCustomerExceptionWithCxfRsEndpoint.
@Test
public void testSuppressGetCustomerExceptionWithCxfRsEndpoint() {
Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true&throwExceptionOnFailure=false&synchronous=true", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message message = exchange.getIn();
// set the Http method
message.setHeader(Exchange.HTTP_METHOD, "PUT");
// set the relative path
message.setHeader(Exchange.HTTP_PATH, "/customerservice/customers");
// we just setup the customer with a wrong id
Customer customer = new Customer();
customer.setId(222);
customer.setName("user");
message.setBody(customer);
}
});
// we should get the exception here
assertNull("Don't expect the exception here", exchange.getException());
Message result = exchange.getOut();
assertEquals("Get a wrong http status code.", result.getHeader(Exchange.HTTP_RESPONSE_CODE), 406);
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsProducerTest method testAddCustomerUniqueResponseCodeWithHttpClientAPI.
@Test
public void testAddCustomerUniqueResponseCodeWithHttpClientAPI() {
Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "?httpClientAPI=true&synchronous=true", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
// set the Http method
inMessage.setHeader(Exchange.HTTP_METHOD, "POST");
// set the relative path
inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customersUniqueResponseCode");
// create a new customer object
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));
}
Aggregations