Search in sources :

Example 41 with UrlRewriteRulesDescriptor

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

the class XmlUrlRewriteRulesExporterTest method testSingleNamedRule.

@Test
public void testSingleNamedRule() throws IOException {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    rules.addRule("first").scope("test-scope");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("first")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@scope", is("test-scope")));
}
Also used : StringWriter(java.io.StringWriter) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 42 with UrlRewriteRulesDescriptor

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

the class XmlUrlRewriteRulesExporterTest method testMatchStep.

@Test
public void testMatchStep() throws Exception {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteRuleDescriptor rule = rules.addRule("test-rule").pattern("test-pattern-rule");
    UrlRewriteMatchDescriptor match = rule.addStep("match");
    match.operation("test-operation").pattern("test-pattern-step").flow("all");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("test-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@pattern", is("test-pattern-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule/match)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/@flow", is("ALL")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/@oper", is("test-operation")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/@pattern", is("test-pattern-step")));
}
Also used : UrlRewriteMatchDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor) UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) StringWriter(java.io.StringWriter) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 43 with UrlRewriteRulesDescriptor

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

the class XmlUrlRewriteRulesExporterTest method testNestedStep.

@Test
public void testNestedStep() throws Exception {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteRuleDescriptor rule = rules.addRule("test-rule");
    UrlRewriteMatchDescriptor match = rule.addStep("match");
    UrlRewriteMatchDescriptor matchMatch = match.addStep("match");
    UrlRewriteCheckDescriptor matchCheck = match.addStep("check");
    UrlRewriteControlDescriptor matchControl = match.addStep("control");
    UrlRewriteActionDescriptor matchRewrite = match.addStep("rewrite");
    UrlRewriteCheckDescriptor check = rule.addStep("check");
    UrlRewriteMatchDescriptor checkMatch = check.addStep("match");
    UrlRewriteCheckDescriptor checkCheck = check.addStep("check");
    UrlRewriteControlDescriptor checkControl = check.addStep("control");
    UrlRewriteActionDescriptor checkRewrite = check.addStep("rewrite");
    UrlRewriteControlDescriptor control = rule.addStep("control");
    UrlRewriteMatchDescriptor controlMatch = control.addStep("match");
    UrlRewriteCheckDescriptor controlCheck = control.addStep("check");
    UrlRewriteControlDescriptor controlControl = control.addStep("control");
    UrlRewriteActionDescriptor controlRewrite = control.addStep("rewrite");
    UrlRewriteActionDescriptor rewrite = rule.addStep("rewrite");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("test-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/match/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/check/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/match"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/check"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/control"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/control/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/rewrite"));
}
Also used : UrlRewriteMatchDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteMatchDescriptor) UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) StringWriter(java.io.StringWriter) UrlRewriteControlDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteControlDescriptor) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) UrlRewriteActionDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionDescriptor) UrlRewriteCheckDescriptor(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteCheckDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 44 with UrlRewriteRulesDescriptor

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

the class XmlUrlRewriteRulesExporterTest method testRewriteStep.

@Test
public void testRewriteStep() throws Exception {
    UrlRewriteRulesDescriptor rules = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteRuleDescriptor rule = rules.addRule("test-rule");
    UrlRewriteActionRewriteDescriptorExt step = rule.addStep("rewrite");
    step.operation("test-operation").parameter("test-param");
    StringWriter writer = new StringWriter();
    UrlRewriteRulesDescriptorFactory.store(rules, "xml", writer);
    String str = writer.toString();
    // System.out.println( str );
    Source xml = XmlConverters.the(str);
    assertThat(xml, XmlMatchers.hasXPath("/rules"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule"));
    assertThat(xml, XmlMatchers.hasXPath("count(/rules/rule)", is("1")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/@name", is("test-rule")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/rewrite"));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/rewrite/@oper", is("test-operation")));
    assertThat(xml, XmlMatchers.hasXPath("/rules/rule/rewrite/@template", is("test-param")));
}
Also used : UrlRewriteActionRewriteDescriptorExt(org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt) UrlRewriteRuleDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor) StringWriter(java.io.StringWriter) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 45 with UrlRewriteRulesDescriptor

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

the class XmlUrlRewriteRulesImporter method load.

@Override
public UrlRewriteRulesDescriptor load(Reader reader) throws IOException {
    Digester digester = loader.newDigester(new ExtendedBaseRules());
    digester.setValidating(false);
    try {
        UrlRewriteRulesDescriptor rules = digester.parse(reader);
        return rules;
    } catch (SAXException e) {
        throw new IOException(e);
    }
}
Also used : ExtendedBaseRules(org.apache.commons.digester3.ExtendedBaseRules) Digester(org.apache.commons.digester3.Digester) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)46 Test (org.junit.Test)38 StringReader (java.io.StringReader)20 UrlRewriteFilterContentDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)20 UrlRewriteFilterDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)20 Matchers.containsString (org.hamcrest.Matchers.containsString)19 InputStream (java.io.InputStream)16 UrlRewriteRuleDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor)13 UrlRewriteFilterApplyDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor)12 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)11 UrlRewriteFilterBufferDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor)11 UrlRewriteProcessor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteProcessor)11 UrlRewriteActionRewriteDescriptorExt (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt)9 StringWriter (java.io.StringWriter)8 Resolver (org.apache.knox.gateway.util.urltemplate.Resolver)8 Template (org.apache.knox.gateway.util.urltemplate.Template)8 URL (java.net.URL)7 Source (javax.xml.transform.Source)6 IOException (java.io.IOException)5 GatewayServices (org.apache.knox.gateway.services.GatewayServices)5