Search in sources :

Example 1 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project load-balancer by RestComm.

the class XmlConfigurationLoader method configureSip.

private static void configureSip(XMLConfiguration xml, SipConfiguration dst) {
    HierarchicalConfiguration<ImmutableNode> src = xml.configurationAt("sip");
    List<HierarchicalConfiguration<ImmutableNode>> srcRoutingRulesIpv4 = xml.configurationsAt("sip.routingRulesIpv4.rule");
    List<HierarchicalConfiguration<ImmutableNode>> srcRoutingRulesIpv6 = xml.configurationsAt("sip.routingRulesIpv6.rule");
    ExternalLegConfiguration ex = dst.getExternalLegConfiguration();
    InternalLegConfiguration in = dst.getInternalLegConfiguration();
    AlgorithmConfiguration alg = dst.getAlgorithmConfiguration();
    // Basic SIP configuration
    dst.setPublicIp(src.getString("publicIp", SipConfiguration.PUBLIC_IP));
    dst.setPublicIpv6(src.getString("publicIpv6", SipConfiguration.PUBLIC_IPV6));
    dst.setExtraServerNodes(src.getString("extraServerNodes", SipConfiguration.EXTRA_SERVER_NODES));
    dst.setPerformanceTestingMode(src.getBoolean("performanceTestingMode", SipConfiguration.PERFORMANCE_TESTING_MODE));
    dst.setUseIpLoadBalancerAddressInViaHeaders(src.getBoolean("useIpLoadBalancerAddressInViaHeaders", SipConfiguration.USE_IP_LOAD_BALANCER_ADRESS_IN_VIA_HEADERS));
    dst.setSendTrying(src.getBoolean("isSendTrying", SipConfiguration.IS_SEND_TRYING));
    dst.setBlockedValues(src.getString("blockedValues", SipConfiguration.BLOCKED_VALUES));
    dst.setUsePrettyEncoding(src.getBoolean("usePrettyEncoding", SipConfiguration.USE_PRETTY_ENCODING));
    dst.setIsSend5xxResponse(src.getBoolean("isSend5xxResponse", SipConfiguration.IS_SEND_5XX_RESPONSE));
    dst.setIsSend5xxResponseSatusCode(src.getInteger("isSend5xxResponseSatusCode", SipConfiguration.IS_SEND_5XX_RESPONSE_STATUS_CODE));
    dst.setIsSend5xxResponseReasonHeader(src.getString("isSend5xxResponseReasonHeader", SipConfiguration.IS_SEND_5XX_RESPONSE_REASON_HEADER));
    String responsesStatusCodeNodeRemoval = src.getString("responsesStatusCodeNodeRemoval", SipConfiguration.RESPONSES_STATUS_CODE_NODE_REMOVAL);
    if (responsesStatusCodeNodeRemoval != null) {
        List<Integer> responsesStatusCodeNodeRemovalList = new ArrayList<Integer>();
        StringTokenizer tokens = new StringTokenizer(responsesStatusCodeNodeRemoval, ",");
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            responsesStatusCodeNodeRemovalList.add(Integer.parseInt(token));
        }
        dst.setResponseStatusCodeNodeRemoval(responsesStatusCodeNodeRemovalList);
    }
    if (src.getString("maxNumberResponsesWithError") != null && !src.getString("maxNumberResponsesWithError").equals(""))
        dst.setMaxNumberResponsesWithError(src.getInteger("maxNumberResponsesWithError", SipConfiguration.MAX_NUMBER_RESPONSES_WITH_ERROR));
    if (src.getString("maxErrorTime") != null && !src.getString("maxErrorTime").equals(""))
        dst.setMaxErrorTime(src.getLong("maxErrorTime", SipConfiguration.MAX_ERROR_TIME));
    dst.setIsUseWithNexmo(src.getBoolean("isUseWithNexmo", SipConfiguration.IS_USE_WITH_NEXMO));
    dst.setMatchingHostnameForRoute(src.getString("matchingHostnameForRoute", SipConfiguration.MATCHING_HOSTNAME_FOR_ROUTE));
    dst.setIsFilterSubdomain(src.getBoolean("isFilterSubdomain", SipConfiguration.IS_FILTER_SUBDOMAIN));
    if (src.getString("internalTransport") != null && !src.getString("internalTransport").equals(""))
        dst.setInternalTransport(src.getString("internalTransport", SipConfiguration.INTERNAL_TRANSPORT));
    if (src.getString("trafficRampupCyclePeriod") != null && !src.getString("trafficRampupCyclePeriod").equals(""))
        dst.setTrafficRampupCyclePeriod(src.getInteger("trafficRampupCyclePeriod", SipConfiguration.TRAFFIC_RAMPUP_CYCLE_PERIOD));
    if (src.getString("trafficPercentageIncrease") != null && !src.getString("trafficPercentageIncrease").equals(""))
        dst.setTrafficPercentageIncrease(src.getInteger("trafficPercentageIncrease", SipConfiguration.MAX_WEIGHT_INDEX));
    if (src.getString("maxRequestNumberWithoutResponse") != null && !src.getString("maxRequestNumberWithoutResponse").equals(""))
        dst.setMaxRequestNumberWithoutResponse(src.getInteger("maxRequestNumberWithoutResponse", SipConfiguration.MAX_REQUEST_NUMBER_WITHOUT_RESPONSE));
    if (src.getString("maxResponseTime") != null && !src.getString("maxResponseTime").equals(""))
        dst.setMaxResponseTime(src.getLong("maxResponseTime", SipConfiguration.MAX_RESPONSE_TIME));
    // Routing rules
    if (srcRoutingRulesIpv4 != null) {
        ArrayList<RoutingRule> routingRulesIpv4 = new ArrayList<RoutingRule>();
        for (HierarchicalConfiguration<ImmutableNode> property : srcRoutingRulesIpv4) routingRulesIpv4.add(new RoutingRule(property.getString("ipPattern"), property.getBoolean("patch")));
        dst.setRoutingRulesIpv4(routingRulesIpv4);
    }
    if (srcRoutingRulesIpv6 != null) {
        ArrayList<RoutingRule> routingRulesIpv6 = new ArrayList<RoutingRule>();
        for (HierarchicalConfiguration<ImmutableNode> property : srcRoutingRulesIpv6) routingRulesIpv6.add(new RoutingRule(property.getString("ipPattern"), property.getBoolean("patch")));
        dst.setRoutingRulesIpv6(routingRulesIpv6);
    }
    // Algorithm configuration
    if (src.getString("algorithm.algorithmClass") != null && !src.getString("algorithm.algorithmClass").equals(""))
        alg.setAlgorithmClass(src.getString("algorithm.algorithmClass", AlgorithmConfiguration.ALGORITHM_CLASS));
    if (src.getString("algorithm.sipHeaderAffinityKey") != null && !src.getString("algorithm.sipHeaderAffinityKey").equals(""))
        alg.setSipHeaderAffinityKey(src.getString("algorithm.sipHeaderAffinityKey", AlgorithmConfiguration.SIP_HEADER_AFFINITY_KEY));
    if (src.getString("algorithm.sipHeaderAffinityExclusionPattern") != null && !src.getString("algorithm.sipHeaderAffinityExclusionPattern").equals(""))
        alg.setSipHeaderAffinityKeyExclusionPattern(src.getString("algorithm.sipHeaderAffinityExclusionPattern"));
    if (src.getString("algorithm.sipHeaderAffinityFallbackKey") != null && !src.getString("algorithm.sipHeaderAffinityFallbackKey").equals(""))
        alg.setSipHeaderAffinityFallbackKey(src.getString("algorithm.sipHeaderAffinityFallbackKey"));
    alg.setCallIdAffinityGroupFailover(src.getBoolean("algorithm.callIdAffinityGroupFailover", AlgorithmConfiguration.CALL_ID_AFFINITY_GROUP_FAILOVER));
    alg.setCallIdAffinityMaxTimeInCache(src.getInteger("algorithm.callIdAffinityMaxTimeInCache", AlgorithmConfiguration.CALL_ID_AFFINITY_MAX_TIME_IN_CACHE));
    alg.setHttpAffinityKey(src.getString("algorithm.httpAffinityKey", AlgorithmConfiguration.HTTP_AFFINITY_KEY));
    alg.setSubclusterMap(src.getString("subclusterMap", AlgorithmConfiguration.SUBCLUSTER_MAP));
    alg.setEarlyDialogWorstCase(src.getBoolean("earlyDialogWorstCase", AlgorithmConfiguration.EARLY_DIALOG_WORST_CASE));
    // external leg configuration
    ex.setHost(src.getString("external.host", ExternalLegConfiguration.HOST));
    String externalIpLoadBalancerAddresses = src.getString("external.ipLoadBalancerAddress", ExternalLegConfiguration.IP_LOAD_BALANCER_ADRESS);
    if (externalIpLoadBalancerAddresses != null && !externalIpLoadBalancerAddresses.equals("")) {
        ArrayList<String> externalIpLoadBalancerAddressesList = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(externalIpLoadBalancerAddresses, ",");
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            externalIpLoadBalancerAddressesList.add(token);
        }
        ex.setIpLoadBalancerAddress(externalIpLoadBalancerAddressesList);
    }
    if (src.getString("external.udpPort") != null && !src.getString("external.udpPort").equals(""))
        ex.setUdpPort(src.getInteger("external.udpPort", ExternalLegConfiguration.UDP_PORT));
    if (src.getString("external.tcpPort") != null && !src.getString("external.tcpPort").equals(""))
        ex.setTcpPort(src.getInteger("external.tcpPort", ExternalLegConfiguration.TCP_PORT));
    if (src.getString("external.tlsPort") != null && !src.getString("external.tlsPort").equals(""))
        ex.setTlsPort(src.getInteger("external.tlsPort", ExternalLegConfiguration.TLS_PORT));
    if (src.getString("external.wsPort") != null && !src.getString("external.wsPort").equals(""))
        ex.setWsPort(src.getInteger("external.wsPort", ExternalLegConfiguration.WS_PORT));
    if (src.getString("external.wssPort") != null && !src.getString("external.wssPort").equals(""))
        ex.setWssPort(src.getInteger("external.wssPort", ExternalLegConfiguration.WSS_PORT));
    if (src.getString("external.ipLoadBalancerUdpPort") != null && !src.getString("external.ipLoadBalancerUdpPort").equals(""))
        ex.setIpLoadBalancerUdpPort(src.getInteger("external.ipLoadBalancerUdpPort", ExternalLegConfiguration.IP_LOAD_BALANCER_UDP_PORT));
    if (src.getString("external.ipLoadBalancerTcpPort") != null && !src.getString("external.ipLoadBalancerTcpPort").equals(""))
        ex.setIpLoadBalancerTcpPort(src.getInteger("external.ipLoadBalancerTcpPort", ExternalLegConfiguration.IP_LOAD_BALANCER_TCP_PORT));
    if (src.getString("external.ipLoadBalancerTlsPort") != null && !src.getString("external.ipLoadBalancerTlsPort").equals(""))
        ex.setIpLoadBalancerTlsPort(src.getInteger("external.ipLoadBalancerTlsPort", ExternalLegConfiguration.IP_LOAD_BALANCER_TLS_PORT));
    if (src.getString("external.ipLoadBalancerWsPort") != null && !src.getString("external.ipLoadBalancerWsPort").equals(""))
        ex.setIpLoadBalancerWsPort(src.getInteger("external.ipLoadBalancerWsPort", ExternalLegConfiguration.IP_LOAD_BALANCER_WS_PORT));
    if (src.getString("external.ipLoadBalancerWssPort") != null && !src.getString("external.ipLoadBalancerWssPort").equals(""))
        ex.setIpLoadBalancerWssPort(src.getInteger("external.ipLoadBalancerWssPort", ExternalLegConfiguration.IP_LOAD_BALANCER_WSS_PORT));
    // external ipv6
    ex.setIpv6Host(src.getString("external.ipv6Host", ExternalLegConfiguration.IPV6_HOST));
    String externalIpv6LoadBalancerAddresses = src.getString("external.ipv6LoadBalancerAddress", ExternalLegConfiguration.IPV6_LOAD_BALANCER_ADRESS);
    if (externalIpv6LoadBalancerAddresses != null && !externalIpv6LoadBalancerAddresses.equals("")) {
        ArrayList<String> externalIpv6LoadBalancerAddressesList = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(externalIpv6LoadBalancerAddresses, ",");
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            externalIpv6LoadBalancerAddressesList.add(token);
        }
        ex.setIpv6LoadBalancerAddress(externalIpv6LoadBalancerAddressesList);
    }
    if (src.getString("external.ipv6UdpPort") != null && !src.getString("external.ipv6UdpPort").equals(""))
        ex.setIpv6UdpPort(src.getInteger("external.ipv6UdpPort", ExternalLegConfiguration.IPV6_UDP_PORT));
    if (src.getString("external.ipv6TcpPort") != null && !src.getString("external.ipv6TcpPort").equals(""))
        ex.setIpv6TcpPort(src.getInteger("external.ipv6TcpPort", ExternalLegConfiguration.IPV6_TCP_PORT));
    if (src.getString("external.ipv6TlsPort") != null && !src.getString("external.ipv6TlsPort").equals(""))
        ex.setIpv6TlsPort(src.getInteger("external.ipv6TlsPort", ExternalLegConfiguration.IPV6_TLS_PORT));
    if (src.getString("external.ipv6WsPort") != null && !src.getString("external.ipv6WsPort").equals(""))
        ex.setIpv6WsPort(src.getInteger("external.ipv6WsPort", ExternalLegConfiguration.IPV6_WS_PORT));
    if (src.getString("external.ipv6WssPort") != null && !src.getString("external.ipv6WssPort").equals(""))
        ex.setIpv6WssPort(src.getInteger("external.ipv6WssPort", ExternalLegConfiguration.IPV6_WSS_PORT));
    if (src.getString("external.ipv6LoadBalancerUdpPort") != null && !src.getString("external.ipv6LoadBalancerUdpPort").equals(""))
        ex.setIpv6LoadBalancerUdpPort(src.getInteger("external.ipv6LoadBalancerUdpPort", ExternalLegConfiguration.IPV6_LOAD_BALANCER_UDP_PORT));
    if (src.getString("external.ipv6LoadBalancerTcpPort") != null && !src.getString("external.ipv6LoadBalancerTcpPort").equals(""))
        ex.setIpv6LoadBalancerTcpPort(src.getInteger("external.ipv6LoadBalancerTcpPort", ExternalLegConfiguration.IPV6_LOAD_BALANCER_TCP_PORT));
    if (src.getString("external.ipv6LoadBalancerTlsPort") != null && !src.getString("external.ipv6LoadBalancerTlsPort").equals(""))
        ex.setIpv6LoadBalancerTlsPort(src.getInteger("external.ipv6LoadBalancerTlsPort", ExternalLegConfiguration.IPV6_LOAD_BALANCER_TLS_PORT));
    if (src.getString("external.ipv6LoadBalancerWsPort") != null && !src.getString("external.ipv6LoadBalancerWsPort").equals(""))
        ex.setIpv6LoadBalancerWsPort(src.getInteger("external.ipv6LoadBalancerWsPort", ExternalLegConfiguration.IPV6_LOAD_BALANCER_WS_PORT));
    if (src.getString("external.ipv6LoadBalancerWssPort") != null && !src.getString("external.ipv6LoadBalancerWssPort").equals(""))
        ex.setIpv6LoadBalancerWssPort(src.getInteger("external.ipv6LoadBalancerWssPort", ExternalLegConfiguration.IPV6_LOAD_BALANCER_WSS_PORT));
    // internal leg configuration
    in.setHost(src.getString("internal.host", InternalLegConfiguration.HOST));
    String internalIpLoadBalancerAddresses = src.getString("internal.ipLoadBalancerAddress", InternalLegConfiguration.IP_LOAD_BALANCER_ADRESS);
    if (internalIpLoadBalancerAddresses != null && !internalIpLoadBalancerAddresses.equals("")) {
        ArrayList<String> internalIpLoadBalancerAddressesList = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(internalIpLoadBalancerAddresses, ",");
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            internalIpLoadBalancerAddressesList.add(token);
        }
        in.setIpLoadBalancerAddress(internalIpLoadBalancerAddressesList);
    }
    if (src.getString("internal.udpPort") != null && !src.getString("internal.udpPort").equals(""))
        in.setUdpPort(src.getInteger("internal.udpPort", InternalLegConfiguration.UDP_PORT));
    if (src.getString("internal.tcpPort") != null && !src.getString("internal.tcpPort").equals(""))
        in.setTcpPort(src.getInteger("internal.tcpPort", InternalLegConfiguration.TCP_PORT));
    if (src.getString("internal.tlsPort") != null && !src.getString("internal.tlsPort").equals(""))
        in.setTlsPort(src.getInteger("internal.tlsPort", InternalLegConfiguration.TLS_PORT));
    if (src.getString("internal.wsPort") != null && !src.getString("internal.wsPort").equals(""))
        in.setWsPort(src.getInteger("internal.wsPort", InternalLegConfiguration.WS_PORT));
    if (src.getString("internal.wssPort") != null && !src.getString("internal.wssPort").equals(""))
        in.setWssPort(src.getInteger("internal.wssPort", InternalLegConfiguration.WSS_PORT));
    if (src.getString("internal.ipLoadBalancerUdpPort") != null && !src.getString("internal.ipLoadBalancerUdpPort").equals(""))
        in.setIpLoadBalancerUdpPort(src.getInteger("internal.ipLoadBalancerUdpPort", InternalLegConfiguration.IP_LOAD_BALANCER_UDP_PORT));
    if (src.getString("internal.ipLoadBalancerTcpPort") != null && !src.getString("internal.ipLoadBalancerTcpPort").equals(""))
        in.setIpLoadBalancerTcpPort(src.getInteger("internal.ipLoadBalancerTcpPort", InternalLegConfiguration.IP_LOAD_BALANCER_TCP_PORT));
    if (src.getString("internal.ipLoadBalancerTlsPort") != null && !src.getString("internal.ipLoadBalancerTlsPort").equals(""))
        in.setIpLoadBalancerTlsPort(src.getInteger("internal.ipLoadBalancerTlsPort", InternalLegConfiguration.IP_LOAD_BALANCER_TLS_PORT));
    if (src.getString("internal.ipLoadBalancerWsPort") != null && !src.getString("internal.ipLoadBalancerWsPort").equals(""))
        in.setIpLoadBalancerWsPort(src.getInteger("internal.ipLoadBalancerWsPort", InternalLegConfiguration.IP_LOAD_BALANCER_WS_PORT));
    if (src.getString("internal.ipLoadBalancerWssPort") != null && !src.getString("internal.ipLoadBalancerWssPort").equals(""))
        in.setIpLoadBalancerWssPort(src.getInteger("internal.ipLoadBalancerWssPort", InternalLegConfiguration.IP_LOAD_BALANCER_WSS_PORT));
    // ipv6
    in.setIpv6Host(src.getString("internal.ipv6Host", InternalLegConfiguration.IPV6_HOST));
    String internalIpv6LoadBalancerAddresses = src.getString("internal.ipv6LoadBalancerAddress", InternalLegConfiguration.IPV6_LOAD_BALANCER_ADRESS);
    if (internalIpv6LoadBalancerAddresses != null && !internalIpv6LoadBalancerAddresses.equals("")) {
        ArrayList<String> internalIpv6LoadBalancerAddressesList = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(internalIpv6LoadBalancerAddresses, ",");
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            internalIpv6LoadBalancerAddressesList.add(token);
        }
        in.setIpv6LoadBalancerAddress(internalIpv6LoadBalancerAddressesList);
    }
    ;
    if (src.getString("internal.ipv6UdpPort") != null && !src.getString("internal.ipv6UdpPort").equals(""))
        in.setIpv6UdpPort(src.getInteger("internal.ipv6UdpPort", InternalLegConfiguration.IPV6_UDP_PORT));
    if (src.getString("internal.ipv6TcpPort") != null && !src.getString("internal.ipv6TcpPort").equals(""))
        in.setIpv6TcpPort(src.getInteger("internal.ipv6TcpPort", InternalLegConfiguration.IPV6_TCP_PORT));
    if (src.getString("internal.ipv6TlsPort") != null && !src.getString("internal.ipv6TlsPort").equals(""))
        in.setIpv6TlsPort(src.getInteger("internal.ipv6TlsPort", InternalLegConfiguration.IPV6_TLS_PORT));
    if (src.getString("internal.ipv6WsPort") != null && !src.getString("internal.ipv6WsPort").equals(""))
        in.setIpv6WsPort(src.getInteger("internal.ipv6WsPort", InternalLegConfiguration.IPV6_WS_PORT));
    if (src.getString("internal.ipv6WssPort") != null && !src.getString("internal.ipv6WssPort").equals(""))
        in.setIpv6WssPort(src.getInteger("internal.ipv6WssPort", InternalLegConfiguration.IPV6_WSS_PORT));
    if (src.getString("internal.ipv6LoadBalancerUdpPort") != null && !src.getString("internal.ipv6LoadBalancerUdpPort").equals(""))
        in.setIpv6LoadBalancerUdpPort(src.getInteger("internal.ipv6LoadBalancerUdpPort", InternalLegConfiguration.IPV6_LOAD_BALANCER_UDP_PORT));
    if (src.getString("internal.ipv6LoadBalancerTcpPort") != null && !src.getString("internal.ipv6LoadBalancerTcpPort").equals(""))
        in.setIpv6LoadBalancerTcpPort(src.getInteger("internal.ipv6LoadBalancerTcpPort", InternalLegConfiguration.IPV6_LOAD_BALANCER_TCP_PORT));
    if (src.getString("internal.ipv6LoadBalancerTlsPort") != null && !src.getString("internal.ipv6LoadBalancerTlsPort").equals(""))
        in.setIpv6LoadBalancerTlsPort(src.getInteger("internal.ipv6LoadBalancerTlsPort", InternalLegConfiguration.IPV6_LOAD_BALANCER_TLS_PORT));
    if (src.getString("internal.ipv6LoadBalancerWsPort") != null && !src.getString("internal.ipv6LoadBalancerWsPort").equals(""))
        in.setIpv6LoadBalancerWsPort(src.getInteger("internal.ipv6LoadBalancerWsPort", InternalLegConfiguration.IPV6_LOAD_BALANCER_WS_PORT));
    if (src.getString("internal.ipv6LoadBalancerWssPort") != null && !src.getString("internal.ipv6LoadBalancerWssPort").equals(""))
        in.setIpv6LoadBalancerWssPort(src.getInteger("internal.ipv6LoadBalancerWssPort", InternalLegConfiguration.IPV6_LOAD_BALANCER_WSS_PORT));
}
Also used : ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) StringTokenizer(java.util.StringTokenizer) RoutingRule(org.mobicents.tools.sip.balancer.RoutingRule)

