Skip to content

Instantly share code, notes, and snippets.

@gbutt
Created May 16, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbutt/eeb5fc06b54d922517f6 to your computer and use it in GitHub Desktop.
Save gbutt/eeb5fc06b54d922517f6 to your computer and use it in GitHub Desktop.
configloader
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.example.configloader">
<cm:default-properties>
<cm:property name="configPath" value=""/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="configLoader" class="com.example.ConfigLoader" init-method="init">
<property name="configPath" value="${configPath}" />
</bean>
</blueprint>
configPath=profile:config.json
[
{
active: true
}
]
package com.example;
import org.apache.commons.lang.NullArgumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ConfigLoader {
private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class);
private String configPath;
public String getConfigPath() {
return configPath;
}
public void setConfigPath(String value) {
configPath = value;
}
private File configFile;
public File getConfigFile() {
return configFile;
}
public void setConfigFile(File value) {
configFile = value;
}
public void init() throws FileNotFoundException, IOException {
if (configPath == null) {
throw new NullArgumentException("configPath");
}
File file = new File(configPath);
setConfigFile(file);
log.info("Loaded config file from: " + configPath);
FileReader reader = new FileReader(configFile);
char[] contents = new char[(int)file.length()];
reader.read(contents);
log.info("Contents: " + String.valueOf(contents));
}
}
attribute.parents = karaf
bundle.configloader = mvn:com.example/LoadJsonFromProfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment