001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.processor; 018 019import java.util.concurrent.ScheduledExecutorService; 020 021import org.apache.camel.CamelContext; 022import org.apache.camel.Exchange; 023import org.apache.camel.Predicate; 024import org.apache.camel.Processor; 025import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy; 026import org.apache.camel.util.CamelLogger; 027 028/** 029 * Default error handler 030 * 031 * @version 032 */ 033public class DefaultErrorHandler extends RedeliveryErrorHandler { 034 035 /** 036 * Creates the default error handler. 037 * 038 * @param camelContext the camel context 039 * @param output outer processor that should use this default error handler 040 * @param logger logger to use for logging failures and redelivery attempts 041 * @param redeliveryProcessor an optional processor to run before redelivery attempt 042 * @param redeliveryPolicy policy for redelivery 043 * @param exceptionPolicyStrategy strategy for onException handling 044 * @param retryWhile retry while 045 * @param executorService the {@link java.util.concurrent.ScheduledExecutorService} to be used for redelivery thread pool. Can be <tt>null</tt>. 046 * @param onPrepareProcessor a custom {@link org.apache.camel.Processor} to prepare the {@link org.apache.camel.Exchange} before 047 * handled by the failure processor / dead letter channel. 048 * @param onExceptionOccurredProcessor a custom {@link org.apache.camel.Processor} to process the {@link org.apache.camel.Exchange} just after an exception was thrown. 049 */ 050 public DefaultErrorHandler(CamelContext camelContext, Processor output, CamelLogger logger, Processor redeliveryProcessor, 051 RedeliveryPolicy redeliveryPolicy, ExceptionPolicyStrategy exceptionPolicyStrategy, Predicate retryWhile, 052 ScheduledExecutorService executorService, Processor onPrepareProcessor, Processor onExceptionOccurredProcessor) { 053 054 super(camelContext, output, logger, redeliveryProcessor, redeliveryPolicy, null, null, true, false, retryWhile, executorService, onPrepareProcessor, onExceptionOccurredProcessor); 055 setExceptionPolicy(exceptionPolicyStrategy); 056 } 057 058 public void process(Exchange exchange) throws Exception { 059 // just to let the stacktrace reveal that this is a dead letter channel 060 super.process(exchange); 061 } 062 063 @Override 064 public String toString() { 065 if (output == null) { 066 // if no output then dont do any description 067 return ""; 068 } 069 return "DefaultErrorHandler[" + output + "]"; 070 } 071 072}