You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2016/11/16 17:18:08 UTC
knox git commit: KNOX-763 Missing function files
Repository: knox
Updated Branches:
refs/heads/master 7c9b30aad -> 47e89d000
KNOX-763 Missing function files
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/47e89d00
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/47e89d00
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/47e89d00
Branch: refs/heads/master
Commit: 47e89d000106ed505280662a1a2f53c589b24fa4
Parents: 7c9b30a
Author: Sumit Gupta <su...@apache.org>
Authored: Wed Nov 16 12:17:47 2016 -0500
Committer: Sumit Gupta <su...@apache.org>
Committed: Wed Nov 16 12:17:47 2016 -0500
----------------------------------------------------------------------
.../impl/html/HtmlImportFunctionDescriptor.java | 30 +++++++
.../impl/html/HtmlImportFunctionProcessor.java | 89 ++++++++++++++++++++
2 files changed, 119 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/47e89d00/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionDescriptor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionDescriptor.java
new file mode 100644
index 0000000..e5bddfd
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionDescriptor.java
@@ -0,0 +1,30 @@
+/**
+ * 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.api.UrlRewriteFunctionDescriptor;
+
+public class HtmlImportFunctionDescriptor implements UrlRewriteFunctionDescriptor<HtmlImportFunctionDescriptor> {
+
+ public static final String FUNCTION_NAME = "import";
+
+ @Override
+ public String name() {
+ return FUNCTION_NAME;
+ }
+}
http://git-wip-us.apache.org/repos/asf/knox/blob/47e89d00/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessor.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessor.java
new file mode 100644
index 0000000..27d6ef5
--- /dev/null
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlImportFunctionProcessor.java
@@ -0,0 +1,89 @@
+/**
+ * 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.api.FrontendFunctionDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptorFactory;
+import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteFunctionProcessorFactory;
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * This function enhances the 'frontend' function with the ability to add a prefix to the rewritten frontend portion
+ * along with the '@import' literal. This is a workaround for the requirement to provide the ability to rewrite
+ * a portion of html content that contains a tag like the following
+ *
+ * <head> <style type=\"text/css\">@import "pretty.css";</style></head>
+ *
+ * and needs to be rewritten to something like
+ *
+ * <head> <style type=\"text/css\">@import "http://localhost:8443/sandbox/service/pretty.css";</style></head>
+ *
+ * The rewrite rule could then contain the $import function that would delegate to the frontend function.
+ *
+ * If there are more than one params passed, the first one is used as a prefix to the value of the frontend function.
+ *
+ */
+public class HtmlImportFunctionProcessor implements UrlRewriteFunctionProcessor<HtmlImportFunctionDescriptor> {
+
+ private static final String IMPORT_LITERAL = "@import";
+
+ private UrlRewriteFunctionProcessor frontend;
+
+ @Override
+ public void initialize(UrlRewriteEnvironment environment, HtmlImportFunctionDescriptor descriptor) throws Exception {
+ UrlRewriteFunctionDescriptor frontendDescriptor = UrlRewriteFunctionDescriptorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME);
+ frontend = UrlRewriteFunctionProcessorFactory.create(FrontendFunctionDescriptor.FUNCTION_NAME, frontendDescriptor);
+ frontend.initialize(environment, frontendDescriptor);
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ frontend.destroy();
+ }
+
+ @Override
+ public List<String> resolve(UrlRewriteContext context, List<String> parameters) throws Exception {
+ String prefix = "";
+ if ( parameters != null && parameters.size() > 1 ) {
+ prefix = parameters.get(0);
+ parameters = parameters.subList(1, parameters.size());
+ }
+ List<String> frontendValues = frontend.resolve(context, parameters);
+ StringBuffer buffer = new StringBuffer(IMPORT_LITERAL);
+ buffer.append(" ");
+ buffer.append(prefix);
+ if ( frontendValues != null && frontendValues.size() > 0 ) {
+ for ( String value : frontendValues ) {
+ buffer.append(value);
+ }
+ }
+ return Arrays.asList(buffer.toString());
+ }
+
+ @Override
+ public String name() {
+ return HtmlImportFunctionDescriptor.FUNCTION_NAME;
+ }
+
+}