use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor in project knox by apache.
the class UrlRewriteUtil method filterJavaScript.
public static String filterJavaScript(String inputValue, UrlRewriteFilterContentDescriptor config, UrlRewriteFilterReader filterReader, UrlRewriteFilterPathDescriptor.Compiler<Pattern> regexCompiler) {
StringBuffer tbuff = new StringBuffer();
StringBuffer sbuff = new StringBuffer();
sbuff.append(inputValue);
if (config != null && !config.getSelectors().isEmpty()) {
for (UrlRewriteFilterPathDescriptor selector : config.getSelectors()) {
if (selector instanceof UrlRewriteFilterApplyDescriptor) {
UrlRewriteFilterApplyDescriptor apply = (UrlRewriteFilterApplyDescriptor) selector;
Matcher matcher = apply.compiledPath(regexCompiler).matcher(sbuff);
int index = 0;
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
if (start != -1 && end != -1) {
tbuff.append(sbuff, index, start);
String value = matcher.group();
value = filterReader.filterValueString(null, value, apply.rule());
tbuff.append(value);
index = end;
}
}
tbuff.append(sbuff, index, sbuff.length());
sbuff.setLength(0);
sbuff.append(tbuff);
tbuff.setLength(0);
}
}
}
return sbuff.toString();
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor in project knox by apache.
the class XmlUrlRewriteRulesExporter method createFilterContent.
private Element createFilterContent(Document document, UrlRewriteFilterContentDescriptor parent) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
Element parentElement = createElement(document, CONTENT, parent);
for (UrlRewriteFilterPathDescriptor child : parent.getSelectors()) {
Element childElement = createFilterSelector(document, child);
parentElement.appendChild(childElement);
}
return parentElement;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor 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.UrlRewriteFilterPathDescriptor in project knox by apache.
the class HtmlFilterReaderBase method getRuleName.
private String getRuleName(String inputValue) {
if (config != null && !config.getSelectors().isEmpty()) {
for (UrlRewriteFilterPathDescriptor selector : config.getSelectors()) {
if (selector instanceof UrlRewriteFilterApplyDescriptor) {
UrlRewriteFilterApplyDescriptor apply = (UrlRewriteFilterApplyDescriptor) selector;
Matcher matcher = apply.compiledPath(REGEX_COMPILER).matcher(inputValue);
if (matcher.matches()) {
return apply.rule();
}
}
}
}
return null;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterPathDescriptor 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