Example 2 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class SiteAwareCORSFilter method doFilterInternal.

/**
 * Copy the values from the site configuration to the response headers.
 */
@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException {
    SiteContext siteContext = SiteContext.getCurrent();
    HierarchicalConfiguration corsConfig = siteContext.getConfig().configurationAt(CONFIG_KEY);
    response.setHeader(CORSFilter.ALLOW_ORIGIN, corsConfig.getString(ALLOW_ORIGIN_KEY, ALLOW_ORIGIN_DEFAULT));
    response.setHeader(CORSFilter.ALLOW_CREDENTIALS, corsConfig.getString(ALLOW_CREDENTIALS_KEY, ALLOW_CREDENTIALS_DEFAULT));
    response.setHeader(CORSFilter.ALLOW_METHODS, corsConfig.getString(ALLOW_METHODS_KEY, ALLOW_METHODS_DEFAULT));
    response.setHeader(CORSFilter.ALLOW_HEADERS, corsConfig.getString(ALLOW_HEADERS_KEY, ALLOW_HEADERS_DEFAULT));
    response.setHeader(CORSFilter.MAX_AGE, corsConfig.getString(MAX_AGE_KEY, MAX_AGE_DEFAULT));
    filterChain.doFilter(request, response);
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Example 3 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class SiteAwareCORSFilter method shouldNotFilter.

/**
 * Exclude requests for sites that have no configuration or it is marked as disabled.
 */
@Override
protected boolean shouldNotFilter(final HttpServletRequest request) throws ServletException {
    SiteContext siteContext = SiteContext.getCurrent();
    HierarchicalConfiguration config = siteContext.getConfig();
    try {
        HierarchicalConfiguration corsConfig = config.configurationAt(CONFIG_KEY);
        if (corsConfig != null) {
            return !corsConfig.getBoolean(ENABLE_KEY, false);
        }
    } catch (Exception e) {
        logger.debug("Site '{}' has no CORS configuration", siteContext.getSiteName());
    }
    return true;
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 4 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class MultiResourceConfigurationBuilder method getConfiguration.

@Override
public HierarchicalConfiguration getConfiguration() throws ConfigurationException {
    List<HierarchicalConfiguration> configs = new ArrayList<>();
    // Last configurations should be loaded and added first so that they have greater priority.
    logger.info("Loading XML configurations in the order in which the properties will be resolved");
    for (int i = configPaths.length - 1; i >= 0; i--) {
        try {
            Resource resource = resourceLoader.getResource(configPaths[i]);
            if (resource.exists()) {
                Map<String, Lookup> prefixLookups = null;
                if (configDecryptor != null) {
                    prefixLookups = Collections.singletonMap(encryptedValuePrefix, new DecryptionLookup(configDecryptor));
                }
                XMLConfiguration config = ConfigUtils.readXmlConfiguration(resource, configListDelimiter, prefixLookups);
                logger.info("XML configuration loaded from " + resource);
                configs.add(config);
            }
        } catch (Exception e) {
            throw new ConfigurationException("Unable to load configuration at " + configPaths[i], e);
        }
    }
    if (configs.size() > 1) {
        CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
        for (Configuration config : configs) {
            combinedConfig.addConfiguration(config);
        }
        return combinedConfig;
    } else if (configs.size() == 1) {
        return configs.get(0);
    } else {
        return null;
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) DecryptionLookup(org.craftercms.commons.config.DecryptionLookup) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) OverrideCombiner(org.apache.commons.configuration2.tree.OverrideCombiner) XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) DecryptionLookup(org.craftercms.commons.config.DecryptionLookup) Lookup(org.apache.commons.configuration2.interpol.Lookup)

Example 5 with HierarchicalConfiguration

use of org.apache.commons.configuration2.HierarchicalConfiguration in project engine by craftercms.

the class ConfigurationScriptJobResolver method resolveJobs.

@Override
@SuppressWarnings("unchecked")
public List<JobContext> resolveJobs(SiteContext siteContext) throws SchedulingException {
    HierarchicalConfiguration config = siteContext.getConfig();
    List<JobContext> jobContexts = new ArrayList<>();
    if (config != null) {
        List<HierarchicalConfiguration> jobFoldersConfig = config.configurationsAt(JOB_FOLDER_KEY);
        if (CollectionUtils.isNotEmpty(jobFoldersConfig)) {
            for (HierarchicalConfiguration jobFolderConfig : jobFoldersConfig) {
                List<JobContext> folderJobContexts = getJobsUnderFolder(siteContext, jobFolderConfig);
                if (CollectionUtils.isNotEmpty(folderJobContexts)) {
                    jobContexts.addAll(folderJobContexts);
                }
            }
        }
        List<HierarchicalConfiguration> jobsConfig = config.configurationsAt(JOB_KEY);
        if (CollectionUtils.isNotEmpty(jobsConfig)) {
            for (HierarchicalConfiguration jobConfig : jobsConfig) {
                JobContext jobContext = getJob(siteContext, jobConfig);
                if (jobContext != null) {
                    jobContexts.add(jobContext);
                }
            }
        }
    }
    return jobContexts;
}
Also used : ArrayList(java.util.ArrayList) JobContext(org.craftercms.engine.util.quartz.JobContext) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Aggregations

HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)13 SiteContext (org.craftercms.engine.service.context.SiteContext)8 ArrayList (java.util.ArrayList)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)4 Callback (org.craftercms.commons.lang.Callback)3 ConfigurationException (org.craftercms.engine.exception.ConfigurationException)3 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)3 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 BeansException (org.springframework.beans.BeansException)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 Resource (org.springframework.core.io.Resource)2 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1