Search in sources :

Example 11 with XMLConfiguration

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);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 12 with XMLConfiguration

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();
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 13 with XMLConfiguration

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;
}
Also used : XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with XMLConfiguration

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);
}
Also used : XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) SiteContext(org.craftercms.engine.service.context.SiteContext)

Example 15 with XMLConfiguration

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);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) Context(org.craftercms.core.service.Context) JobContext(org.craftercms.engine.util.quartz.JobContext) XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)12 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 ImmutableNode (org.apache.commons.configuration2.tree.ImmutableNode)4 SiteContext (org.craftercms.engine.service.context.SiteContext)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)3 Lookup (org.apache.commons.configuration2.interpol.Lookup)3 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 CombinedConfiguration (org.apache.commons.configuration2.CombinedConfiguration)2 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)2 Context (org.craftercms.core.service.Context)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 HostnameLookup (com.evolveum.midpoint.init.interpol.HostnameLookup)1 RandomLookup (com.evolveum.midpoint.init.interpol.RandomLookup)1