Search in sources :

Example 1 with UrlRewriteStepProcessor

use of org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor in project knox by apache.

the class UrlRewriteStepProcessorHolder method initialize.

@Override
@SuppressWarnings("unchecked")
public void initialize(UrlRewriteEnvironment environment, UrlRewriteStepDescriptor descriptor) throws Exception {
    UrlRewriteStepProcessor processor = UrlRewriteStepProcessorFactory.create(descriptor);
    processor.initialize(environment, descriptor);
    initialize(environment, descriptor, processor);
}
Also used : UrlRewriteStepProcessor(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor)

Example 2 with UrlRewriteStepProcessor

use of org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor 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 3 with UrlRewriteStepProcessor

use of org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor in project knox by apache.

the class UrlRewriteStepProcessorFactory method create.

public static UrlRewriteStepProcessor create(UrlRewriteStepDescriptor descriptor) throws IllegalAccessException, InstantiationException {
    UrlRewriteStepProcessor processor;
    Map<String, Class<? extends UrlRewriteStepProcessor>> typeMap;
    typeMap = MAP.get(descriptor.getClass());
    if (typeMap == null) {
        Class<? extends UrlRewriteStepDescriptor> descriptorInterface = getDescriptorInterface(descriptor);
        typeMap = MAP.get(descriptorInterface);
    }
    if (typeMap == null) {
        throw new IllegalArgumentException(descriptor.getClass().getName());
    } else {
        String type = descriptor.type();
        Class<? extends UrlRewriteStepProcessor> processorClass = typeMap.get(type);
        if (processorClass == null) {
            throw new IllegalArgumentException(type);
        } else {
            processor = processorClass.newInstance();
        }
    }
    return processor;
}
Also used : UrlRewriteStepProcessor(org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor)

Aggregations

UrlRewriteStepProcessor (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteStepProcessor)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UrlRewriteStepDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteStepDescriptor)1