Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class CacheComponent extends DefaultComponent {
private CacheConfiguration configuration;
private CacheManagerFactory cacheManagerFactory;
private String configurationFile = "classpath:ehcache.xml";
private String configurationFile;

public CacheComponent() {
configuration = new CacheConfiguration();
Expand Down Expand Up @@ -99,7 +99,7 @@ protected void doStart() throws Exception {
if (configurationFile != null) {
is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), configurationFile);
}
cacheManagerFactory = new DefaultCacheManagerFactory(is);
cacheManagerFactory = new DefaultCacheManagerFactory(is, configurationFile);
}
ServiceHelper.startService(cacheManagerFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,36 @@
import java.io.InputStream;

import net.sf.ehcache.CacheManager;

import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.IOHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultCacheManagerFactory extends CacheManagerFactory {
private static final Logger LOG = LoggerFactory.getLogger(DefaultCacheManagerFactory.class);

private InputStream is;

private String configurationFile;

public DefaultCacheManagerFactory() {
this(null);
this(null, null);
}

public DefaultCacheManagerFactory(InputStream is) {
public DefaultCacheManagerFactory(InputStream is, String configurationFile) {
this.is = is;
this.configurationFile = configurationFile;
}

@Override
protected CacheManager createCacheManagerInstance() {
if (is == null) {
is = getClass().getResourceAsStream("/ehcache.xml");
// it will still look for "/ehcache.xml" before defaulting to "/ehcache-failsafe.xml"
LOG.info("Creating CacheManager using Ehcache defaults");
return EHCacheUtil.createCacheManager();
}
LOG.info("Creating CacheManager using camel-cache configuration: {}", configurationFile);
return EHCacheUtil.createCacheManager(is);
}

Expand Down
Loading