use of org.apache.camel.Processor in project camel by apache.
the class ChangeHeaderCaseIssueTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:result").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// change the case of the header
Object value = exchange.getIn().removeHeader("SOAPAction");
exchange.getIn().setHeader("SoapAction", value);
}
});
from("direct:start").to("mock:result");
}
};
}
use of org.apache.camel.Processor in project camel by apache.
the class ExceptionThrownFromOnExceptionTest method testNoExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel.
public void testNoExceptionThrownFromOnExceptionAndHandledWithDeadLetterChannel() throws Exception {
RETRY.set(0);
ON_EXCEPTION_RETRY.set(0);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
// DLC
deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3);
// on exception to catch all IO exceptions and handle them specially
onException(IOException.class).maximumRedeliveries(3).handled(true).to("mock:b").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
ON_EXCEPTION_RETRY.incrementAndGet();
// no exception is thrown this time
}
}).to("mock:c");
from("direct:start").to("direct:intermediate").to("mock:result");
from("direct:intermediate").to("mock:a").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
RETRY.incrementAndGet();
throw new IOException("IO error");
}
}).to("mock:end");
}
});
context.start();
getMockEndpoint("mock:a").expectedMessageCount(1);
getMockEndpoint("mock:b").expectedMessageCount(1);
getMockEndpoint("mock:c").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedMessageCount(0);
// the exception is handled by onException so it goes not in DLC
getMockEndpoint("mock:error").expectedMessageCount(0);
// and this time there was no exception thrown from onException,
// and the exception is handled so the caller should not fail
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals("Should try 4 times (1 first, 3 retry)", 4, RETRY.get());
assertEquals("Should only invoke onException once", 1, ON_EXCEPTION_RETRY.get());
}
use of org.apache.camel.Processor in project camel by apache.
the class AdviceWithTwoRoutesOnExceptionIssueTest method testAdviceWith.
public void testAdviceWith() throws Exception {
context.getRouteDefinition("a").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:a").skipSendToOriginalEndpoint().to("mock:error");
}
});
context.getRouteDefinition("b").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:b").skipSendToOriginalEndpoint().to("mock:error");
}
});
getMockEndpoint("mock:error").whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
throw new IllegalArgumentException("Forced " + body);
}
});
getMockEndpoint("mock:a").expectedMessageCount(0);
getMockEndpoint("mock:b").expectedMessageCount(0);
// whenAnyExchange is invoked after the mock receive the exchange
getMockEndpoint("mock:error").expectedBodiesReceived("A", "B");
// the onException should handle and send the message to this mock
getMockEndpoint("mock:handled").expectedBodiesReceived("Handling Forced A", "Handling Forced B");
Object outA = template.requestBody("direct:a", "A");
assertEquals("Handling Forced A", outA);
Object outB = template.requestBody("direct:b", "B");
assertEquals("Handling Forced B", outB);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Processor in project camel by apache.
the class AdviceWithOnExceptionMultipleIssueTest method testMultipleAdvice.
public void testMultipleAdvice() throws Exception {
context.addRoutes(createRouteBuilder());
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new Exception("my exception");
}
});
}
});
context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(0);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Processor in project camel by apache.
the class AdviceWithOnExceptionMultipleIssueTest method testSimpleMultipleAdvice.
public void testSimpleMultipleAdvice() throws Exception {
context.addRoutes(createRouteBuilder());
context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:resultA").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
}
});
}
});
context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
}
});
context.start();
getMockEndpoint("mock:resultA").expectedMessageCount(1);
template.sendBody("direct:startA", "a trigger");
assertMockEndpointsSatisfied();
}
Aggregations