You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by lm...@apache.org on 2017/05/27 20:14:04 UTC

knox git commit: KNOX-751 - Need rewrite function to capture href information from single page host to rewrite output of node hosts (Jeffrey E Rodriguez via lmccay)

Repository: knox
Updated Branches:
  refs/heads/master 771a2fc0d -> e4768f1ef


KNOX-751 - Need rewrite function to capture href information from single page host to rewrite output of node hosts (Jeffrey E Rodriguez via lmccay)

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

Branch: refs/heads/master
Commit: e4768f1efce860099c6a1f8d366e2a58954c0314
Parents: 771a2fc
Author: Larry McCay <lm...@hortonworks.com>
Authored: Sat May 27 16:13:55 2017 -0400
Committer: Larry McCay <lm...@hortonworks.com>
Committed: Sat May 27 16:13:55 2017 -0400

----------------------------------------------------------------------
 .../pom.xml                                     | 106 ++++++++++++++
 .../api/InboundUrlFunctionDescriptor.java       |  31 ++++
 .../impl/InboundUrlFunctionProcessor.java       |  60 ++++++++
 ...ter.rewrite.api.UrlRewriteFunctionDescriptor |  19 +++
 ...lter.rewrite.spi.UrlRewriteFunctionProcessor |  19 +++
 .../api/InboundUrlFunctionDescriptorTest.java   |  48 +++++++
 .../impl/InboundUrlFunctionProcessorTest.java   | 140 +++++++++++++++++++
 .../filter/rewrite/impl/UrlRewriteResponse.java |  13 +-
 gateway-release/pom.xml                         |   5 +
 pom.xml                                         |   6 +
 10 files changed, 446 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/pom.xml b/gateway-provider-rewrite-func-inbound-query-param/pom.xml
