in core/camel-api/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java [115:265]
public String summaryErrorMessage(boolean includeHeader, boolean ignoreDeprecated, boolean includeWarnings) {
boolean ok = isSuccess();
// special check if we should ignore deprecated options being used
if (ok && !ignoreDeprecated) {
ok = deprecated == null;
}
if (includeWarnings) {
if (incapable != null) {
return "\tIncapable of parsing uri: " + incapable;
} else if (syntaxError != null) {
return "\tSyntax error: " + syntaxError;
} else if (unknownComponent != null) {
return "\tUnknown component: " + unknownComponent;
}
}
if (ok) {
return null;
}
// for each invalid option build a reason message
Map<String, String> options = new LinkedHashMap<>();
if (unknown != null) {
for (String name : unknown) {
if (unknownSuggestions != null && unknownSuggestions.containsKey(name)) {
String[] suggestions = unknownSuggestions.get(name);
if (suggestions != null && suggestions.length > 0) {
String str = Arrays.asList(suggestions).toString();
options.put(name, "Unknown option. Did you mean: " + str);
} else {
options.put(name, "Unknown option");
}
} else {
options.put(name, "Unknown option");
}
}
}
if (notConsumerOnly != null) {
for (String name : notConsumerOnly) {
options.put(name, "Option not applicable in consumer only mode");
}
}
if (notProducerOnly != null) {
for (String name : notProducerOnly) {
options.put(name, "Option not applicable in producer only mode");
}
}
if (required != null) {
for (String name : required) {
options.put(name, "Missing required option");
}
}
if (deprecated != null) {
for (String name : deprecated) {
options.put(name, "Deprecated option");
}
}
if (invalidEnum != null) {
for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
String name = entry.getKey();
String[] choices = invalidEnumChoices.get(name);
String defaultValue = defaultValues != null ? defaultValues.get(entry.getKey()) : null;
String str = Arrays.asList(choices).toString();
String msg = "Invalid enum value: " + entry.getValue() + ". Possible values: " + str;
if (invalidEnumSuggestions != null) {
String[] suggestions = invalidEnumSuggestions.get(name);
if (suggestions != null && suggestions.length > 0) {
str = Arrays.asList(suggestions).toString();
msg += ". Did you mean: " + str;
}
}
if (defaultValue != null) {
msg += ". Default value: " + defaultValue;
}
options.put(entry.getKey(), msg);
}
}
if (invalidReference != null) {
for (Map.Entry<String, String> entry : invalidReference.entrySet()) {
boolean empty = isEmpty(entry.getValue());
if (empty) {
options.put(entry.getKey(), "Empty reference value");
} else if (!entry.getValue().startsWith("#")) {
options.put(entry.getKey(), "Invalid reference value: " + entry.getValue() + " must start with #");
} else {
options.put(entry.getKey(), "Invalid reference value: " + entry.getValue());
}
}
}
if (invalidBoolean != null) {
for (Map.Entry<String, String> entry : invalidBoolean.entrySet()) {
boolean empty = isEmpty(entry.getValue());
if (empty) {
options.put(entry.getKey(), "Empty boolean value");
} else {
options.put(entry.getKey(), "Invalid boolean value: " + entry.getValue());
}
}
}
if (invalidInteger != null) {
for (Map.Entry<String, String> entry : invalidInteger.entrySet()) {
boolean empty = isEmpty(entry.getValue());
if (empty) {
options.put(entry.getKey(), "Empty integer value");
} else {
options.put(entry.getKey(), "Invalid integer value: " + entry.getValue());
}
}
}
if (invalidNumber != null) {
for (Map.Entry<String, String> entry : invalidNumber.entrySet()) {
boolean empty = isEmpty(entry.getValue());
if (empty) {
options.put(entry.getKey(), "Empty number value");
} else {
options.put(entry.getKey(), "Invalid number value: " + entry.getValue());
}
}
}
// build a table with the error summary nicely formatted
// lets use 24 as min length
int maxLen = 24;
for (String key : options.keySet()) {
maxLen = Math.max(maxLen, key.length());
}
String format = "%" + maxLen + "s %s";
// build the human error summary
StringBuilder sb = new StringBuilder(512);
if (includeHeader) {
sb.append("Endpoint validator error\n");
sb.append(
"---------------------------------------------------------------------------------------------------------------------------------------\n");
sb.append("\n");
}
if (uri != null) {
sb.append("\t").append(uri).append("\n");
} else {
sb.append("\n");
}
for (Map.Entry<String, String> option : options.entrySet()) {
String out = String.format(format, option.getKey(), option.getValue());
sb.append("\n\t").append(out);
}
return sb.toString();
}