Search in sources :

Example 1 with ParameterizedCollectionType

use of org.apache.cxf.jaxrs.utils.ParameterizedCollectionType in project camel by apache.

the class CxfRsAsyncProducerTest method testGetCustomersWithHttpCentralClientAPI.

@Test
public void testGetCustomersWithHttpCentralClientAPI() {
    Exchange exchange = template.send("direct://proxy", newExchange -> {
        newExchange.setPattern(ExchangePattern.InOut);
        Message inMessage = newExchange.getIn();
        inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
        inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/");
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, List.class);
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, new ParameterizedCollectionType(Customer.class));
        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));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) ParameterizedCollectionType(org.apache.cxf.jaxrs.utils.ParameterizedCollectionType) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)1 ParameterizedCollectionType (org.apache.cxf.jaxrs.utils.ParameterizedCollectionType)1 Test (org.junit.Test)1