use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor in project knox by apache.
the class JsonFilterReader method filterBufferedValues.
private void filterBufferedValues(Level node, List<UrlRewriteFilterPathDescriptor> selectors) {
for (UrlRewriteFilterPathDescriptor selector : selectors) {
JsonPath.Expression path = (JsonPath.Expression) selector.compiledPath(JPATH_COMPILER);
List<JsonPath.Match> matches = path.evaluate(node.node);
for (JsonPath.Match match : matches) {
if (match.getNode().isTextual()) {
if (selector instanceof UrlRewriteFilterApplyDescriptor) {
filterBufferedValue(match, (UrlRewriteFilterApplyDescriptor) selector);
}
}
}
}
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor in project knox by apache.
the class XmlFilterReader method streamAttribute.
private void streamAttribute(Element element, Attribute attribute) throws XPathExpressionException {
Attr node;
QName name = attribute.getName();
String prefix = name.getPrefix();
String uri = name.getNamespaceURI();
if (uri == null || uri.isEmpty()) {
node = document.createAttribute(name.getLocalPart());
element.setAttributeNode(node);
} else {
node = document.createAttributeNS(uri, name.getLocalPart());
if (prefix != null && !prefix.isEmpty()) {
node.setPrefix(prefix);
}
element.setAttributeNodeNS(node);
}
String value = attribute.getValue();
Level level = stack.peek();
if ((level.scopeConfig) == null || (level.scopeConfig.getSelectors().isEmpty())) {
value = filterAttribute(null, attribute.getName(), value, null);
node.setValue(value);
} else {
UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath(level);
if (path instanceof UrlRewriteFilterApplyDescriptor) {
String rule = ((UrlRewriteFilterApplyDescriptor) path).rule();
value = filterAttribute(null, attribute.getName(), value, rule);
node.setValue(value);
}
}
if (prefix == null || prefix.isEmpty()) {
writer.write(" ");
writer.write(name.getLocalPart());
} else {
writer.write(" ");
writer.write(prefix);
writer.write(":");
writer.write(name.getLocalPart());
}
writer.write("=\"");
writer.write(value);
writer.write("\"");
element.removeAttributeNode(node);
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor in project knox by apache.
the class UrlRewriteFilterGroupDescriptorBase method addApply.
@Override
public UrlRewriteFilterApplyDescriptor addApply(String path, String rule) {
UrlRewriteFilterApplyDescriptor apply = new UrlRewriteFilterApplyDescriptorImpl();
apply.path(path);
apply.rule(rule);
addSelector(apply);
return apply;
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor in project knox by apache.
the class JsonFilterReaderTest method testBufferedDetectApply.
@Test
public void testBufferedDetectApply() throws IOException {
InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties.json");
String input = IOUtils.toString(stream, Charset.forName("UTF-8"));
// System.out.println( "INPUT=" + input );
UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/json");
UrlRewriteFilterBufferDescriptor bufferConfig = contentConfig.addBuffer("$.name<properties>.*.name<property>");
UrlRewriteFilterDetectDescriptor detectConfig = bufferConfig.addDetect("$.name<property-name>", "test-name-2");
UrlRewriteFilterApplyDescriptor applyConfig = detectConfig.addApply("$.name<property-value>", "test-rule-2");
// UrlRewriteRulesDescriptorFactory.store( rulesConfig, "xml", new PrintWriter( System.out ) );
JsonFilterReader filter = new TestJsonFilterReader(new StringReader(input), contentConfig);
String output = IOUtils.toString(filter);
// System.out.println( "OUTPUT=" + output );
JsonAssert.with(output).assertThat("name<properties>[0].name<property>.name<property-name>", is("test-name-1"));
JsonAssert.with(output).assertThat("name<properties>[0].name<property>.name<property-value>", is("test-value-1"));
JsonAssert.with(output).assertThat("name<properties>[1].name<property>.name<property-name>", is("test-name-2"));
JsonAssert.with(output).assertThat("name<properties>[1].name<property>.name<property-value>", is("value:test-rule-2<test-value-2>"));
JsonAssert.with(output).assertThat("name<properties>[2].name<property>.name<property-name>", is("test-name-3"));
JsonAssert.with(output).assertThat("name<properties>[2].name<property>.name<property-value>", is("test-value-3"));
}
use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor in project knox by apache.
the class JsonFilterReaderTest method testBufferedApply.
@Test
public void testBufferedApply() throws IOException {
InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties.json");
String input = IOUtils.toString(stream, Charset.forName("UTF-8"));
// System.out.println( "INPUT=" + input );
UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/json");
UrlRewriteFilterBufferDescriptor bufferConfig = contentConfig.addBuffer("$.name<properties>.*.name<property>");
UrlRewriteFilterApplyDescriptor applyConfig = bufferConfig.addApply("$.name<property-value>", "test-rule");
// UrlRewriteRulesDescriptorFactory.store( rulesConfig, "xml", new PrintWriter( System.out ) );
JsonFilterReader filter = new TestJsonFilterReader(new StringReader(input), contentConfig);
String output = IOUtils.toString(filter);
// System.out.println( "OUTPUT=" + output );
JsonAssert.with(output).assertThat("name<properties>[0].name<property>.name<property-name>", is("test-name-1"));
JsonAssert.with(output).assertThat("name<properties>[0].name<property>.name<property-value>", is("value:test-rule<test-value-1>"));
JsonAssert.with(output).assertThat("name<properties>[1].name<property>.name<property-name>", is("test-name-2"));
JsonAssert.with(output).assertThat("name<properties>[1].name<property>.name<property-value>", is("value:test-rule<test-value-2>"));
JsonAssert.with(output).assertThat("name<properties>[2].name<property>.name<property-name>", is("test-name-3"));
JsonAssert.with(output).assertThat("name<properties>[2].name<property>.name<property-value>", is("value:test-rule<test-value-3>"));
}
Aggregations