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 CxfRsProducerClientFactoryCache2Test method doRunTest.
private void doRunTest(ProducerTemplate template, final int clientPort) {
// use request as we want InOut
Exchange exchange = template.request("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 testGetCustomerWithClientProxyAPI.
@Test
public void testGetCustomerWithClientProxyAPI() {
// START SNIPPET: ProxyExample
Exchange exchange = template.send("direct://proxy", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
// using the proxy client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
// set a customer header
inMessage.setHeader("key", "value");
// setup the accept content type
inMessage.setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
// set the parameters , if you just have one parameter
// camel will put this object into an Object[] itself
inMessage.setBody("123");
}
});
// 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"));
// END SNIPPET: ProxyExample
}
use of org.apache.camel.component.cxf.jaxrs.testbean.Customer in project camel by apache.
the class CxfRsProducerTest method testGetCustomersWithClientProxyAPI.
@Test
public void testGetCustomersWithClientProxyAPI() {
Exchange exchange = template.send("direct://proxy", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomers");
// using the proxy client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
// set the parameters , if you just have one parameter
// camel will put this object into an Object[] itself
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 CxfRsProducerTest method testRestServerDirectlyAddCustomer.
@Test
public void testRestServerDirectlyAddCustomer() {
Customer input = new Customer();
input.setName("Donald Duck");
// we cannot convert directly to Customer as we need camel-jaxb
String response = template.requestBodyAndHeader("cxfrs:http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/customerservice/customers?synchronous=true", input, Exchange.HTTP_METHOD, "POST", String.class);
assertNotNull(response);
assertTrue(response.endsWith("<name>Donald Duck</name></Customer>"));
}
Aggregations