Search in sources :

Example 1 with UrlRewriteFunctionDescriptor

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

the class XmlUrlRewriteRulesExporter method store.

@Override
public void store(UrlRewriteRulesDescriptor descriptor, Writer writer) throws IOException {
    try {
        Document document = XmlUtils.createDocument();
        Element root = document.createElement(ROOT);
        document.appendChild(root);
        if (!descriptor.getFunctions().isEmpty()) {
            Element functionsElement = document.createElement(FUNCTIONS);
            root.appendChild(functionsElement);
            for (UrlRewriteFunctionDescriptor function : descriptor.getFunctions()) {
                Element functionElement = createElement(document, function.name(), function);
                functionsElement.appendChild(functionElement);
            }
        }
        if (!descriptor.getRules().isEmpty()) {
            for (UrlRewriteRuleDescriptor rule : descriptor.getRules()) {
                Element ruleElement = createRule(document, rule);
                root.appendChild(ruleElement);
            }
        }
        if (!descriptor.getFilters().isEmpty()) {
            for (UrlRewriteFilterDescriptor filter : descriptor.getFilters()) {
                Element filterElement = createFilter(document, filter);
                root.appendChild(filterElement);
            }
        }
        XmlUtils.writeXml(document, writer);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (TransformerException e) {
        throw new IOException(e);
    } catch (InvocationTargetException e) {
        LOG.failedToWriteRulesDescriptor(e);
    } catch (NoSuchMethodException e) {
        LOG.failedToWriteRulesDescriptor(e);
    } catch (IntrospectionException e) {
        LOG.failedToWriteRulesDescriptor(e);
    } catch (IllegalAccessException e) {
        LOG.failedToWriteRulesDescriptor(e);
    }
}
Also used : UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) Element(org.w3c.dom.Element) IntrospectionException(java.beans.IntrospectionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) UrlRewriteFunctionDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor) TransformerException(javax.xml.transform.TransformerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)

Example 2 with UrlRewriteFunctionDescriptor

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

the class HtmlPrefixProcessor method initialize.

@Override
public void initialize(final UrlRewriteEnvironment environment, final HtmlPrefixDescriptor descriptor) throws Exception {
    final UrlRewriteFunctionDescriptor frontendDescriptor = UrlRewriteFunctionDescriptorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME);
    frontend = UrlRewriteFunctionProcessorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME, frontendDescriptor);
    frontend.initialize(environment, frontendDescriptor);
}
Also used : UrlRewriteFunctionDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor)

Example 3 with UrlRewriteFunctionDescriptor

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

the class UrlRewriteFunctionProcessorFactory method loadProcessors.

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

Example 4 with UrlRewriteFunctionDescriptor

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

the class HtmlImportFunctionProcessor method initialize.

@Override
public void initialize(UrlRewriteEnvironment environment, HtmlImportFunctionDescriptor descriptor) throws Exception {
    UrlRewriteFunctionDescriptor frontendDescriptor = UrlRewriteFunctionDescriptorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME);
    frontend = UrlRewriteFunctionProcessorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME, frontendDescriptor);
    frontend.initialize(environment, frontendDescriptor);
}
Also used : UrlRewriteFunctionDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor)

Aggregations

UrlRewriteFunctionDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor)4 IntrospectionException (java.beans.IntrospectionException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 UrlRewriteFilterDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)1 UrlRewriteRuleDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor)1 UrlRewriteFunctionProcessor (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1