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; 018 019import org.apache.camel.util.URISupport; 020 021/** 022 * Exception when failing to create a {@link org.apache.camel.Route}. 023 * 024 * @version 025 */ 026public class FailedToCreateRouteException extends CamelException { 027 private static final long serialVersionUID = 1L; 028 private final String routeId; 029 030 public FailedToCreateRouteException(String routeId, String route, Throwable cause) { 031 super("Failed to create route " + routeId + ": " + getRouteMessage(route) + " because of " + getExceptionMessage(cause), cause); 032 this.routeId = routeId; 033 } 034 035 public FailedToCreateRouteException(String routeId, String route, String at, Throwable cause) { 036 super("Failed to create route " + routeId + " at: >>> " + at + " <<< in route: " + getRouteMessage(route) + " because of " + cause.getMessage(), cause); 037 this.routeId = routeId; 038 } 039 040 public String getRouteId() { 041 return routeId; 042 } 043 044 protected static String getExceptionMessage(Throwable cause) { 045 if (cause.getMessage() != null) { 046 return cause.getMessage(); 047 } else { 048 return cause.getClass().getSimpleName(); 049 } 050 } 051 052 protected static String getRouteMessage(String route) { 053 // ensure to sanitize uri's in the route so we do not show sensitive information such as passwords 054 route = URISupport.sanitizeUri(route); 055 056 // cut the route after 60 chars so it won't be too big in the message 057 // users just need to be able to identify the route so they know where to look 058 if (route.length() > 60) { 059 return route.substring(0, 60) + "..."; 060 } else { 061 return route; 062 } 063 } 064}