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/f6ed747b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f6ed747b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f6ed747b Branch: refs/heads/camel-2.10.x Commit: f6ed747b2fa3f1a9501c91678e457adde302bec0 Parents: 58d46a7 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:45:46 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/f6ed747b/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, '/'); + } + }