Search in sources :

Example 1 with UrlRewriteRulesDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor 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"));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) InputStream(java.io.InputStream) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) UrlRewriteFilterDetectDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor) Test(org.junit.Test)

Example 2 with UrlRewriteRulesDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor 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>"));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) InputStream(java.io.InputStream) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 3 with UrlRewriteRulesDescriptor

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

the class JsonFilterReaderTest method testValueNumberWithBuffering.

@Test
public void testValueNumberWithBuffering() throws Exception {
    String input = "{ \"apps\" : {\"app\":[{\"id\":\"one\", \"progress\":100.0, \"startedTime\":1399975176760}]} }";
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/json");
    UrlRewriteFilterBufferDescriptor bufferConfig = contentConfig.addBuffer("$.apps.app[*]");
    UrlRewriteFilterApplyDescriptor applyConfig = bufferConfig.addApply("$.id", "test-rule");
    JsonFilterReader filter = new JsonFilterReader(new StringReader(input), contentConfig);
    String output = IOUtils.toString(filter);
    assertThat(output, containsString("\"startedTime\":1399975176760}"));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 4 with UrlRewriteRulesDescriptor

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

the class XmlFilterReaderTest method testSimpleAttributeBuffered.

@Test
public void testSimpleAttributeBuffered() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    UrlRewriteFilterBufferDescriptor scopeConfig = contentConfig.addBuffer("/root");
    String inputXml = "<root name='value'/>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    // System.out.println( outputHtml );
    assertThat(the(outputHtml), hasXPath("/root/@name", equalTo("value")));
}
Also used : UrlRewriteFilterBufferDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 5 with UrlRewriteRulesDescriptor

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

the class XmlFilterReaderTest method testStreamedApplyForElements.

@Test
public void testStreamedApplyForElements() throws Exception {
    InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties-elements.xml");
    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/xml");
    UrlRewriteFilterApplyDescriptor applyConfig = contentConfig.addApply("/properties/property/value/text()", "test-rule-2");
    // UrlRewriteRulesDescriptorFactory.store( rulesConfig, "xml", new PrintWriter( System.out ) );
    XmlFilterReader filter = new TestXmlFilterReader(new StringReader(input), contentConfig);
    String output = IOUtils.toString(filter);
    // System.out.println( "OUTPUT=" + output );
    assertThat(the(output), hasXPath("/properties/property[1]/name/text()", equalTo("test-name-1")));
    assertThat(the(output), hasXPath("/properties/property[1]/value/text()", equalTo("text:test-rule-2{test-value-1}")));
    assertThat(the(output), hasXPath("/properties/property[2]/name/text()", equalTo("test-name-2")));
    assertThat(the(output), hasXPath("/properties/property[2]/value/text()", equalTo("text:test-rule-2{test-value-2}")));
    assertThat(the(output), hasXPath("/properties/property[3]/name/text()", equalTo("test-name-3")));
    assertThat(the(output), hasXPath("/properties/property[3]/value/text()", equalTo("text:test-rule-2{test-value-3}")));
}
Also used : InputStream(java.io.InputStream) StringReader(java.io.StringReader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) UrlRewriteFilterApplyDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor) UrlRewriteFilterDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

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