Search in sources :

Example 71 with Message

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

the class MessageWithAttachmentRedeliveryIssueTest method testMessageWithAttachmentRedeliveryIssue.

public void testMessageWithAttachmentRedeliveryIssue() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.send("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello World");
            exchange.getIn().addAttachment("message1.xml", new DataHandler(new FileDataSource(new File("src/test/data/message1.xml"))));
            exchange.getIn().addAttachmentObject("message2.xml", new DefaultAttachment(new FileDataSource(new File("src/test/data/message2.xml"))));
        }
    });
    assertMockEndpointsSatisfied();
    Message msg = getMockEndpoint("mock:result").getReceivedExchanges().get(0).getIn();
    assertNotNull(msg);
    assertEquals("Hello World", msg.getBody());
    assertTrue(msg.hasAttachments());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) File(java.io.File)

Example 72 with Message

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

Example 73 with Message

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

the class SimulatorTest method assertRespondsWith.

protected void assertRespondsWith(final String value, String containedText) throws InvalidPayloadException {
    Exchange response = template.request("direct:a", new Processor() {

        public void process(Exchange exchange) throws Exception {
            Message in = exchange.getIn();
            in.setBody("answer");
            in.setHeader("cheese", value);
        }
    });
    assertNotNull("Should receive a response!", response);
    String text = response.getOut().getMandatoryBody(String.class);
    assertStringContains(text, containedText);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) InvalidPayloadException(org.apache.camel.InvalidPayloadException)

Example 74 with Message

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

the class RedeliveryPolicyPerExceptionTest method testUsingCustomExceptionHandlerWithNoRedeliveries.

public void testUsingCustomExceptionHandlerWithNoRedeliveries() throws Exception {
    b.expectedMessageCount(1);
    sendBody("direct:start", "b");
    MockEndpoint.assertIsSatisfied(a, b);
    List<Exchange> list = b.getReceivedExchanges();
    assertTrue("List should not be empty!", !list.isEmpty());
    Exchange exchange = list.get(0);
    Message in = exchange.getIn();
    log.info("Found message with headers: " + in.getHeaders());
    assertMessageHeader(in, Exchange.REDELIVERY_COUNTER, 0);
    assertMessageHeader(in, Exchange.REDELIVERY_MAX_COUNTER, null);
    assertMessageHeader(in, Exchange.REDELIVERED, false);
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message)

Example 75 with Message

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

the class EC2Producer method stopInstances.

private void stopInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    StopInstancesRequest request = new StopInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    StopInstancesResult result;
    try {
        result = ec2Client.stopInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Stop Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : Message(org.apache.camel.Message) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest)

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