You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/07/25 08:44:58 UTC
git commit: CAMEL-6572: Added some loggin in resource helper.
Updated Branches:
refs/heads/master 10b08ab05 -> 5763c7998
CAMEL-6572: Added some loggin in resource helper.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5763c799
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5763c799
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5763c799
Branch: refs/heads/master
Commit: 5763c7998e036992a956faaf43c219bd44033bb6
Parents: 10b08ab
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 25 08:03:03 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 25 08:03:14 2013 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/util/ResourceHelper.java | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5763c799/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 b301abe..ccdf0bf 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
@@ -30,12 +30,16 @@ import java.net.URLConnection;
import java.util.Map;
import org.apache.camel.spi.ClassResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Helper class for loading resources on the classpath or file system.
*/
public final class ResourceHelper {
+ private static final transient Logger LOG = LoggerFactory.getLogger(ResourceHelper.class);
+
private ResourceHelper() {
// utility class
}
@@ -81,9 +85,11 @@ public final class ResourceHelper {
public static InputStream resolveMandatoryResourceAsInputStream(ClassResolver classResolver, String uri) throws IOException {
if (uri.startsWith("file:")) {
uri = ObjectHelper.after(uri, "file:");
+ LOG.trace("Loading resource: {} from file system", uri);
return new FileInputStream(uri);
} else if (uri.startsWith("http:")) {
URL url = new URL(uri);
+ LOG.trace("Loading resource: {} from HTTP", uri);
URLConnection con = url.openConnection();
con.setUseCaches(false);
try {
@@ -102,9 +108,10 @@ public final class ResourceHelper {
// load from classpath by default
String resolvedName = resolveUriPath(uri);
+ LOG.trace("Loading resource: {} from classpath", resolvedName);
InputStream is = classResolver.loadResourceAsStream(resolvedName);
if (is == null) {
- throw new FileNotFoundException("Cannot find resource in classpath for URI: " + uri);
+ throw new FileNotFoundException("Cannot find resource: " + resolvedName + " in classpath for URI: " + uri);
} else {
return is;
}
@@ -123,21 +130,25 @@ public final class ResourceHelper {
if (uri.startsWith("file:")) {
// check if file exists first
String name = ObjectHelper.after(uri, "file:");
+ LOG.trace("Loading resource: {} from file system", uri);
File file = new File(name);
if (!file.exists()) {
throw new FileNotFoundException("File " + file + " not found");
}
return new URL(uri);
} else if (uri.startsWith("http:")) {
+ LOG.trace("Loading resource: {} from HTTP", uri);
return new URL(uri);
} else if (uri.startsWith("classpath:")) {
uri = ObjectHelper.after(uri, "classpath:");
}
// load from classpath by default
- URL url = classResolver.loadResourceAsURL(uri);
+ String resolvedName = resolveUriPath(uri);
+ LOG.trace("Loading resource: {} from classpath", resolvedName);
+ URL url = classResolver.loadResourceAsURL(resolvedName);
if (url == null) {
- throw new FileNotFoundException("Cannot find resource in classpath for URI: " + uri);
+ throw new FileNotFoundException("Cannot find resource: " + resolvedName + " in classpath for URI: " + uri);
} else {
return url;
}