com.nepxion.discovery.plugin.configcenter.loader.LocalConfigLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-config-center Show documentation
Show all versions of discovery-plugin-config-center Show documentation
Nepxion Discovery is an enhancement for Spring Cloud Discovery
package com.nepxion.discovery.plugin.configcenter.loader;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
public abstract class LocalConfigLoader implements ConfigLoader {
private static final Logger LOG = LoggerFactory.getLogger(LocalConfigLoader.class);
@Autowired
private ApplicationContext applicationContext;
@Override
public String getConfig() throws Exception {
String path = getPath();
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("Config local path isn't set");
}
LOG.info("Config local path is {}", path);
InputStream inputStream = null;
try {
String filePath = applicationContext.getEnvironment().resolvePlaceholders(path);
inputStream = applicationContext.getResource(filePath).getInputStream();
return IOUtils.toString(inputStream, DiscoveryConstant.ENCODING_UTF_8);
} catch (Exception e) {
LOG.warn("File [{}] isn't found or invalid, ignore to load...", path);
return null;
} finally {
if (inputStream != null) {
IOUtils.closeQuietly(inputStream);
}
}
}
protected abstract String getPath();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy