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 ExchangeFailureHandledEvent extends AbstractExchangeEvent {
027    private static final long serialVersionUID = -7554809462006009548L;
028
029    private final transient Processor failureHandler;
030    private final boolean deadLetterChannel;
031    private final String deadLetterUri;
032    private final boolean handled;
033
034    public ExchangeFailureHandledEvent(Exchange source, Processor failureHandler, boolean deadLetterChannel, String deadLetterUri) {
035        super(source);
036        this.failureHandler = failureHandler;
037        this.deadLetterChannel = deadLetterChannel;
038        this.deadLetterUri = deadLetterUri;
039        this.handled = source.getProperty(Exchange.ERRORHANDLER_HANDLED, false, Boolean.class);
040    }
041
042    public Processor getFailureHandler() {
043        return failureHandler;
044    }
045
046    public boolean isDeadLetterChannel() {
047        return deadLetterChannel;
048    }
049
050    public String getDeadLetterUri() {
051        return deadLetterUri;
052    }
053
054    public boolean isHandled() {
055        return handled;
056    }
057
058    public boolean isContinued() {
059        return !handled;
060    }
061
062    @Override
063    public String toString() {
064        if (isDeadLetterChannel()) {
065            String uri = URISupport.sanitizeUri(deadLetterUri);
066            return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was handled by dead letter channel: " + uri;
067        } else {
068            return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was processed by failure processor: " + failureHandler;
069        }
070    }
071}