Updated Branches: refs/heads/camel-2.11.x 4aeb44a84 -> 3457faa61 refs/heads/camel-2.12.x b347ad0b3 -> 3b8d80d2d refs/heads/master f21e2299b -> d06f3cf90
CAMEL-6689: Polished Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d06f3cf9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d06f3cf9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d06f3cf9 Branch: refs/heads/master Commit: d06f3cf90299fbc270f627aaf88647ca80a17ea7 Parents: f21e229 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Nov 24 09:21:33 2013 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Nov 24 09:21:33 2013 +0100 ---------------------------------------------------------------------- .../org/apache/camel/util/ResourceHelper.java | 45 +++++++++----------- 1 file changed, 21 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d06f3cf9/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 1609918..15ceefc 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 @@ -106,12 +106,7 @@ public final class ResourceHelper { public static InputStream resolveResourceAsInputStream(ClassResolver classResolver, String uri) throws IOException { if (uri.startsWith("file:")) { uri = ObjectHelper.after(uri, "file:"); - try { - // try to decode as the uri may contain %20 for spaces etc - uri = URLDecoder.decode(uri, "UTF-8"); - } catch (Exception e) { - // ignore - } + uri = tryDecodeUri(uri); LOG.trace("Loading resource: {} from file system", uri); return new FileInputStream(uri); } else if (uri.startsWith("http:")) { @@ -130,13 +125,8 @@ public final class ResourceHelper { throw e; } } else if (uri.startsWith("classpath:")) { - try { - // try to decode as the uri may contain %20 for spaces etc - uri = URLDecoder.decode(uri, "UTF-8"); - } catch (Exception e) { - // ignore - } uri = ObjectHelper.after(uri, "classpath:"); + uri = tryDecodeUri(uri); } // load from classpath by default @@ -176,12 +166,7 @@ public final class ResourceHelper { if (uri.startsWith("file:")) { // check if file exists first String name = ObjectHelper.after(uri, "file:"); - try { - // try to decode as the uri may contain %20 for spaces etc - uri = URLDecoder.decode(uri, "UTF-8"); - } catch (Exception e) { - // ignore - } + uri = tryDecodeUri(uri); LOG.trace("Loading resource: {} from file system", uri); File file = new File(name); if (!file.exists()) { @@ -193,12 +178,7 @@ public final class ResourceHelper { return new URL(uri); } else if (uri.startsWith("classpath:")) { uri = ObjectHelper.after(uri, "classpath:"); - try { - // try to decode as the uri may contain %20 for spaces etc - uri = URLDecoder.decode(uri, "UTF-8"); - } catch (Exception e) { - // ignore - } + uri = tryDecodeUri(uri); } // load from classpath by default @@ -254,4 +234,21 @@ public final class ResourceHelper { return FileUtil.compactPath(name, '/'); } + /** + * Tries decoding the uri. + * + * @param uri the uri + * @return the decoded uri, or the original uri + */ + private static String tryDecodeUri(String uri) { + try { + // try to decode as the uri may contain %20 for spaces etc + uri = URLDecoder.decode(uri, "UTF-8"); + } catch (Exception e) { + LOG.trace("Error URL decoding uri using UTF-8 encoding: {}. This exception is ignored.", uri); + // ignore + } + return uri; + } + }