Search in sources :

Example 96 with Message

use of org.apache.camel.Message in project camel by apache.

the class MessageSupportTest method testGetMessageId.

public void testGetMessageId() {
    context.setUuidGenerator(new SimpleUuidGenerator());
    Exchange exchange = new DefaultExchange(context);
    Message in = exchange.getIn();
    assertEquals("1", in.getMessageId());
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message)

Example 97 with Message

use of org.apache.camel.Message in project camel by apache.

the class MessageSupportTest method testCopyFromSameHeadersInstance.

public void testCopyFromSameHeadersInstance() {
    Exchange exchange = new DefaultExchange(context);
    Message in = exchange.getIn();
    Map<String, Object> headers = in.getHeaders();
    headers.put("foo", 123);
    Message out = new DefaultMessage();
    out.setBody("Bye World");
    out.setHeaders(headers);
    out.copyFrom(in);
    assertEquals(123, headers.get("foo"));
    assertEquals(123, in.getHeader("foo"));
    assertEquals(123, out.getHeader("foo"));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message)

Example 98 with Message

use of org.apache.camel.Message in project camel by apache.

the class PipelineTest method testSendMessageThroughAPipeline.

public void testSendMessageThroughAPipeline() throws Exception {
    resultEndpoint.expectedBodiesReceived(4);
    Exchange results = template.request("direct:a", new Processor() {

        public void process(Exchange exchange) {
            // now lets fire in a message
            Message in = exchange.getIn();
            in.setBody(1);
            in.setHeader("foo", "bar");
        }
    });
    resultEndpoint.assertIsSatisfied();
    assertEquals("Result body", 4, results.getOut().getBody());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message)

Example 99 with Message

use of org.apache.camel.Message in project camel by apache.

the class AggregateGroupMessageTest method testGrouped.

@SuppressWarnings("unchecked")
public void testGrouped() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    template.sendBody("direct:start", "100");
    template.sendBody("direct:start", "150");
    template.sendBody("direct:start", "130");
    template.sendBody("direct:start", "200");
    template.sendBody("direct:start", "190");
    assertMockEndpointsSatisfied();
    Exchange out = result.getExchanges().get(0);
    List<Message> grouped = out.getIn().getBody(List.class);
    assertEquals(5, grouped.size());
    assertEquals("100", grouped.get(0).getBody(String.class));
    assertEquals("150", grouped.get(1).getBody(String.class));
    assertEquals("130", grouped.get(2).getBody(String.class));
    assertEquals("200", grouped.get(3).getBody(String.class));
    assertEquals("190", grouped.get(4).getBody(String.class));
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 100 with Message

use of org.apache.camel.Message in project camel by apache.

the class BeanIOSplitter method evaluate.

public Object evaluate(Exchange exchange) throws Exception {
    Message msg = exchange.getIn();
    Object body = msg.getBody();
    if (factory == null) {
        factory = createStreamFactory(exchange.getContext());
    }
    BeanReader beanReader = null;
    if (body instanceof WrappedFile) {
        body = ((WrappedFile) body).getFile();
    }
    if (body instanceof File) {
        File file = (File) body;
        beanReader = factory.createReader(getStreamName(), file);
    }
    if (beanReader == null) {
        Reader reader = msg.getMandatoryBody(Reader.class);
        beanReader = factory.createReader(getStreamName(), reader);
    }
    BeanIOIterator iterator = new BeanIOIterator(beanReader);
    BeanReaderErrorHandler errorHandler = getOrCreateBeanReaderErrorHandler(configuration, exchange, null, iterator);
    beanReader.setErrorHandler(errorHandler);
    return iterator;
}
Also used : Message(org.apache.camel.Message) BeanIOHelper.getOrCreateBeanReaderErrorHandler(org.apache.camel.dataformat.beanio.BeanIOHelper.getOrCreateBeanReaderErrorHandler) BeanReaderErrorHandler(org.beanio.BeanReaderErrorHandler) WrappedFile(org.apache.camel.WrappedFile) BeanReader(org.beanio.BeanReader) Reader(java.io.Reader) BeanReader(org.beanio.BeanReader) File(java.io.File) WrappedFile(org.apache.camel.WrappedFile)

Aggregations

Message (org.apache.camel.Message)721 Exchange (org.apache.camel.Exchange)341 Test (org.junit.Test)215 Processor (org.apache.camel.Processor)118 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)104 DefaultMessage (org.apache.camel.impl.DefaultMessage)51 DefaultExchange (org.apache.camel.impl.DefaultExchange)44 Endpoint (org.apache.camel.Endpoint)40 Response (javax.ws.rs.core.Response)38 InputStream (java.io.InputStream)36 HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)26 RouteBuilder (org.apache.camel.builder.RouteBuilder)25 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 Map (java.util.Map)24 DataHandler (javax.activation.DataHandler)21 Producer (org.apache.camel.Producer)21 CxfOperationException (org.apache.camel.component.cxf.CxfOperationException)19