Repository: camel Updated Branches: refs/heads/camel-2.18.x dc46e915d -> b7b660d00
CAMEL-10983: Fail early and show meaningful log for invalid endpoint URI in Blueprint Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b7b660d0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7b660d0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7b660d0 Branch: refs/heads/camel-2.18.x Commit: b7b660d009497cf54666f5f005460fd9dc8d193b Parents: dc46e91 Author: Tadayoshi Sato <sato.tadayo...@gmail.com> Authored: Fri Mar 10 22:05:12 2017 +0900 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Mar 10 21:49:50 2017 +0100 ---------------------------------------------------------------------- .../handler/CamelNamespaceHandler.java | 37 ++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b7b660d0/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java index 321b163..ab41dc6 100644 --- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java @@ -16,6 +16,7 @@ */ package org.apache.camel.blueprint.handler; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -988,9 +989,9 @@ public class CamelNamespaceHandler implements NamespaceHandler { CamelContextFactoryBean ccfb = (CamelContextFactoryBean) blueprintContainer.getComponentInstance(".camelBlueprint.factory." + camelContextName); CamelContext camelContext = ccfb.getContext(); - Set<String> components = new HashSet<String>(); - Set<String> languages = new HashSet<String>(); - Set<String> dataformats = new HashSet<String>(); + Set<String> components = new HashSet<>(); + Set<String> languages = new HashSet<>(); + Set<String> dataformats = new HashSet<>(); // regular camel routes for (RouteDefinition rd : camelContext.getRouteDefinitions()) { @@ -1152,16 +1153,20 @@ public class CamelNamespaceHandler implements NamespaceHandler { private void findUriComponent(String uri, Set<String> components) { // if the uri is a placeholder then skip it - if (uri != null && uri.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { + if (uri == null || uri.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { return; } - if (uri != null) { - String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2); - if (splitURI[1] != null) { - String scheme = splitURI[0]; - components.add(scheme); - } + // validate uri here up-front so a meaningful error can be logged for blueprint + // it will also speed up tests in case of failure + if (!validateUri(uri)) { + return; + } + + String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2); + if (splitURI[1] != null) { + String scheme = splitURI[0]; + components.add(scheme); } } @@ -1187,11 +1192,21 @@ public class CamelNamespaceHandler implements NamespaceHandler { } } } catch (URISyntaxException e) { - // ignore + // ignore as uri should be already validated at findUriComponent method } } } + private static boolean validateUri(String uri) { + try { + // the same validation as done in DefaultCamelContext#normalizeEndpointUri(String) + URISupport.normalizeUri(uri); + } catch (URISyntaxException | UnsupportedEncodingException e) { + LOG.error("Endpoint URI '" + uri + "' is not valid due to: " + e.getMessage(), e); + return false; + } + return true; + } } }