Search in sources :

Example 6 with DefaultMessage

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

the class BeanInfoAMoreComplexOverloadedTest method testAmbigious.

public void testAmbigious() throws Exception {
    BeanInfo beanInfo = new BeanInfo(context, Bean.class);
    Message message = new DefaultMessage();
    message.setBody("Hello World");
    Exchange exchange = new DefaultExchange(context);
    exchange.setIn(message);
    try {
        beanInfo.createInvocation(new Bean(), exchange);
        fail("Should have thrown an exception");
    } catch (AmbiguousMethodCallException e) {
        assertEquals(2, e.getMethods().size());
    }
}
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)

Example 7 with DefaultMessage

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

the class DefaultExchangeFormatterTest method setUp.

@Before
public void setUp() {
    camelContext = new DefaultCamelContext();
    Message message = new DefaultMessage();
    message.setBody("This is the message body");
    exchange = new DefaultExchange(camelContext);
    exchange.setIn(message);
    exchangeFormatter = new DefaultExchangeFormatter();
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultExchange(org.apache.camel.impl.DefaultExchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

Example 8 with DefaultMessage

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

the class SetBodyProcessor method process.

@Override
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
            ExchangeHelper.replaceMessage(exchange, msg, false);
        } else {
            // no copy needed so set replace value directly
            old.setBody(newBody);
        }
    } 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)

Example 9 with DefaultMessage

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

the class GZIPHelperTest method createMessageWithContentEncodingHeader.

private Message createMessageWithContentEncodingHeader(String contentEncoding) {
    Message msg = new DefaultMessage();
    msg.setHeader("Content-Encoding", contentEncoding);
    return msg;
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage)

Example 10 with DefaultMessage

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

the class ObjectHelperTest method testIteratorWithEmptyMessage.

public void testIteratorWithEmptyMessage() {
    Message msg = new DefaultMessage();
    msg.setBody("");
    Iterator<Object> it = ObjectHelper.createIterator(msg);
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("Should have thrown exception");
    } catch (NoSuchElementException nsee) {
        // expected
        assertEquals("no more element available for '' at the index 0", nsee.getMessage());
    }
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) NoSuchElementException(java.util.NoSuchElementException)

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