new file mode 100644
index 0000000..0fa9ad1
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/pom.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.knox</groupId>
+        <artifactId>gateway</artifactId>
+        <version>0.13.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>gateway-provider-rewrite-func-inbound-query-param</artifactId>
+    <name>gateway-provider-rewrite-func-inbound-url</name>
+    <description>An extension to the URL rewriter that provides a way to get the inbound service URL.</description>
+
+    <licenses>
+        <license>
+            <name>The Apache Software License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-i18n</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-spi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-provider-rewrite</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jboss.shrinkwrap</groupId>
+            <artifactId>shrinkwrap-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.shrinkwrap</groupId>
+            <artifactId>shrinkwrap-impl-base</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+            <artifactId>shrinkwrap-descriptors-api-javaee</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+            <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
+        </dependency>
+
+        <!-- ********** ********** ********** ********** ********** ********** -->
+        <!-- ********** Test Dependencies                           ********** -->
+        <!-- ********** ********** ********** ********** ********** ********** -->
+
+        <dependency>
+            <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-test-utils</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-library</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <!-- This must be after restassured otherwise is messes up the hamcrest dependencies. -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptor.java b/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptor.java
new file mode 100644
index 0000000..5ba2e11
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptor.java
@@ -0,0 +1,31 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.inboundurl.api;
+
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
+
+public class InboundUrlFunctionDescriptor implements UrlRewriteFunctionDescriptor<InboundUrlFunctionDescriptor> {
+
+  public static final String FUNCTION_NAME = "inboundurl";
+
+  @Override
+  public String name() {
+    return FUNCTION_NAME;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessor.java b/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessor.java
new file mode 100644
index 0000000..e26d81e
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/main/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessor.java
@@ -0,0 +1,60 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.inboundurl.impl;
+
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext;
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.apache.hadoop.gateway.inboundurl.api.InboundUrlFunctionDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponse;
+
+import java.util.Collections;
+import java.util.List;
+
+public class InboundUrlFunctionProcessor
+    implements UrlRewriteFunctionProcessor<InboundUrlFunctionDescriptor> {
+
+  @Override
+  public String name() {
+    return InboundUrlFunctionDescriptor.FUNCTION_NAME;
+  }
+
+  @Override
+  public void initialize( UrlRewriteEnvironment environment, InboundUrlFunctionDescriptor descriptor ) throws Exception {
+  }
+
+  @Override
+  public void destroy() throws Exception {
+  }
+
+  @Override
+  public List<String> resolve( UrlRewriteContext context, List<String> parameters ) throws Exception {
+      if( parameters == null || parameters.size() == 0 ) {
+        return Collections.emptyList();
+      } else {
+        switch( context.getDirection() ) {
+          case IN:
+            return Collections.emptyList();
+          case OUT:
+            return context.getParameters().resolve( UrlRewriteResponse.INBOUND_QUERY_PARAM_PREFIX + parameters.get( 0 ));
+          default:
+            return Collections.emptyList();
+        }
+      }
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor b/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
new file mode 100644
index 0000000..42aa9f6
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor
@@ -0,0 +1,19 @@
+##########################################################################
+# 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
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+##########################################################################
+
+org.apache.hadoop.gateway.inboundurl.api.InboundUrlFunctionDescriptor

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor b/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
new file mode 100644
index 0000000..c9f09b6
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/main/resources/META-INF/services/org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor
@@ -0,0 +1,19 @@
+##########################################################################
+# 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
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+##########################################################################
+
+org.apache.hadoop.gateway.inboundurl.impl.InboundUrlFunctionProcessor

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
new file mode 100644
index 0000000..59d1f8a
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/api/InboundUrlFunctionDescriptorTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.inboundurl.api;
+
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteFunctionDescriptor;
+import org.junit.Test;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+public class InboundUrlFunctionDescriptorTest {
+
+  @Test
+  public void testServiceLoader() throws Exception {
+    ServiceLoader loader = ServiceLoader.load( UrlRewriteFunctionDescriptor.class );
+    Iterator iterator = loader.iterator();
+    assertThat( "Service iterator empty.", iterator.hasNext() );
+    while( iterator.hasNext() ) {
+      Object object = iterator.next();
+      if( object instanceof InboundUrlFunctionDescriptor ) {
+        String name = ((InboundUrlFunctionDescriptor)object).name();
+        assertThat( name, is("inboundurl"));
+        return;
+      }
+    }
+    fail( "Failed to find " + InboundUrlFunctionDescriptor.class.getName() + " via service loader." );
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
new file mode 100644
index 0000000..f78bf50
--- /dev/null
+++ b/gateway-provider-rewrite-func-inbound-query-param/src/test/java/org/apache/hadoop/gateway/inboundurl/impl/InboundUrlFunctionProcessorTest.java
@@ -0,0 +1,140 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.inboundurl.impl;
+
+import com.google.common.collect.Lists;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteRulesDescriptorFactory;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriter;
+import org.apache.hadoop.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt;
+import org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteFunctionProcessor;
+import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponse;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteProcessor;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletContextListener;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
+import org.apache.hadoop.gateway.services.GatewayServices;
+import org.apache.hadoop.gateway.util.urltemplate.Parser;
+import org.apache.hadoop.gateway.util.urltemplate.Resolver;
+import org.apache.hadoop.gateway.util.urltemplate.Template;
+import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteContextImpl;
+import org.junit.Test;
+
+import java.util.*;
+
+import org.easymock.EasyMock;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+public class InboundUrlFunctionProcessorTest {
+
+  @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 InboundUrlFunctionProcessor ) {
+        return;
+      }
+    }
+    fail( "Failed to find " + InboundUrlFunctionProcessor.class.getName() + " via service loader." );
+  }
+
+  @Test
+  public void testServiceResolve() throws Exception {
+    ServiceLoader loader = ServiceLoader.load( UrlRewriteFunctionProcessor.class );
+    Iterator iterator = loader.iterator();
+    assertThat( "Service iterator empty.", iterator.hasNext() );
+    InboundUrlFunctionProcessor proc = null;
+    while( iterator.hasNext() ) {
+      Object object = iterator.next();
+      if( object instanceof InboundUrlFunctionProcessor ) {
+        proc = (InboundUrlFunctionProcessor) object ;
+      }
+    }
+    if( proc == null )
+      fail( "Failed to find " + InboundUrlFunctionProcessor.class.getName() + " via service loader." );
+
+    Map<String,UrlRewriteFunctionProcessor> functions = new HashMap<>();
+    UrlRewriteEnvironment environment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
+    UrlRewriter.Direction direction = UrlRewriter.Direction.OUT;
+
+    List<String> parameters = Collections.singletonList("host");
+
+    Template template = Parser.parseLiteral( "https://localhost:8443/gateway/default/datanode/?host=http://foo:50075" );
+    UrlRewriteContextImpl ctx = new UrlRewriteContextImpl( environment, this.getRewriteResponse(), functions, direction, template );
+
+    List<String> result = proc.resolve(ctx, parameters);
+    assertThat( result.get(0), is( "http://foo:50075" ) );
+  }
+
+  private UrlRewriteResponse getRewriteResponse() throws Exception {
+    UrlRewriteProcessor rewriter = EasyMock.createNiceMock( UrlRewriteProcessor.class );
+    EasyMock.expect( rewriter.getConfig() ).andReturn( null ).anyTimes();
+
+    ServletContext context = EasyMock.createNiceMock( ServletContext.class );
+    EasyMock.expect( context.getAttribute( UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME ) ).andReturn( rewriter ).anyTimes();
+
+    FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
+    EasyMock.expect( config.getInitParameter( UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM ) ).andReturn( "test-filter" ).anyTimes();
+    EasyMock.expect( config.getServletContext() ).andReturn( context ).anyTimes();
+
+    HttpServletRequest request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getParameterValues("host" ) ).andReturn( new String[]{"http://foo:50075"}  ).anyTimes();
+
+    HttpServletResponse response = EasyMock.createNiceMock( HttpServletResponse.class );
+
+    EasyMock.replay( rewriter, context, config, request, response );
+
+    return new UrlRewriteResponse( config, request, response );
+  }
+
+
+  @Test
+  public void testQueryParam() throws Exception {
+    GatewayServices gatewayServices = EasyMock.createNiceMock( GatewayServices.class );
+    UrlRewriteEnvironment environment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
+    EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();
+    EasyMock.expect( environment.resolve( "cluster.name" ) ).andReturn(Collections.singletonList("test-cluster-name")).anyTimes();
+
+    Resolver resolver = EasyMock.createNiceMock( Resolver.class );
+    EasyMock.expect( resolver.resolve( "query.param.host" ) ).andReturn( Lists.newArrayList( "http://foo:50075" ) ).anyTimes();
+    EasyMock.replay( gatewayServices, environment, resolver );
+
+    UrlRewriteRulesDescriptor descriptor = UrlRewriteRulesDescriptorFactory.create();
+    UrlRewriteRuleDescriptor rule = descriptor.addRule( "test-location" );
+    rule.pattern( "{*}://{*}:{*}/{**}/?{**}" );
+    UrlRewriteActionRewriteDescriptorExt rewrite = rule.addStep( "rewrite" );
+    rewrite.template( "{$inboundurl[host]}" );
+    UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
+    rewriter.initialize( environment, descriptor );
+    Template input = Parser.parseLiteral( "https://localhost:8443/gateway/default/datanode/?host=http://foo:50075" );
+    Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.OUT, "test-location" );
+    assertThat( output.toString(), is( "http://foo:50075" ) );
+  }
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index af280cd..35ab677 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -77,6 +77,7 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
   private static final String REQUEST_PARAM_PREFIX = "request.";
   private static final String CLUSTER_PARAM_PREFIX = "cluster.";
   private static final String GATEWAY_PARAM_PREFIX = "gateway.";
+  public  static final String INBOUND_QUERY_PARAM_PREFIX   = "query.param.";
 
   private UrlRewriter rewriter;
   private FilterConfig config;
@@ -219,7 +220,9 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
       return Arrays.asList( getGatewayParam( name.substring( GATEWAY_PARAM_PREFIX.length() ) ) );
     } else if ( name.startsWith( CLUSTER_PARAM_PREFIX ) ) {
       return Arrays.asList( getClusterParam( name.substring( GATEWAY_PARAM_PREFIX.length() ) ) );
-    }  else {
+    } else if ( name.startsWith( INBOUND_QUERY_PARAM_PREFIX ) ) {
+      return getInboundQueryParam(name.substring(INBOUND_QUERY_PARAM_PREFIX.length()));
+    } else {
       return Arrays.asList( config.getInitParameter( name ) );
     }
   }
