Search in sources :

Example 1 with UrlRewriteFlowDescriptor

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

the class UrlRewriteStepProcessorHolder method process.

@Override
public UrlRewriteStepStatus process(UrlRewriteContext context) throws Exception {
    UrlRewriteStepStatus status = UrlRewriteStepStatus.SUCCESS;
    // If initialization failed then fail processing
    if (processor != null) {
        status = processor.process(context);
        if (UrlRewriteStepStatus.SUCCESS == status && descriptor instanceof UrlRewriteFlowDescriptor && !childProcessors.isEmpty()) {
            UrlRewriteFlowDescriptor flowDescriptor = (UrlRewriteFlowDescriptor) descriptor;
            UrlRewriteStepFlow flow = flowDescriptor.flow();
            if (flow == null) {
                flow = UrlRewriteStepFlow.AND;
            }
            switch(flow) {
                case ALL:
                    return processAllFlow(context);
                case AND:
                    return processAndFlow(context);
                case OR:
                    return processOrFlow(context);
            }
        }
    }
    return status;
}
Also used : UrlRewriteStepStatus(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus) UrlRewriteFlowDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor) UrlRewriteStepFlow(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepFlow)

Example 2 with UrlRewriteFlowDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor 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 UrlRewriteFlowDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor 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)

Aggregations

UrlRewriteFlowDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFlowDescriptor)3 UrlRewriteStepDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor)2 UrlRewriteStepFlow (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepFlow)1 UrlRewriteStepStatus (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepStatus)1 Element (org.w3c.dom.Element)1