CAMEL-6572: Fixed validator component to load reosurces from classpath with relative paths in OSGi.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/353abe0e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/353abe0e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/353abe0e Branch: refs/heads/master Commit: 353abe0ec7dde5491c15c3bc46e9da0daf546222 Parents: 8b298b4 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 24 15:43:36 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 24 15:43:36 2013 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/util/ResourceHelper.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/353abe0e/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java b/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java index a7717af..b301abe 100644 --- a/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java @@ -101,7 +101,8 @@ public final class ResourceHelper { } // load from classpath by default - InputStream is = classResolver.loadResourceAsStream(uri); + String resolvedName = resolveUriPath(uri); + InputStream is = classResolver.loadResourceAsStream(resolvedName); if (is == null) { throw new FileNotFoundException("Cannot find resource in classpath for URI: " + uri); } else { @@ -175,4 +176,18 @@ public final class ResourceHelper { return uri; } } + + /** + * Helper operation used to remove relative path notation from + * resources. Most critical for resources on the Classpath + * as resource loaders will not resolve the relative paths correctly. + * + * @param name the name of the resource to load + * @return the modified or unmodified string if there were no changes + */ + private static String resolveUriPath(String name) { + // compact the path and use / as separator as that's used for loading resources on the classpath + return FileUtil.compactPath(name, '/'); + } + }