@@ -272,6 +275,14 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
     }
   }
 
+  private List <String> getInboundQueryParam(String name ){
+     List <String> inboundHosts = null;
+     if( this.request!=null )
+       inboundHosts =
+         Arrays.asList( this.request.getParameterValues(name));
+     return inboundHosts;
+  }
+
   private String getRequestParam( String name ) {
     if( "host".equals( name ) ) {
       return request.getServerName();

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/gateway-release/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-release/pom.xml b/gateway-release/pom.xml
index ab76e8e..427faa5 100644
--- a/gateway-release/pom.xml
+++ b/gateway-release/pom.xml
@@ -232,6 +232,11 @@
         </dependency>
         <dependency>
             <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-provider-rewrite-func-inbound-query-param</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>${gateway-group}</groupId>
             <artifactId>gateway-provider-security-picketlink</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/knox/blob/e4768f1e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ed60339..3383caf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,6 +51,7 @@
         <module>gateway-provider-rewrite</module>
         <module>gateway-provider-rewrite-func-hostmap-static</module>
         <module>gateway-provider-rewrite-func-service-registry</module>
+        <module>gateway-provider-rewrite-func-inbound-query-param</module>
         <module>gateway-provider-rewrite-step-secure-query</module>
         <module>gateway-provider-rewrite-step-encrypt-uri</module>
         <module>gateway-provider-security-jwt</module>
@@ -547,6 +548,11 @@
             </dependency>
             <dependency>
                 <groupId>${gateway-group}</groupId>
+                <artifactId>gateway-provider-rewrite-func-inbound-query-param</artifactId>
+                <version>${gateway-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${gateway-group}</groupId>
                 <artifactId>gateway-provider-rewrite-step-secure-query</artifactId>
                 <version>${gateway-version}</version>
             </dependency>