Search in sources :

Example 41 with DefaultMessage

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

the class ObjectHelperTest method testIteratorWithMessage.

public void testIteratorWithMessage() {
    Message msg = new DefaultMessage();
    msg.setBody("a,b,c");
    Iterator<?> it = ObjectHelper.createIterator(msg);
    assertEquals("a", it.next());
    assertEquals("b", it.next());
    assertEquals("c", it.next());
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) NoSuchElementException(java.util.NoSuchElementException)

Example 42 with DefaultMessage

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

the class ObjectHelperTest method testIteratorWithNullMessage.

public void testIteratorWithNullMessage() {
    Message msg = new DefaultMessage();
    msg.setBody(null);
    Iterator<Object> it = ObjectHelper.createIterator(msg);
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) NoSuchElementException(java.util.NoSuchElementException)

Example 43 with DefaultMessage

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

the class BeanInfoAMoreComplexOverloadedTest method testRequestA.

public void testRequestA() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);
    Message message = new DefaultMessage();
    message.setBody(new RequestA());
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);
    MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
    Method method = methodInvocation.getMethod();
    assertEquals("doSomething", method.getName());
    assertEquals(RequestA.class, method.getGenericParameterTypes()[0]);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) Method(java.lang.reflect.Method)

Example 44 with DefaultMessage

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

the class BeanInfoOverloadedTest method testBeanInfoOverloaded.

public void testBeanInfoOverloaded() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);
    Message message = new DefaultMessage();
    message.setBody(new RequestB());
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);
    MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
    Method method = methodInvocation.getMethod();
    assertEquals("doSomething", method.getName());
    assertEquals(RequestB.class, method.getGenericParameterTypes()[0]);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) Method(java.lang.reflect.Method)

Example 45 with DefaultMessage

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

the class TransformProcessor method process.

public boolean process(Exchange exchange, AsyncCallback callback) {
    try {
        Object newBody = expression.evaluate(exchange, Object.class);
        if (exchange.getException() != null) {
            // the expression threw an exception so we should break-out
            callback.done(true);
            return true;
        }
        boolean out = exchange.hasOut();
        Message old = out ? exchange.getOut() : exchange.getIn();
        // create a new message container so we do not drag specialized message objects along
        // but that is only needed if the old message is a specialized message
        boolean copyNeeded = !(old.getClass().equals(DefaultMessage.class));
        if (copyNeeded) {
            Message msg = new DefaultMessage();
            msg.copyFromWithNewBody(old, newBody);
            // replace message on exchange (must set as OUT)
            ExchangeHelper.replaceMessage(exchange, msg, true);
        } else {
            // no copy needed so set replace value directly
            old.setBody(newBody);
            // but the message must be on OUT
            if (!exchange.hasOut()) {
                exchange.setOut(exchange.getIn());
            }
        }
    } catch (Throwable e) {
        exchange.setException(e);
    }
    callback.done(true);
    return true;
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage)

Aggregations

DefaultMessage (org.apache.camel.impl.DefaultMessage)45 Message (org.apache.camel.Message)44 Exchange (org.apache.camel.Exchange)22 DefaultExchange (org.apache.camel.impl.DefaultExchange)19 Test (org.junit.Test)16 HashMap (java.util.HashMap)15 IOException (java.io.IOException)4 Method (java.lang.reflect.Method)3 NoSuchElementException (java.util.NoSuchElementException)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 Before (org.junit.Before)3 Map (java.util.Map)2 BiFunction (java.util.function.BiFunction)2 BasicAttribute (javax.naming.directory.BasicAttribute)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 ModificationItem (javax.naming.directory.ModificationItem)2 Processor (org.apache.camel.Processor)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 Path (org.apache.hadoop.fs.Path)2