Author: ningjiang
Date: Mon Mar 25 02:43:45 2013
New Revision: 1460514
URL: http://svn.apache.org/r1460514
Log:
CAMEL-6204 fixed the issue that ObjectHelper cannot loadResources with leading /
Added:
camel/trunk/camel-core/src/test/resources/org/apache/camel/util/ObjectHelperResourceTestFile.properties
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=1460514&r1=1460513&r2=1460514&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Mon Mar 25 02:43:45 2013
@@ -57,6 +57,7 @@ import org.apache.camel.WrappedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
* A number of useful helper methods for working with Objects
*
@@ -891,6 +892,9 @@ public final class ObjectHelper {
if (in == null) {
in =
ObjectHelper.class.getClassLoader().getResourceAsStream(resolvedName);
}
+ if (in == null) {
+ in = ObjectHelper.class.getResourceAsStream(resolvedName);
+ }
return in;
}
@@ -913,6 +917,9 @@ public final class ObjectHelper {
if (url == null) {
url =
ObjectHelper.class.getClassLoader().getResource(resolvedName);
}
+ if (url == null) {
+ url = ObjectHelper.class.getResource(resolvedName);
+ }
return url;
}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java?rev=1460514&r1=1460513&r2=1460514&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
Mon Mar 25 02:43:45 2013
@@ -16,7 +16,9 @@
*/
package org.apache.camel.util;
+import java.io.InputStream;
import java.lang.reflect.Method;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -38,11 +40,28 @@ import org.apache.camel.component.bean.M
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultMessage;
+
/**
* @version
*/
public class ObjectHelperTest extends TestCase {
+ public void testLoadResourceAsStream() {
+ InputStream res1 =
ObjectHelper.loadResourceAsStream("org/apache/camel/util/ObjectHelperResourceTestFile.properties");
+ InputStream res2 =
ObjectHelper.loadResourceAsStream("/org/apache/camel/util/ObjectHelperResourceTestFile.properties");
+
+ assertNotNull("Cannot load resource without leading \"/\"", res1);
+ assertNotNull("Cannot load resource with leading \"/\"", res2);
+ }
+
+ public void testLoadResource() {
+ URL url1 =
ObjectHelper.loadResourceAsURL("org/apache/camel/util/ObjectHelperResourceTestFile.properties");
+ URL url2 =
ObjectHelper.loadResourceAsURL("/org/apache/camel/util/ObjectHelperResourceTestFile.properties");
+
+ assertNotNull("Cannot load resource without leading \"/\"", url1);
+ assertNotNull("Cannot load resource with leading \"/\"", url2);
+ }
+
public void testRemoveInitialCharacters() throws Exception {
assertEquals(ObjectHelper.removeStartingCharacters("foo", '/'), "foo");
assertEquals(ObjectHelper.removeStartingCharacters("/foo", '/'),
"foo");
Added:
camel/trunk/camel-core/src/test/resources/org/apache/camel/util/ObjectHelperResourceTestFile.properties
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/util/ObjectHelperResourceTestFile.properties?rev=1460514&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/resources/org/apache/camel/util/ObjectHelperResourceTestFile.properties
(added)
+++
camel/trunk/camel-core/src/test/resources/org/apache/camel/util/ObjectHelperResourceTestFile.properties
Mon Mar 25 02:43:45 2013
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+filterParameters.include=include
+filterParameters.exclude=exclude