use of org.apache.camel.impl.DefaultMessage in project camel by apache.
the class SpringLdapProducerTest method testWrongBodyType.
@Test(expected = NullPointerException.class)
public void testWrongBodyType() throws Exception {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage();
in.setBody("");
exchange.setIn(in);
ldapProducer.process(exchange);
}
use of org.apache.camel.impl.DefaultMessage in project camel by apache.
the class SpringLdapProducerTest method testSearch.
@Test
public void testSearch() throws Exception {
String dn = "some dn";
String filter = "filter";
Integer scope = SearchControls.SUBTREE_SCOPE;
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage();
Map<String, Object> body = new HashMap<String, Object>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.FILTER, filter);
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.SEARCH);
when(ldapEndpoint.scopeValue()).thenReturn(scope);
processBody(exchange, in, body);
verify(ldapTemplate).search(eq(dn), eq(filter), eq(scope), any(AttributesMapper.class));
}
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;
}
use of org.apache.camel.impl.DefaultMessage in project camel by apache.
the class UnmarshalProcessorTest method testDataFormatReturnsMessage.
public void testDataFormatReturnsMessage() throws Exception {
Exchange exchange = createExchangeWithBody(new DefaultCamelContext(), "body");
Message out = new DefaultMessage();
out.setBody(new Object());
Processor processor = new UnmarshalProcessor(new MyDataFormat(out));
processor.process(exchange);
assertSame("UnmarshalProcessor did not make use of the returned OUT message", out, exchange.getOut());
assertSame("UnmarshalProcessor did change the body bound to the OUT message", out.getBody(), exchange.getOut().getBody());
}
use of org.apache.camel.impl.DefaultMessage in project camel by apache.
the class CometdBinding method createCamelMessage.
public Message createCamelMessage(ServerSession remote, ServerMessage cometdMessage, Object data) {
if (cometdMessage != null) {
data = cometdMessage.getData();
}
Message message = new DefaultMessage();
message.setBody(data);
Map headers = getHeadersFromMessage(cometdMessage);
if (headers != null) {
message.setHeaders(headers);
}
message.setHeader(COMETD_CLIENT_ID_HEADER_NAME, remote.getId());
if (cometdMessage != null && cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME) != null) {
message.setHeader(COMETD_SUBSCRIPTION_HEADER_NAME, cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME));
}
if (enableSessionHeader) {
addSessionAttributesToMessageHeaders(remote, message);
}
return message;
}
Aggregations