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.management.event;
018
019import org.apache.camel.Exchange;
020import org.apache.camel.Processor;
021import org.apache.camel.util.URISupport;
022
023/**
024 * @version 
025 */
026public class ExchangeFailureHandlingEvent extends AbstractExchangeEvent {
027    private static final long serialVersionUID = -7554809462006009549L;
028
029    private final transient Processor failureHandler;
030    private final boolean deadLetterChannel;
031    private final String deadLetterUri;
032
033    public ExchangeFailureHandlingEvent(Exchange source, Processor failureHandler, boolean deadLetterChannel, String deadLetterUri) {
034        super(source);
035        this.failureHandler = failureHandler;
036        this.deadLetterChannel = deadLetterChannel;
037        this.deadLetterUri = deadLetterUri;
038    }
039
040    public Processor getFailureHandler() {
041        return failureHandler;
042    }
043
044    public boolean isDeadLetterChannel() {
045        return deadLetterChannel;
046    }
047
048    public String getDeadLetterUri() {
049        return deadLetterUri;
050    }
051
052    @Override
053    public String toString() {
054        if (isDeadLetterChannel()) {
055            String uri = URISupport.sanitizeUri(deadLetterUri);
056            return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but is being handled by dead letter channel: " + uri;
057        } else {
058            return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but is being processed by failure processor: " + failureHandler;
059        }
060    }
061}