Search in sources :

Example 36 with DefaultMessage

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);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) Test(org.junit.Test)

Example 37 with DefaultMessage

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));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) AttributesMapper(org.springframework.ldap.core.AttributesMapper) Test(org.junit.Test)

Example 38 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)

Example 39 with DefaultMessage

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());
}
Also used : Exchange(org.apache.camel.Exchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 40 with DefaultMessage

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;
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) ServerMessage(org.cometd.bayeux.server.ServerMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DefaultMessage (org.apache.camel.impl.DefaultMessage)48 Message (org.apache.camel.Message)47 Exchange (org.apache.camel.Exchange)23 DefaultExchange (org.apache.camel.impl.DefaultExchange)19 Test (org.junit.Test)18 HashMap (java.util.HashMap)16 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