Search in sources :

Example 11 with Customer

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));
}
Also used : Exchange(org.apache.camel.Exchange) Response(javax.ws.rs.core.Response) Message(org.apache.camel.Message) Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) Test(org.junit.Test)

Example 12 with Customer

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));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) Test(org.junit.Test)

Example 13 with Customer

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"));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) Test(org.junit.Test)

Example 14 with Customer

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());
}
Also used : Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 15 with Customer

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"));
}
Also used : Customer(org.apache.camel.component.cxf.jaxrs.testbean.Customer) Test(org.junit.Test)

Aggregations

Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)33 Test (org.junit.Test)31 Exchange (org.apache.camel.Exchange)27 Message (org.apache.camel.Message)25 Processor (org.apache.camel.Processor)16 CxfOperationException (org.apache.camel.component.cxf.CxfOperationException)16 Response (javax.ws.rs.core.Response)4 WebTarget (javax.ws.rs.client.WebTarget)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 ParameterizedCollectionType (org.apache.cxf.jaxrs.utils.ParameterizedCollectionType)1