use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.
the class XmlErrorHandlerFactoryBean method setProperties.
private void setProperties(DefaultErrorHandlerBuilder builder) throws Exception {
if (nonNull(handler.getDeadLetterHandleNewException())) {
builder.setDeadLetterHandleNewException(handler.getDeadLetterHandleNewException());
}
builder.setDeadLetterUri(handler.getDeadLetterUri());
builder.setExecutorServiceRef(handler.getExecutorServiceRef());
builder.setRetryWhileRef(handler.getRetryWhileRef());
if (nonNull(handler.getUseOriginalMessage())) {
builder.setUseOriginalMessage(handler.getUseOriginalMessage());
}
if (isNotEmpty(handler.getOnExceptionOccurredRef())) {
Processor processor = getReferenceByName(manager, handler.getOnExceptionOccurredRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onExceptionOccurredRef")));
builder.setOnExceptionOccurred(processor);
}
if (isNotEmpty(handler.getOnPrepareFailureRef())) {
Processor processor = getReferenceByName(manager, handler.getOnPrepareFailureRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onPrepareFailureRef")));
builder.setOnPrepareFailure(processor);
}
if (isNotEmpty(handler.getOnRedeliveryRef())) {
Processor processor = getReferenceByName(manager, handler.getOnRedeliveryRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onRedeliveryRef")));
builder.setOnRedelivery(processor);
}
if (nonNull(handler.getRedeliveryPolicy())) {
RedeliveryPolicyFactoryBean policy = handler.getRedeliveryPolicy();
policy.setBeanManager(manager);
builder.setRedeliveryPolicy(policy.getObject());
}
if (isNotEmpty(handler.getRedeliveryPolicyRef())) {
RedeliveryPolicy policy = getReferenceByName(manager, handler.getRedeliveryPolicyRef(), RedeliveryPolicy.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getRedeliveryPolicyRef(), "redeliveryPolicyRef")));
builder.setRedeliveryPolicy(policy);
}
}
use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.
the class AbstractCamelRedeliveryPolicyFactoryBean method getObject.
public RedeliveryPolicy getObject() throws Exception {
RedeliveryPolicy answer = new RedeliveryPolicy();
CamelContext context = getCamelContext();
// copy across the properties - if they are set
if (maximumRedeliveries != null) {
answer.setMaximumRedeliveries(CamelContextHelper.parseInteger(context, maximumRedeliveries));
}
if (redeliveryDelay != null) {
answer.setRedeliveryDelay(CamelContextHelper.parseLong(context, redeliveryDelay));
}
if (asyncDelayedRedelivery != null) {
if (CamelContextHelper.parseBoolean(context, asyncDelayedRedelivery)) {
answer.asyncDelayedRedelivery();
}
}
if (retriesExhaustedLogLevel != null) {
answer.setRetriesExhaustedLogLevel(retriesExhaustedLogLevel);
}
if (retryAttemptedLogLevel != null) {
answer.setRetryAttemptedLogLevel(retryAttemptedLogLevel);
}
if (backOffMultiplier != null) {
answer.setBackOffMultiplier(CamelContextHelper.parseDouble(context, backOffMultiplier));
}
if (useExponentialBackOff != null) {
answer.setUseExponentialBackOff(CamelContextHelper.parseBoolean(context, useExponentialBackOff));
}
if (collisionAvoidanceFactor != null) {
answer.setCollisionAvoidanceFactor(CamelContextHelper.parseDouble(context, collisionAvoidanceFactor));
}
if (useCollisionAvoidance != null) {
answer.setUseCollisionAvoidance(CamelContextHelper.parseBoolean(context, useCollisionAvoidance));
}
if (maximumRedeliveryDelay != null) {
answer.setMaximumRedeliveryDelay(CamelContextHelper.parseLong(context, maximumRedeliveryDelay));
}
if (logStackTrace != null) {
answer.setLogStackTrace(CamelContextHelper.parseBoolean(context, logStackTrace));
}
if (logRetryStackTrace != null) {
answer.setLogRetryStackTrace(CamelContextHelper.parseBoolean(context, logRetryStackTrace));
}
if (logHandled != null) {
answer.setLogHandled(CamelContextHelper.parseBoolean(context, logHandled));
}
if (logContinued != null) {
answer.setLogContinued(CamelContextHelper.parseBoolean(context, logContinued));
}
if (logRetryAttempted != null) {
answer.setLogRetryAttempted(CamelContextHelper.parseBoolean(context, logRetryAttempted));
}
if (logExhausted != null) {
answer.setLogExhausted(CamelContextHelper.parseBoolean(context, logExhausted));
}
if (logExhaustedMessageHistory != null) {
answer.setLogExhaustedMessageHistory(CamelContextHelper.parseBoolean(context, logExhaustedMessageHistory));
}
if (disableRedelivery != null) {
if (CamelContextHelper.parseBoolean(context, disableRedelivery)) {
answer.setMaximumRedeliveries(0);
}
}
if (delayPattern != null) {
answer.setDelayPattern(CamelContextHelper.parseText(context, delayPattern));
}
if (allowRedeliveryWhileStopping != null) {
answer.setAllowRedeliveryWhileStopping(CamelContextHelper.parseBoolean(context, allowRedeliveryWhileStopping));
}
if (exchangeFormatterRef != null) {
answer.setExchangeFormatterRef(exchangeFormatterRef);
}
return answer;
}
use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.
the class ContextErrorHandlerTest method setUp.
protected void setUp() throws Exception {
setUseRouteBuilder(false);
super.setUp();
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.maximumRedeliveries(1);
redeliveryPolicy.setUseExponentialBackOff(true);
DeadLetterChannelBuilder deadLetterChannelBuilder = new DeadLetterChannelBuilder("mock:error");
deadLetterChannelBuilder.setRedeliveryPolicy(redeliveryPolicy);
context.setErrorHandlerBuilder(deadLetterChannelBuilder);
}
use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.
the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.
public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").to("seda:b");
from("direct:c").to("direct:d");
}
};
List<Route> list = getRouteListWithCurrentContext(builder);
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.
the class ErrorHandlerDefinitionParserTest method testDefaultErrorHandler.
public void testDefaultErrorHandler() {
DefaultErrorHandlerBuilder errorHandler = ctx.getBean("defaultErrorHandler", DefaultErrorHandlerBuilder.class);
assertNotNull(errorHandler);
RedeliveryPolicy policy = errorHandler.getRedeliveryPolicy();
assertNotNull(policy);
assertEquals("Wrong maximumRedeliveries", 2, policy.getMaximumRedeliveries());
assertEquals("Wrong redeliveryDelay", 0, policy.getRedeliveryDelay());
assertEquals("Wrong logStackTrace", false, policy.isLogStackTrace());
errorHandler = ctx.getBean("errorHandler", DefaultErrorHandlerBuilder.class);
assertNotNull(errorHandler);
}
Aggregations