Search in sources :

Example 1 with UrlRewriteFilterGroupDescriptor

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

the class JsonFilterReader method startBuffering.

protected boolean startBuffering(Level node) {
    boolean buffered = false;
    UrlRewriteFilterGroupDescriptor scope = node.scopeConfig;
    if (scope != null) {
        for (UrlRewriteFilterPathDescriptor selector : scope.getSelectors()) {
            JsonPath.Expression path = (JsonPath.Expression) selector.compiledPath(JPATH_COMPILER);
            List<JsonPath.Match> matches = path.evaluate(node.scopeNode);
            if (matches != null && !matches.isEmpty()) {
                if (selector instanceof UrlRewriteFilterBufferDescriptor) {
                    bufferingLevel = node;
                    bufferingConfig = (UrlRewriteFilterBufferDescriptor) selector;
                    buffered = true;
                }
                break;
            }
        }
    }
    return buffered;
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) JsonPath(org.apache.knox.gateway.util.JsonPath) UrlRewriteFilterGroupDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor) UrlRewriteFilterPathDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor)

Example 2 with UrlRewriteFilterGroupDescriptor

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

the class XmlUrlRewriteRulesExporter method createFilterSelector.

private Element createFilterSelector(Document document, UrlRewriteFilterPathDescriptor parent) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Element parentElement = createElement(document, toTagName(parent), parent);
    if (parent instanceof UrlRewriteFilterGroupDescriptor) {
        for (UrlRewriteFilterPathDescriptor child : ((UrlRewriteFilterGroupDescriptor) parent).getSelectors()) {
            Element childElement = createFilterSelector(document, child);
            parentElement.appendChild(childElement);
        }
    }
    return parentElement;
}
Also used : Element(org.w3c.dom.Element) UrlRewriteFilterGroupDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor) UrlRewriteFilterPathDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor)

Example 3 with UrlRewriteFilterGroupDescriptor

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

the class JsonFilterReader method filterStreamValue.

protected String filterStreamValue(Level node) {
    String value;
    if (node.isArray()) {
        value = node.node.get(0).asText();
    } else {
        value = node.node.get(node.field).asText();
    }
    String rule = null;
    UrlRewriteFilterGroupDescriptor scope = node.scopeConfig;
    // TODO: Scan the top level apply rules for the first match.
    if (scope != null) {
        for (UrlRewriteFilterPathDescriptor selector : scope.getSelectors()) {
            JsonPath.Expression path = (JsonPath.Expression) selector.compiledPath(JPATH_COMPILER);
            List<JsonPath.Match> matches = path.evaluate(node.scopeNode);
            if (matches != null && !matches.isEmpty()) {
                JsonPath.Match match = matches.get(0);
                if (match.getNode().isTextual()) {
                    if (selector instanceof UrlRewriteFilterApplyDescriptor) {
                        UrlRewriteFilterApplyDescriptor apply = (UrlRewriteFilterApplyDescriptor) selector;
                        rule = apply.rule();
                        break;
                    }
                }
            }
        }
    }
    try {
        value = filterValueString(node.field, value, rule);
        if (node.isArray()) {
            ((ArrayNode) node.node).set(0, new TextNode(value));
        } else {
            ((ObjectNode) node.node).put(node.field, value);
        }
    } catch (Exception e) {
        LOG.failedToFilterValue(value, rule, e);
    }
    return value;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonPath(org.apache.knox.gateway.util.JsonPath) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UrlRewriteFilterGroupDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterPathDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor)

Aggregations

UrlRewriteFilterGroupDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterGroupDescriptor)3 UrlRewriteFilterPathDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor)3 JsonPath (org.apache.knox.gateway.util.JsonPath)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 IOException (java.io.IOException)1 UrlRewriteFilterApplyDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor)1 UrlRewriteFilterBufferDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor)1 Element (org.w3c.dom.Element)1