knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject knox git commit: KNOX-763 Added import rewrite function for html content containing @import
Date Wed, 16 Nov 2016 17:01:30 GMT
Repository: knox
Updated Branches:
  refs/heads/master 13cea0c5e -> 7c9b30aad


KNOX-763 Added import rewrite function for html content containing @import


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/7c9b30aa
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/7c9b30aa
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/7c9b30aa

Branch: refs/heads/master
Commit: 7c9b30aad4ec45c0d4434a24a1332129ceb9e29b
Parents: 13cea0c
Author: Sumit Gupta <sumit@apache.org>
Authored: Wed Nov 16 11:58:48 2016 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Wed Nov 16 11:58:48 2016 -0500

----------------------------------------------------------------------
 ...ter.rewrite.api.UrlRewriteFunctionDescriptor |  3 +-
 ...lter.rewrite.spi.UrlRewriteFunctionProcessor |  3 +-
 .../api/UrlRewriteServletFilterTest.java        | 35 ++++++-------
 .../html/HtmlImportFunctionProcessorTest.java   | 52 ++++++++++++++++++++
 .../api/UrlRewriteServletFilterTest/rewrite.xml |  2 +-
 .../gateway/util/urltemplate/Function.java      |  2 +-
 6 files changed, 74 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
index 0e73b31..e5ccde7 100644
--- a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
+++ b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
@@ -16,4 +16,5 @@
 # limitations under the License.
 ##########################################################################
 
-org.apache.hadoop.gateway.filter.rewrite.api.FrontendFunctionDescriptor
\ No newline at end of file
+org.apache.hadoop.gateway.filter.rewrite.api.FrontendFunctionDescriptor
+org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlImportFunctionDescriptor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
index 7757ed6..16731b8 100644
--- a/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
+++ b/gateway-provider-rewrite/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
@@ -16,4 +16,5 @@
 # limitations under the License.
 ##########################################################################
 
-org.apache.hadoop.gateway.filter.rewrite.impl.FrontendFunctionProcessor
\ No newline at end of file
+org.apache.hadoop.gateway.filter.rewrite.impl.FrontendFunctionProcessor
+org.apache.hadoop.gateway.filter.rewrite.impl.html.HtmlImportFunctionProcessor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
index 1950bf3..8052c2b 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
@@ -54,6 +54,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anyOf;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.fail;
@@ -767,26 +768,21 @@ public class UrlRewriteServletFilterTest {
     //initParams.put( "response", "" );
     setUp( initParams );
 
-    String responseHtml = "<!DOCTYPE html>\n" +
-                          "<html>\n" +
-                          "  <head>\n" +
-                          "    <meta charset=\"UTF-8\">\n" +
+    String responseHtml = "<html>" +
+                          "  <head>" +
                           "    <style type=\"text/css\">@import \"pretty.css\";</style>"
+
-                          "    <script src=\"script.js\"></script>\n" +
-                          "  </head>\n" +
-                          "  <body>\n" +
-                          "  </body>\n" +
+                          "  </head>" +
+                          "</html>";
+    String responseHtmlOne = "<html>" +
+                          "  <head>" +
+                          "    <style type=\"text/css\">@import \"http://0.0.0.0:0/stylesheets/pretty.css\";</style>"
+
+                          "  </head>" +
+                          "</html>";
+    String responseHtmlTwo = "<html>" +
+                          "  <head>" +
+                          "    <style type=\"text/css\">@import \"http://localhost:0/stylesheets/pretty.css\";</style>"
+
+                          "  </head>" +
                           "</html>";
-    String rewrittenResponseHtml = "<!DOCTYPE html>\n" +
-                                   "<html>\n" +
-                                   "  <head>\n" +
-                                   "    <meta charset=\"UTF-8\">\n" +
-                                   "    <style type=\"text/css\">@import \"http://someotherhost/stylesheets/pretty.css\";</style>"
+
-                                   "    <script src=\"script.js\"></script>\n"
+
-                                   "  </head>\n" +
-                                   "  <body>\n" +
-                                   "  </body>\n" +
-                                   "</html>";
 
     // Setup the server side request/response interaction.
     interaction.expect()
@@ -807,7 +803,8 @@ public class UrlRewriteServletFilterTest {
 
     assertThat( response.getStatus(), is( 200 ) );
     String content = response.getContent();
-    assertThat(content, is(rewrittenResponseHtml));
+//    assertThat( the( content ), hasXPath( "//style/text()", equalTo( "@import \\\"http://0.0.0.0:0/stylesheets/pretty.css\\\";"
) ) );
+    assertThat(content, anyOf( is(responseHtmlOne), is(responseHtmlTwo)));
   }
 
   private static class SetupFilter implements Filter {

http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessorTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessorTest.java
new file mode 100644
index 0000000..e26d584
--- /dev/null
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessorTest.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.gateway.filter.rewrite.impl.html;
+
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.fail;
+
+public class HtmlImportFunctionProcessorTest {
+
+  @SuppressWarnings("rawtypes")
+  @Test
+  public void testServiceLoader() throws Exception {
+    ServiceLoader loader = ServiceLoader.load( UrlRewriteFunctionProcessor.class );
+    Iterator iterator = loader.iterator();
+    assertThat( "Service iterator empty.", iterator.hasNext() );
+    while( iterator.hasNext() ) {
+      Object object = iterator.next();
+      if( object instanceof HtmlImportFunctionProcessor ) {
+        return;
+      }
+    }
+    fail( "Failed to find " + HtmlImportFunctionProcessor.class.getName() + " via service
loader." );
+  }
+
+  @Test
+  public void testName() throws Exception {
+    HtmlImportFunctionProcessor processor = new HtmlImportFunctionProcessor();
+    assertThat( processor.name(), is( "import" ) );
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
index 72a7ecc..b979545 100644
--- a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
+++ b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
@@ -54,7 +54,7 @@
     </rule>
 
     <rule name="test-rule-html-import-attribute">
-        <rewrite template="@import &quot;http://someotherhost/stylesheets/pretty.css&quot;;"/>
+        <rewrite template="{$import[&quot;, url]}/stylesheets/pretty.css&quot;;"/>
     </rule>
 
     <filter name="test-filter-1">

http://git-wip-us.apache.org/repos/asf/knox/blob/7c9b30aa/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Function.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Function.java
b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Function.java
index cbe38eb..092013f 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Function.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Function.java
@@ -79,7 +79,7 @@ class Function {
               if( "$".equals( token ) || "(".equals( token ) || ")".equals( token ) || "[".equals(
token ) || "]".equals( token ) ) {
                 // Ignore it.
               } else {
-                paramValue = Arrays.asList( token );
+                paramValue = Arrays.asList(token.split(","));
               }
               return;
           }


Mime
View raw message