Package org.apache.camel

Examples of org.apache.camel.Exchange


        template.sendBody("direct:start", expectedBody);

        resultEndpoint.assertIsSatisfied();

        List<Exchange> list = resultEndpoint.getReceivedExchanges();
        Exchange exchange = list.get(0);
        Object actualBody = exchange.getIn().getBody();

        log.debug("Received: " + actualBody);
        assertEquals("Received body", expectedBody, actualBody);
    }
View Full Code Here


        template.sendBodyAndHeader("activemq:test.a", expectedBody, "cheese", 123);

        resultEndpoint.assertIsSatisfied();

        List<Exchange> list = resultEndpoint.getReceivedExchanges();
        Exchange exchange = list.get(0);
        Object replyTo = exchange.getIn().getHeader("JMSReplyTo");
        LOG.info("Reply to is: " + replyTo);
        Destination destination = assertIsInstanceOf(Destination.class, replyTo);
        assertEquals("ReplyTo", replyQueue.toString(), destination.toString());
    }
View Full Code Here

    public String browseExchange(Integer index) {
        List<Exchange> exchanges = getExchanges();
        if (index >= exchanges.size()) {
            return null;
        }
        Exchange exchange = exchanges.get(index);
        if (exchange == null) {
            return null;
        }
        // must use java type with JMX such as java.lang.String
        return exchange.toString();
    }
View Full Code Here

    public String browseMessageBody(Integer index) {
        List<Exchange> exchanges = getExchanges();
        if (index >= exchanges.size()) {
            return null;
        }
        Exchange exchange = exchanges.get(index);
        if (exchange == null) {
            return null;
        }

        // must use java type with JMX such as java.lang.String
        String body;
        if (exchange.hasOut()) {
            body = exchange.getOut().getBody(String.class);
        } else {
            body = exchange.getIn().getBody(String.class);
        }

        return body;
    }
View Full Code Here

    public String browseMessageAsXml(Integer index, Boolean includeBody) {
        List<Exchange> exchanges = getExchanges();
        if (index >= exchanges.size()) {
            return null;
        }
        Exchange exchange = exchanges.get(index);
        if (exchange == null) {
            return null;
        }

        Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
        String xml = MessageHelper.dumpAsXml(msg, includeBody);

        return xml;
    }
View Full Code Here

        InputStream is = this.getClass().getResourceAsStream("/person1.xml");
       
        template.requestBody("jms:person", is);

        received.assertIsSatisfied();
        Exchange ex = received.getExchanges().get(0);
        String id = XPathBuilder.xpath("//id").namespace("ns1", "http://person.jms2rest.camel.karaf.tutorial.lr.net").stringResult().evaluate(ex, String.class);
        Assert.assertEquals("1001", id);
    }
View Full Code Here

        }
        configured = true;
    }

    protected void sendTimerExchange(long counter) {
        final Exchange exchange = endpoint.createExchange();
        exchange.setProperty(Exchange.TIMER_COUNTER, counter);
        exchange.setProperty(Exchange.TIMER_NAME, endpoint.getTimerName());
        exchange.setProperty(Exchange.TIMER_TIME, endpoint.getTime());
        exchange.setProperty(Exchange.TIMER_PERIOD, endpoint.getPeriod());

        Date now = new Date();
        exchange.setProperty(Exchange.TIMER_FIRED_TIME, now);
        // also set now on in header with same key as quartz to be consistent
        exchange.getIn().setHeader("firedTime", now);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Timer {} is firing #{} count", endpoint.getTimerName(), counter);
        }

        if (!endpoint.isSynchronous()) {
            getAsyncProcessor().process(exchange, new AsyncCallback() {
                @Override
                public void done(boolean doneSync) {
                    // handle any thrown exception
                    if (exchange.getException() != null) {
                        getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
                    }
                }
            });
        } else {
            try {
                getProcessor().process(exchange);
            } catch (Exception e) {
                exchange.setException(e);
            }

            // handle any thrown exception
            if (exchange.getException() != null) {
                getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
            }
        }
    }
View Full Code Here

    /**
     * Creates a message exchange for the given index in the {@link DataSet}
     */
    public Exchange createExchange(long messageIndex) throws Exception {
        Exchange exchange = createExchange();
        getDataSet().populateMessage(exchange, messageIndex);

        Message in = exchange.getIn();
        in.setHeader(Exchange.DATASET_INDEX, messageIndex);

        return exchange;
    }
View Full Code Here

            public void process(Exchange exchange) throws Exception {
                exchange.setException(new MyCustomException());
            }
        });

        Exchange exchangeOne = sendMessage(endpoint, "message one");
        Exchange exchangeTwo = sendMessage(endpoint, "message two");
        Exchange exchangeThree = sendMessage(endpoint, "message three");
        assertMockEndpointsSatisfied();

        assertTrue(exchangeOne.getException() instanceof MyCustomException);
        assertTrue(exchangeTwo.getException() instanceof MyCustomException);
        assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
    }
View Full Code Here

    @Override
    protected void performAssertions(Exchange actual, Exchange copy) throws Exception {
        int receivedCount = receivedCounter.incrementAndGet();
        long index = receivedCount - 1;
        Exchange expected = createExchange(index);

        // now let's assert that they are the same
        if (log.isDebugEnabled()) {
            log.debug("Received message: {} (DataSet index={}) = {}",
                    new Object[]{index, copy.getIn().getHeader(Exchange.DATASET_INDEX, Integer.class), copy});
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.