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