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;
}
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);
}
}
}
}
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;
}
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;
}
Aggregations