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