use of org.apache.commons.configuration2.XMLConfiguration in project load-balancer by RestComm.
the class XmlConfigurationLoader method setFilterConfig.
private static void setFilterConfig(XMLConfiguration xmlConfiguration, HttpConfiguration httpConfiguration) {
Document doc = xmlConfiguration.getDocument();
NodeList nodes = doc.getElementsByTagName("urlrewrite");
Node node = null;
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNodeName().equals("urlrewrite"))
node = nodes.item(i);
}
if (node != null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document urlRewriteRuleDocument = builder.newDocument();
Node importedNode = urlRewriteRuleDocument.importNode(node, true);
urlRewriteRuleDocument.appendChild(importedNode);
httpConfiguration.setUrlrewriteRule(urlRewriteRuleDocument);
}
}
use of org.apache.commons.configuration2.XMLConfiguration in project load-balancer by RestComm.
the class XmlConfigurationLoader method setHeartbeatConfig.
private void setHeartbeatConfig(LoadBalancerConfiguration lbConfiguration, XMLConfiguration xmlConfiguration) {
String configClassString = xmlConfiguration.getString("heartbeat[@configclass]");
if (configClassString != null) {
lbConfiguration.setHeartbeatConfigurationClass(xmlConfiguration.getString("heartbeat[@configclass]"));
Document doc = xmlConfiguration.getDocument();
NodeList nodes = doc.getElementsByTagName("heartbeatConfig");
Node node = null;
int lentgth = nodes.getLength();
for (int i = 0; i < lentgth; i++) {
if (nodes.item(i).getNodeName().equals("heartbeatConfig"))
node = nodes.item(i);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document heartbeatConfigDocument = builder.newDocument();
Node importedNode = heartbeatConfigDocument.importNode(node, true);
heartbeatConfigDocument.appendChild(importedNode);
JAXBContext jc = null;
Unmarshaller u = null;
try {
jc = JAXBContext.newInstance(Class.forName(lbConfiguration.getHeartbeatConfigurationClass()));
u = jc.createUnmarshaller();
lbConfiguration.setHeartbeatConfiguration((HeartbeatConfig) u.unmarshal(heartbeatConfigDocument));
} catch (ClassNotFoundException | JAXBException e) {
e.printStackTrace();
}
}
}
use of org.apache.commons.configuration2.XMLConfiguration in project load-balancer by RestComm.
the class XmlConfigurationLoader method load.
public LoadBalancerConfiguration load(File filepath) {
// Default configuration
LoadBalancerConfiguration configuration = new LoadBalancerConfiguration();
// Read configuration from file
XMLConfiguration xml;
try {
xml = this.configurations.xml(filepath);
setHeartbeatConfig(configuration, xml);
// Overwrite default configurations
configureCommon(xml.configurationAt("common"), configuration.getCommonConfiguration());
configureHttp(xml, configuration.getHttpConfiguration());
configureSmpp(xml.configurationAt("smpp"), configuration.getSmppConfiguration());
configureSip(xml, configuration.getSipConfiguration());
configureSsl(xml.configurationAt("ssl"), configuration.getSslConfiguration());
configureSipStack(xml.configurationsAt("sipStack.property"), configuration.getSipStackConfiguration(), xml.configurationAt("ssl"));
} catch (ConfigurationException | IllegalArgumentException e) {
log.error("Could not load configuration from " + filepath + ". Using default values. Message : " + e.getMessage());
}
return configuration;
}
use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class ToCurrentTargetedVersionItemProcessorTest method setUpCurrentConfig.
private void setUpCurrentConfig() {
XMLConfiguration config = mock(XMLConfiguration.class);
when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
SiteContext siteContext = spy(new SiteContext());
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getConfig()).thenReturn(config);
SiteContext.setCurrent(siteContext);
}
use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class ConfigurationScriptJobResolverTest method setUpSiteContext.
private void setUpSiteContext(SiteContext siteContext, ContentStoreService storeService) throws Exception {
XMLConfiguration config = ConfigUtils.readXmlConfiguration(new ClassPathResource("config/site-config.xml"), ',', null);
config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getConfig()).thenReturn(config);
}
Aggregations