Search in sources :

Example 1 with UrlRewriteRuleProcessorHolder

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder in project knox by apache.

the class UrlRewriteProcessor method initializeRules.

private void initializeRules(UrlRewriteRulesDescriptor descriptor) {
    for (UrlRewriteRuleDescriptor ruleDescriptor : descriptor.getRules()) {
        try {
            UrlRewriteRuleProcessorHolder ruleProcessor = new UrlRewriteRuleProcessorHolder();
            ruleProcessor.initialize(environment, ruleDescriptor);
            if (!rules.containsKey(ruleDescriptor.name())) {
                rules.put(ruleDescriptor.name(), ruleProcessor);
            }
            Template template = ruleDescriptor.template();
            if (template != null) {
                EnumSet<Direction> directions = ruleDescriptor.directions();
                if (directions == null || directions.isEmpty()) {
                    inbound.add(template, ruleProcessor);
                    outbound.add(template, ruleProcessor);
                } else if (directions.contains(Direction.IN)) {
                    inbound.add(template, ruleProcessor);
                } else if (directions.contains(Direction.OUT)) {
                    outbound.add(template, ruleProcessor);
                }
            }
        } catch (Exception e) {
            LOG.failedToInitializeRewriteRules(e);
        }
    }
}
Also used : UrlRewriteRuleProcessorHolder(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder) Template(org.apache.knox.gateway.util.urltemplate.Template)

Example 2 with UrlRewriteRuleProcessorHolder

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder in project knox by apache.

the class ScopedMatcher method getMatcher.

/**
 * Returns a matcher for a given template and processor holder. This method takes into account different scopes in
 * addition to template values. If a matcher exists for a template but the scope is different, a new matcher is
 * created and returned.
 * @param template the template for which a matcher is needed
 * @param holder the rule holder that goes along with the template.
 * @return a matcher
 */
private Matcher<UrlRewriteRuleProcessorHolder> getMatcher(Template template, UrlRewriteRuleProcessorHolder holder) {
    for (Matcher<UrlRewriteRuleProcessorHolder> matcher : matchers) {
        UrlRewriteRuleProcessorHolder matchersHolder = matcher.get(template);
        if (matchersHolder == null) {
            return matcher;
        } else if (holder.getScope() == null && matchersHolder.getScope() == null) {
            return matcher;
        }
    }
    Matcher<UrlRewriteRuleProcessorHolder> matcher = new Matcher<>();
    matchers.add(matcher);
    return matcher;
}
Also used : UrlRewriteRuleProcessorHolder(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder) Matcher(org.apache.knox.gateway.util.urltemplate.Matcher)

Aggregations

UrlRewriteRuleProcessorHolder (org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRuleProcessorHolder)2 Matcher (org.apache.knox.gateway.util.urltemplate.Matcher)1 Template (org.apache.knox.gateway.util.urltemplate.Template)1