Search in sources :

Example 1 with UrlRewriteStepDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor in project knox by apache.

the class UrlRewriteStepProcessorFactory method loadStepProcessors.

private static Map<Class<? extends UrlRewriteStepDescriptor>, Map<String, Class<? extends UrlRewriteStepProcessor>>> loadStepProcessors() {
    Map<Class<? extends UrlRewriteStepDescriptor>, Map<String, Class<? extends UrlRewriteStepProcessor>>> descriptorMap = new HashMap<>();
    ServiceLoader<UrlRewriteStepProcessor> processors = ServiceLoader.load(UrlRewriteStepProcessor.class);
    for (UrlRewriteStepProcessor processor : processors) {
        Class<? extends UrlRewriteStepDescriptor> descriptorInterface = getDescriptorInterface(processor);
        Map<String, Class<? extends UrlRewriteStepProcessor>> typeMap = descriptorMap.get(descriptorInterface);
        if (typeMap == null) {
            typeMap = new HashMap<>();
            descriptorMap.put(descriptorInterface, typeMap);
        }
        String processorType = processor.getType();
        typeMap.put(processorType, processor.getClass());
    }
    return descriptorMap;
}
Also used : UrlRewriteStepProcessor(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor) HashMap(java.util.HashMap) UrlRewriteStepDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with UrlRewriteStepDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor in project knox by apache.

the class UrlRewriteStepProcessorHolder method initialize.

// For unit testing.
@SuppressWarnings("unchecked")
void initialize(UrlRewriteEnvironment environment, UrlRewriteStepDescriptor descriptor, UrlRewriteStepProcessor processor) throws Exception {
    this.descriptor = descriptor;
    this.processor = processor;
    this.isCondition = descriptor instanceof UrlRewriteFlowDescriptor;
    this.childProcessors = new ArrayList<UrlRewriteStepProcessorHolder>();
    if (isCondition) {
        UrlRewriteFlowDescriptor flowDescriptor = (UrlRewriteFlowDescriptor) descriptor;
        List<UrlRewriteStepDescriptor> stepList = flowDescriptor.steps();
        if (stepList != null && !stepList.isEmpty()) {
            Iterator<UrlRewriteStepDescriptor> stepIterator = stepList.iterator();
            while (stepIterator.hasNext()) {
                UrlRewriteStepDescriptor stepDescriptor = stepIterator.next();
                UrlRewriteStepProcessorHolder stepProcessor = new UrlRewriteStepProcessorHolder();
                stepProcessor.initialize(environment, stepDescriptor);
                childProcessors.add(stepProcessor);
            }
        }
    }
}
Also used : UrlRewriteStepDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor) UrlRewriteFlowDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor)

Example 3 with UrlRewriteStepDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor in project knox by apache.

the class XmlUrlRewriteRulesExporter method createStep.

private Element createStep(Document document, UrlRewriteStepDescriptor step) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Element parentElement = createElement(document, step.type(), step);
    if (step instanceof UrlRewriteFlowDescriptor) {
        UrlRewriteFlowDescriptor flow = (UrlRewriteFlowDescriptor) step;
        for (Object child : flow.steps()) {
            UrlRewriteStepDescriptor childStep = (UrlRewriteStepDescriptor) child;
            Element childElement = createStep(document, childStep);
            parentElement.appendChild(childElement);
        }
    }
    return parentElement;
}
Also used : Element(org.w3c.dom.Element) UrlRewriteStepDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor) UrlRewriteFlowDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor)

Example 4 with UrlRewriteStepDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor in project knox by apache.

the class XmlUrlRewriteRulesExporter method createRule.

private Element createRule(Document document, UrlRewriteRuleDescriptor rule) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Element ruleElement = createElement(document, RULE, rule);
    for (UrlRewriteStepDescriptor step : rule.steps()) {
        Element childElement = createStep(document, step);
        ruleElement.appendChild(childElement);
    }
    return ruleElement;
}
Also used : Element(org.w3c.dom.Element) UrlRewriteStepDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor)

Aggregations

UrlRewriteStepDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor)4 UrlRewriteFlowDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UrlRewriteStepProcessor (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor)1