Package org.apache.camel

Examples of org.apache.camel.Message


    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();
View Full Code Here


    @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());
View Full Code Here

    public void testGetCustomerWithHttpCentralClientAPI() {
     // START SNIPPET: HttpExample
        Exchange exchange = template.send("direct://http", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.setPattern(ExchangePattern.InOut);
                Message inMessage = exchange.getIn();
                setupDestinationURL(inMessage);
                // using the http central client API
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
                // set the Http method
                inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
                // set the relative path
                inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");               
                // Specify the response class , cxfrs will use InputStream as the response object type
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                // set a customer header
                inMessage.setHeader("key", "value");
                // since we use the Get method, so we don't need to set the message body
                inMessage.setBody(null);               
            }
        });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
View Full Code Here

    public void testSuppressGetCustomerExceptionWithCxfRsEndpoint() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true&throwExceptionOnFailure=false", 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);
       
       
    }
View Full Code Here

    public void testGetCustomerExceptionWithCxfRsEndpoint() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=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
        assertNotNull("Expect the exception here", exchange.getException());
View Full Code Here

    public void testGetCustomerWithCxfRsEndpoint() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=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, "GET");
                    // set the relative path
                    inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");               
                    // Specify the response class , cxfrs will use InputStream as the response object type
                    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                    // since we use the Get method, so we don't need to set the message body
                    inMessage.setBody(null);               
                }
            });
    
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
View Full Code Here

    @Test
    public void testGetCustomerWithVariableReplacementAndCxfRsEndpoint() {
        Exchange exchange = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=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, "GET");
                // set the relative path
                inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/{customerId}");
                // Set variables for replacement
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, new String[] {"123"});
                // Specify the response class , cxfrs will use InputStream as the response object type
                inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                // since we use the Get method, so we don't need to set the message body
                inMessage.setBody(null);
            }
        });

        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
View Full Code Here

    public void testAddCustomerUniqueResponseCodeWithHttpClientAPI() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "?httpClientAPI=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();
View Full Code Here

    @Test
    public void testAddCustomerUniqueResponseCodeWithProxyAPI() {
        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, "addCustomerUniqueResponseCode");
                // 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
                Customer customer = new Customer();
                customer.setId(8888);
                customer.setName("ProxyAPI");
                inMessage.setBody(customer);
            }
        });
       
        // get the response message
        Response response = (Response) exchange.getOut().getBody();
View Full Code Here

    public void testAddCustomerUniqueResponseCode() {
        Exchange exchange
            = template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "?httpClientAPI=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");               
                    // put the response's entity into out message body
                    inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
                    // create a new customer object
                    Customer customer = new Customer();
                    customer.setId(8888);
                    customer.setName("Willem");
                    inMessage.setBody(customer);               
                }
            });
       
        // get the response message
        Customer response = (Customer) exchange.getOut().getBody();
View Full Code Here

TOP

Related Classes of org.apache.camel.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.