Search in sources :

Example 11 with UrlRewriteFilterContentDescriptor

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

the class XmlFilterReaderTest method testSimpleStreaming.

@Test
public void testSimpleStreaming() throws IOException, ParserConfigurationException, XMLStreamException {
    UrlRewriteRulesDescriptor rulesConfig = UrlRewriteRulesDescriptorFactory.create();
    UrlRewriteFilterDescriptor filterConfig = rulesConfig.addFilter("filter-1");
    UrlRewriteFilterContentDescriptor contentConfig = filterConfig.addContent("text/xml");
    String inputXml = "<root/>";
    StringReader inputReader = new StringReader(inputXml);
    XmlFilterReader filterReader = new NoopXmlFilterReader(inputReader, contentConfig);
    String outputHtml = new String(IOUtils.toCharArray(filterReader));
    assertThat(the(outputHtml), hasXPath("/root"));
}
Also used : 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 12 with UrlRewriteFilterContentDescriptor

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

the class XmlFilterReaderTest method testBufferedDetectApplyForAttributes.

@Test
public void testBufferedDetectApplyForAttributes() throws Exception {
    InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties-attributes.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");
    UrlRewriteFilterBufferDescriptor bufferConfig = contentConfig.addBuffer("/properties/property");
    UrlRewriteFilterDetectDescriptor detectConfig = bufferConfig.addDetect("@name", "test-name-2");
    UrlRewriteFilterApplyDescriptor applyConfig = detectConfig.addApply("@value", "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", equalTo("test-name-1")));
    assertThat(the(output), hasXPath("/properties/property[1]/@value", equalTo("test-value-1")));
    assertThat(the(output), hasXPath("/properties/property[2]/@name", equalTo("test-name-2")));
    assertThat(the(output), hasXPath("/properties/property[2]/@value", equalTo("attr:test-rule-2{test-value-2}")));
    assertThat(the(output), hasXPath("/properties/property[3]/@name", equalTo("test-name-3")));
    assertThat(the(output), hasXPath("/properties/property[3]/@value", equalTo("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 13 with UrlRewriteFilterContentDescriptor

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

the class XmlFilterReaderTest method testStreamedApplyForAttributes.

@Test
public void testStreamedApplyForAttributes() throws Exception {
    InputStream stream = TestUtils.getResourceStream(this.getClass(), "properties-attributes.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", "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", equalTo("test-name-1")));
    assertThat(the(output), hasXPath("/properties/property[1]/@value", equalTo("attr:test-rule-2{test-value-1}")));
    assertThat(the(output), hasXPath("/properties/property[2]/@name", equalTo("test-name-2")));
    assertThat(the(output), hasXPath("/properties/property[2]/@value", equalTo("attr:test-rule-2{test-value-2}")));
    assertThat(the(output), hasXPath("/properties/property[3]/@name", equalTo("test-name-3")));
    assertThat(the(output), hasXPath("/properties/property[3]/@value", equalTo("attr: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)

Example 14 with UrlRewriteFilterContentDescriptor

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

the class XmlUrlRewriteRulesExporter method createFilter.

private Element createFilter(Document document, UrlRewriteFilterDescriptor parent) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
    Element parentElement = createElement(document, FILTER, parent);
    for (UrlRewriteFilterContentDescriptor child : parent.getContents()) {
        Element childElement = createFilterContent(document, child);
        parentElement.appendChild(childElement);
    }
    return parentElement;
}
Also used : Element(org.w3c.dom.Element) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)

Example 15 with UrlRewriteFilterContentDescriptor

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

the class UrlRewriteRequest method getInputStream.

@Override
public ServletInputStream getInputStream() throws IOException {
    ServletInputStream input = super.getInputStream();
    if (getContentLength() != 0) {
        MimeType mimeType = getMimeType();
        UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig(bodyFilterName, mimeType);
        if (filterContentConfig != null) {
            String asType = filterContentConfig.asType();
            if (asType != null && asType.trim().length() > 0) {
                mimeType = MimeTypes.create(asType, getCharacterEncoding());
            }
        }
        InputStream stream = UrlRewriteStreamFilterFactory.create(mimeType, null, input, rewriter, this, UrlRewriter.Direction.IN, filterContentConfig);
        input = new UrlRewriteRequestStream(stream);
    }
    return input;
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) MimeType(javax.activation.MimeType) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)

Aggregations

UrlRewriteFilterContentDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)28 StringReader (java.io.StringReader)24 Test (org.junit.Test)24 UrlRewriteFilterDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)20 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)20 Matchers.containsString (org.hamcrest.Matchers.containsString)19 InputStream (java.io.InputStream)14 UrlRewriteFilterApplyDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor)12 UrlRewriteFilterBufferDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor)11 UrlRewriteFilterContentDescriptorImpl (org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 UrlRewriteFilterDetectDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDetectDescriptor)3 MimeType (javax.activation.MimeType)2 BufferedInputStream (java.io.BufferedInputStream)1 OutputStream (java.io.OutputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ZipException (java.util.zip.ZipException)1