[
https://issues.apache.org/jira/browse/CAMEL-5940?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13612214#comment-13612214
]
Piotr Klimczak commented on CAMEL-5940:
---------------------------------------
Hi Henryk,
It seems that in your last example you've hitted same "issue" as me- yesterday.
The ResourceHelper in resolveMandatoryResourceAsInputStream method uses
CamelContext's classResolver which is DefaultClassResolver (in junit test
cases).
Then the DefaultClassResolver in loadResourceAsStream method is using
ObjectHelper's loadResourceAsStream method.
The loadResourceAsStream method has a body as shown below:
{body}
/**
* Attempts to load the given resource as a stream using the thread context
* class loader or the class loader used to load this class
*
* @param name the name of the resource to load
* @return the stream or null if it could not be loaded
*/
public static InputStream loadResourceAsStream(String name) {
InputStream in = null;
String resolvedName = resolveUriPath(name);
ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
in = contextClassLoader.getResourceAsStream(resolvedName);
}
if (in == null) {
in =
ObjectHelper.class.getClassLoader().getResourceAsStream(resolvedName);
}
return in;
}
{body}
In your example (whis is same I've tried yesterday) the problem is with:
{code}
"classpath:/com/my/app/ehcache/config.xml"
{code}
Your example resource would be never found because it has the leading "/".
This code
{code}
getClassLoader().getResourceAsStream(resolvedName)
{code}
expects the resolvedName to be without leading "/".
If provided, then it fails.
It works much different than:
{code}
getClass().getResourceAsStream(resolvedName)
{code}
> camel-cache - Add option to cache component to easily configure ehcache XML
> file to load by default
> ---------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5940
> URL: https://issues.apache.org/jira/browse/CAMEL-5940
> Project: Camel
> Issue Type: Improvement
> Components: camel-cache
> Reporter: Claus Ibsen
> Fix For: 2.11.1
>
>
> See
> By default ehache.xml is loaded from classpath. We should make it possible to
> configure CacheComponent with a string option that refers to the resource to
> load.
> Then people can do something a like:
> {code}
> <bean id="cache" class="...CacheComponent">
> <property name="configurationFile" value="classpath:com/foo/mycache.xml"/>
> </bean>
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira