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());
}
}
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();
}
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;
}
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;
}
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());
}
}
Aggregations