Search in sources :

Example 46 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ValidatorRouteTest method testEndpointValidator.

public void testEndpointValidator() throws Exception {
    Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
    exchange.getIn().setBody("<XOrder/>");
    Exchange answerEx = template.send("direct:endpoint", exchange);
    if (answerEx.getException() != null) {
        throw answerEx.getException();
    }
    assertEquals("<XOrderResponse/>", answerEx.getOut().getBody(String.class));
    assertEquals(MyXmlEndpoint.class, answerEx.getProperty(VALIDATOR_INVOKED));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange)

Example 47 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class ValidatorRouteTest method testCustomValidator.

public void testCustomValidator() throws Exception {
    Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
    exchange.getIn().setBody("name=XOrder");
    Exchange answerEx = template.send("direct:custom", exchange);
    if (answerEx.getException() != null) {
        throw answerEx.getException();
    }
    assertEquals("name=XOrderResponse", answerEx.getOut().getBody(String.class));
    assertEquals(OtherXOrderResponseValidator.class, answerEx.getProperty(VALIDATOR_INVOKED));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange)

Example 48 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange 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 49 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutExpressionRestart.

public void testAggregateProcessorTimeoutExpressionRestart() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A+B");
    mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
    Processor done = new SendProcessor(context.getEndpoint("mock:result"));
    Expression corr = header("id");
    AggregationStrategy as = new BodyInAggregatingStrategy();
    AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
    // start with a high timeout so no completes before we stop
    ap.setCompletionTimeoutExpression(header("myTimeout"));
    ap.start();
    Exchange e1 = new DefaultExchange(context);
    e1.getIn().setBody("A");
    e1.getIn().setHeader("id", 123);
    e1.getIn().setHeader("myTimeout", 2000);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    e2.getIn().setHeader("id", 123);
    e2.getIn().setHeader("myTimeout", 2000);
    ap.process(e1);
    ap.process(e2);
    // shutdown before the 2 sec timeout occurs
    // however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
    ap.stop();
    // should be no completed
    assertEquals(0, mock.getReceivedCounter());
    // start aggregator again
    ap.start();
    // the aggregator should restore the timeout condition and trigger timeout
    assertMockEndpointsSatisfied();
    assertEquals(1, mock.getReceivedCounter());
    ap.shutdown();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Example 50 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutRestart.

public void testAggregateProcessorTimeoutRestart() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A+B");
    mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
    Processor done = new SendProcessor(context.getEndpoint("mock:result"));
    Expression corr = header("id");
    AggregationStrategy as = new BodyInAggregatingStrategy();
    AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
    // start with a high timeout so no completes before we stop
    ap.setCompletionTimeout(2000);
    ap.start();
    Exchange e1 = new DefaultExchange(context);
    e1.getIn().setBody("A");
    e1.getIn().setHeader("id", 123);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    e2.getIn().setHeader("id", 123);
    ap.process(e1);
    ap.process(e2);
    // shutdown before the 2 sec timeout occurs
    // however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
    ap.stop();
    // should be no completed
    assertEquals(0, mock.getReceivedCounter());
    // start aggregator again
    ap.start();
    // the aggregator should restore the timeout condition and trigger timeout
    assertMockEndpointsSatisfied();
    assertEquals(1, mock.getReceivedCounter());
    ap.shutdown();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Aggregations

DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Exchange (org.apache.camel.Exchange)381 Test (org.junit.Test)254 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)127 CamelContext (org.apache.camel.CamelContext)54 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 HashMap (java.util.HashMap)33 Message (org.apache.camel.Message)32 Before (org.junit.Before)32 Tx (org.nhindirect.common.tx.model.Tx)31 ESMClass (org.jsmpp.bean.ESMClass)30 Processor (org.apache.camel.Processor)22 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)22 Expression (org.apache.camel.Expression)21 File (java.io.File)20 DefaultMessage (org.apache.camel.impl.DefaultMessage)20 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 URL (java.net.URL)16 Date (java.util.Date)16