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     */
017    package org.apache.camel.processor;
018    
019    import org.apache.camel.Exchange;
020    import org.apache.camel.Predicate;
021    import org.apache.camel.Processor;
022    import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
023    
024    /**
025     * Implements a <a
026     * href="http://camel.apache.org/dead-letter-channel.html">Dead Letter
027     * Channel</a> after attempting to redeliver the message using the
028     * {@link RedeliveryPolicy}
029     *
030     * @version $Revision: 784803 $
031     */
032    public class DeadLetterChannel extends RedeliveryErrorHandler {
033    
034        /**
035         * Creates the dead letter channel.
036         *
037         * @param output                    outer processor that should use this dead letter channel
038         * @param logger                    logger to use for logging failures and redelivery attempts
039         * @param redeliveryProcessor       an optional processor to run before redelivery attempt
040         * @param redeliveryPolicy          policy for redelivery
041         * @param handledPolicy             policy for handling failed exception that are moved to the dead letter queue
042         * @param exceptionPolicyStrategy   strategy for onException handling
043         * @param deadLetter                the failure processor to send failed exchanges to
044         * @param deadLetterUri             an optional uri for logging purpose
045         * @param useOriginalBodyPolicy     should the original IN body be moved to the dead letter queue or the current exchange IN body?
046         */
047        public DeadLetterChannel(Processor output, Logger logger, Processor redeliveryProcessor, RedeliveryPolicy redeliveryPolicy,
048                                 Predicate handledPolicy, ExceptionPolicyStrategy exceptionPolicyStrategy,
049                                 Processor deadLetter, String deadLetterUri, boolean useOriginalBodyPolicy) {
050            super(output, logger, redeliveryProcessor, redeliveryPolicy, handledPolicy, deadLetter, deadLetterUri, useOriginalBodyPolicy);
051            setExceptionPolicy(exceptionPolicyStrategy);
052        }
053    
054        public void process(Exchange exchange) throws Exception {
055            // just to let the stacktrace reveal that this is a dead letter channel
056            super.process(exchange);
057        }
058    
059        @Override
060        public String toString() {
061            if (output == null) {
062                // if no output then dont do any description
063                return "";
064            }
065            return "DeadLetterChannel[" + output + ", " + (deadLetterUri != null ? deadLetterUri : deadLetter) + "]";
066        }
067    
068    }