Package org.apache.camel

Examples of org.apache.camel.Exchange


    private Message getMessage(MockEndpoint mock) {
        List<Exchange> exs = mock.getExchanges();
        assertNotNull(exs);
        assertEquals(1, exs.size());
        Exchange ex = exs.get(0);
        Message mess = ex.getIn();
        assertNotNull(mess);
        return mess;
    }
View Full Code Here


    @EndpointInject(uri = "mock:image")
    MockEndpoint image;

    protected void checkImage(MockEndpoint mock, int height, int width, String type, BarcodeFormat format) throws IOException {
        Exchange ex = mock.getReceivedExchanges().get(0);
        File in = ex.getIn().getBody(File.class);

        // check image
        BufferedImage i = ImageIO.read(in);
        assertTrue(height >= i.getHeight());
        assertTrue(width >= i.getWidth());
View Full Code Here

        this.checkFormat(in, format);
        in.delete();
    }

    protected void checkImage(MockEndpoint mock, String type, BarcodeFormat format) throws IOException {
        Exchange ex = mock.getReceivedExchanges().get(0);
        File in = ex.getIn().getBody(File.class);
        this.checkType(in, type);
        this.checkFormat(in, format);
        in.delete();
    }
View Full Code Here

        assertNotNull(mc);
        final String requestText = "Hello World!";
        final String responseText = "How are you";
        mc.setMessageListener(new MyMessageListener(requestText, responseText));
        final String correlationId = UUID.randomUUID().toString().replace("-", "");
        Exchange exchange = template.request("sjms:queue:" + queueName + "?exchangePattern=InOut", new Processor() {
           
            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setBody(requestText);
                exchange.getIn().setHeader("JMSCorrelationID", correlationId);
            }
        });
        assertNotNull(exchange);
        assertTrue(exchange.getIn().getBody() instanceof String);
        assertEquals(responseText, exchange.getOut().getBody());
        assertEquals(correlationId, exchange.getOut().getHeader("JMSCorrelationID", String.class));
        mc.close();

    }
View Full Code Here

    }
   
    @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    
    }
View Full Code Here

        // END SNIPPET: ProxyExample    
    }
   
    @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));
    }
View Full Code Here

        assertNotNull(mc);
        final String requestText = "Hello World!";
        final String responseText = "How are you";
        mc.setMessageListener(new MyMessageListener(requestText, responseText));
        final String correlationId = UUID.randomUUID().toString().replace("-", "");
        Exchange exchange = template.request("direct:start", new Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getOut().setBody(requestText);
                exchange.getOut().setHeader("JMSCorrelationID", correlationId);
            }
        });
        assertNotNull(exchange);
        assertTrue(exchange.getIn().getBody() instanceof String);
        assertEquals(responseText, exchange.getIn().getBody());
        assertEquals(correlationId, exchange.getIn().getHeader("JMSCorrelationID", String.class));
        mc.close();

    }
View Full Code Here

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

        // END SNIPPET: HttpExample
    }
   
    @Test
    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

    @Override
    protected int poll() throws Exception {
        Stack<Comment> newComments = getComments();
        while (!newComments.empty()) {
            Comment newComment = newComments.pop();
            Exchange e = getEndpoint().createExchange();
            e.getIn().setBody(newComment);
            getProcessor().process(e);
        }
        return newComments.size();
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.Exchange

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.