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