Search in sources :

Example 56 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ExchangeHelperTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty("foo", 123);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 57 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ExpressionListComparatorTest method testExpressionListComparator.

public void testExpressionListComparator() {
    List<Expression> list = new ArrayList<Expression>();
    list.add(new MyFooExpression());
    list.add(new MyBarExpression());
    ExpressionListComparator comp = new ExpressionListComparator(list);
    Exchange e1 = new DefaultExchange(context);
    Exchange e2 = new DefaultExchange(context);
    int out = comp.compare(e1, e2);
    assertEquals(0, out);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList)

Example 58 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class DefaultValidationErrorHandlerTest method testHandleErrorsResult.

public void testHandleErrorsResult() throws Exception {
    DefaultValidationErrorHandler eh = new DefaultValidationErrorHandler();
    eh.error(new SAXParseException("foo", createLocator(3, 5)));
    eh.error(new SAXParseException("bar", createLocator(9, 12)));
    assertEquals(false, eh.isValid());
    Exchange exchange = new DefaultExchange(context);
    try {
        eh.handleErrors(exchange, createScheme(), new SAXResult());
        fail("Should have thrown an exception");
    } catch (SchemaValidationException e) {
        assertEquals(2, e.getErrors().size());
        assertEquals(0, e.getFatalErrors().size());
        assertEquals(0, e.getWarnings().size());
        assertNotNull(e.getSchema());
        assertNotNull(e.getExchange());
        assertTrue(e.getMessage().startsWith("Validation failed for: org.apache.camel.processor.validation.DefaultValidationErrorHandlerTest"));
        assertTrue(e.getMessage().contains("errors: ["));
        assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: foo, Line : 3, Column : 5"));
        assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: bar, Line : 9, Column : 12"));
        assertTrue(e.getMessage().contains("Exchange[]"));
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SAXResult(javax.xml.transform.sax.SAXResult) SAXParseException(org.xml.sax.SAXParseException)

Example 59 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class XPathBuilder method evaluate.

/**
     * Evaluates the given xpath using the provided body.
     * <p/>
     * The evaluation uses by default {@link javax.xml.xpath.XPathConstants#NODESET} as the type
     * used during xpath evaluation. The output from xpath is then afterwards type converted
     * using Camel's type converter to the given type.
     * <p/>
     * If you want to evaluate xpath using a different type, then call {@link #setResultType(Class)}
     * prior to calling this evaluate method.
     *
     * @param context the camel context
     * @param body    the body
     * @param type    the type to return
     * @return result of the evaluation
     */
public <T> T evaluate(CamelContext context, Object body, Class<T> type) {
    ObjectHelper.notNull(context, "CamelContext");
    // create a dummy Exchange to use during evaluation
    Exchange dummy = new DefaultExchange(context);
    dummy.getIn().setBody(body);
    try {
        return evaluate(dummy, type);
    } finally {
        // remove the thread local after usage
        exchange.remove();
    }
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange)

Example 60 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class PredicateBuilderConcurrentTest method testPredicateBuilderConcurrent.

public void testPredicateBuilderConcurrent() throws Exception {
    context.start();
    List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
    ExecutorService pool = Executors.newFixedThreadPool(10);
    for (int i = 0; i < 1000; i++) {
        final Integer num = i;
        Future<Boolean> future = pool.submit(new Callable<Boolean>() {

            public Boolean call() throws Exception {
                Expression left = ExpressionBuilder.headerExpression("foo");
                Expression right;
                if (num % 2 == 0) {
                    right = ExpressionBuilder.constantExpression("ABC");
                } else {
                    right = ExpressionBuilder.constantExpression("DEF");
                }
                Predicate predicate = PredicateBuilder.isEqualTo(left, right);
                Exchange exchange = new DefaultExchange(context);
                exchange.getIn().setBody("Hello World");
                exchange.getIn().setHeader("foo", "ABC");
                return predicate.matches(exchange);
            }
        });
        futures.add(future);
    }
    for (int i = 0; i < 1000; i++) {
        Boolean result = futures.get(i).get(10, TimeUnit.SECONDS);
        if (i % 2 == 0) {
            assertEquals("Should be true for #" + i, true, result.booleanValue());
        } else {
            assertEquals("Should be false for #" + i, false, result.booleanValue());
        }
    }
    pool.shutdownNow();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) ArrayList(java.util.ArrayList) Predicate(org.apache.camel.Predicate) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Aggregations

DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Exchange (org.apache.camel.Exchange)381 Test (org.junit.Test)254 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)127 CamelContext (org.apache.camel.CamelContext)54 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 HashMap (java.util.HashMap)33 Message (org.apache.camel.Message)32 Before (org.junit.Before)32 Tx (org.nhindirect.common.tx.model.Tx)31 ESMClass (org.jsmpp.bean.ESMClass)30 Processor (org.apache.camel.Processor)22 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)22 Expression (org.apache.camel.Expression)21 File (java.io.File)20 DefaultMessage (org.apache.camel.impl.DefaultMessage)20 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 URL (java.net.URL)16 Date (java.util.Date)16