Search in sources :

Example 1 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 2 with Customer

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

Example 3 with Customer

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

Example 4 with Customer

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

Example 5 with Customer

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>"));
}
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