knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject [3/3] knox git commit: KNOX-394: Request and response URLs must be parsed as literals not templates
Date Tue, 03 Nov 2015 04:52:03 GMT
KNOX-394: Request and response URLs must be parsed as literals not templates


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

Branch: refs/heads/master
Commit: 33bb1ce5727a54721baec0125dd1254d275160ac
Parents: 1755fdf
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Mon Nov 2 23:46:52 2015 -0500
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Mon Nov 2 23:46:52 2015 -0500

----------------------------------------------------------------------
 .../function/UsernameFunctionProcessorTest.java |   2 +-
 .../impl/HostmapFunctionProcessorTest.java      |  14 +-
 .../impl/ServiceAddressFunctionProcessor.java   |   2 +-
 .../impl/ServiceHostFunctionProcessor.java      |   2 +-
 .../ServiceMappedAddressFunctionProcessor.java  |   2 +-
 .../ServiceMappedHostFunctionProcessor.java     |   2 +-
 .../impl/ServicePathFunctionProcessor.java      |   2 +-
 .../impl/ServicePortFunctionProcessor.java      |   2 +-
 .../impl/ServiceSchemeFunctionProcessor.java    |   2 +-
 .../impl/ServiceRegistryFunctionsTest.java      |   2 +-
 .../encrypturi/impl/DecryptUriProcessor.java    |   2 +-
 .../encrypturi/impl/EncryptUriProcessor.java    |   2 +-
 .../securequery/SecureQueryDecodeProcessor.java |   4 +-
 .../SecureQueryDecryptProcessor.java            |   4 +-
 .../securequery/SecureQueryEncodeProcessor.java |   2 +-
 .../SecureQueryEncryptProcessor.java            |   2 +-
 .../SecureQueryDecodeProcessorTest.java         |   4 +-
 .../SecureQueryEncodeProcessorTest.java         |   2 +-
 .../SecureQueryEncryptDecryptProcessorTest.java |   2 +-
 .../UrlRewriteActionRewriteProcessorExt.java    |   4 +-
 .../ext/UrlRewriteMatchDescriptorExt.java       |   2 +-
 .../filter/rewrite/impl/UrlRewriteRequest.java  |   4 +-
 .../filter/rewrite/impl/UrlRewriteResponse.java |   2 +-
 .../impl/UrlRewriteRuleDescriptorImpl.java      |   2 +-
 .../impl/form/FormUrlRewriteFilterReader.java   |   2 +-
 .../impl/html/HtmlUrlRewriteFilterReader.java   |   2 +-
 .../JavaScriptUrlRewriteFilterReader.java       |   2 +-
 .../impl/json/JsonUrlRewriteFilterReader.java   |   2 +-
 .../impl/xml/XmlUrlRewriteFilterReader.java     |   2 +-
 .../rewrite/api/UrlRewriteProcessorTest.java    |  16 +-
 .../api/UrlRewriteServletFilterTest.java        |   2 +-
 .../impl/FrontendFunctionProcessorTest.java     |   2 +-
 .../rewrite/impl/UrlRewriteContextImplTest.java |   2 +-
 .../rewrite/impl/xml/XmlFilterReaderTest.java   |  11 +
 .../apache/hadoop/gateway/GatewayFilter.java    |   6 +-
 .../gateway/dispatch/UrlConnectionDispatch.java |   4 +-
 .../resources/services/oozie/4.0.0/rewrite.xml  |   5 +-
 .../java/org/apache/hadoop/test/TestUtils.java  |  48 +++
 .../gateway/OozieServiceDefinitionTest.java     | 148 +++++++++
 .../oozie-request-relative.xml                  |  14 +
 .../oozie-request-with-var.xml                  |  14 +
 .../gateway/util/urltemplate/Builder.java       |  50 +--
 .../gateway/util/urltemplate/Expander.java      |   2 +-
 .../gateway/util/urltemplate/Fragment.java      |   4 +-
 .../hadoop/gateway/util/urltemplate/Host.java   |   4 +-
 .../hadoop/gateway/util/urltemplate/Parser.java | 114 ++++---
 .../gateway/util/urltemplate/Password.java      |   4 +-
 .../hadoop/gateway/util/urltemplate/Path.java   |   4 +-
 .../hadoop/gateway/util/urltemplate/Port.java   |   4 +-
 .../hadoop/gateway/util/urltemplate/Query.java  |   4 +-
 .../gateway/util/urltemplate/Rewriter.java      |   2 +-
 .../hadoop/gateway/util/urltemplate/Scheme.java |   4 +-
 .../gateway/util/urltemplate/Segment.java       |   4 +-
 .../hadoop/gateway/util/urltemplate/Token.java  |  12 +-
 .../gateway/util/urltemplate/Username.java      |   4 +-
 .../gateway/util/urltemplate/ExpanderTest.java  | 162 +++++++---
 .../gateway/util/urltemplate/MatcherTest.java   | 320 +++++++++----------
 .../gateway/util/urltemplate/ParserTest.java    | 198 +++++++-----
 .../gateway/util/urltemplate/RewriterTest.java  | 100 +++---
 .../gateway/util/urltemplate/SegmentTest.java   |  26 +-
 .../gateway/util/urltemplate/TemplateTest.java  |  49 +--
 .../gateway/util/urltemplate/TokenTest.java     |   2 +-
 62 files changed, 897 insertions(+), 528 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
index ebbe6ec..3cc81a8 100644
--- a/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
+++ b/gateway-provider-identity-assertion-common/src/test/java/org/apache/hadoop/gateway/identityasserter/function/UsernameFunctionProcessorTest.java
@@ -223,7 +223,7 @@ public class UsernameFunctionProcessorTest {
       try {
         request.setAttribute(
             AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME,
-            Parser.parse( sourceUrl.toString() ) );
+            Parser.parseLiteral( sourceUrl.toString() ) );
       } catch( URISyntaxException e ) {
         throw new ServletException( e );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java b/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
index be738e9..67290fb 100644
--- a/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
+++ b/gateway-provider-rewrite-func-hostmap-static/src/test/java/org/apache/hadoop/gateway/hostmap/impl/HostmapFunctionProcessorTest.java
@@ -91,7 +91,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
+    Template input = Parser.parseLiteral( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.IN, null );
     //System.out.println( output );
     assertThat( output, notNullValue() );
@@ -117,7 +117,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse(
+    Template input = Parser.parseLiteral(
         "test-scheme://test-external-host:42/test-path/test-file?test-name-1=test-value-1&test-name-2=test-value-2" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.OUT, "test-rule" );
     //System.out.println( output );
@@ -151,7 +151,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse(
+    Template input = Parser.parseLiteral(
         "test-scheme://test-external-host:42/test-path/test-file?qp1=qp1-val&qp2=qp2-val&test-name-1=test-value-1&test-name-2=test-value-2" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.OUT, "test-rule" );
     //System.out.println( output );
@@ -185,7 +185,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse(
+    Template input = Parser.parseLiteral(
         "test-scheme://test-inbound-unmapped-host:42/test-path/test-file?test-name-1=test-value-1&test-name-2=test-value-2" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.IN, null );
     //System.out.println( output );
@@ -212,7 +212,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
+    Template input = Parser.parseLiteral( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.IN, null );
     //System.out.println( output );
     assertThat( output, notNullValue() );
@@ -238,7 +238,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
+    Template input = Parser.parseLiteral( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.IN, null );
     //System.out.println( output );
     assertThat( output, notNullValue() );
@@ -264,7 +264,7 @@ public class HostmapFunctionProcessorTest {
     UrlRewriteProcessor rewriter = new UrlRewriteProcessor();
     rewriter.initialize( environment, descriptor );
 
-    Template input = Parser.parse( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
+    Template input = Parser.parseLiteral( "test-scheme://test-inbound-host:42/test-path/test-file?test-name=test-value" );
     Template output = rewriter.rewrite( resolver, input, UrlRewriter.Direction.IN, null );
     //System.out.println( output );
     assertThat( output, notNullValue() );

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceAddressFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceAddressFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceAddressFunctionProcessor.java
index c8b53a3..e7bafae 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceAddressFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceAddressFunctionProcessor.java
@@ -56,7 +56,7 @@ public class ServiceAddressFunctionProcessor
     String addr = parameter;
     String url = lookupServiceUrl( parameter );
     if( url != null ) {
-      Template template = Parser.parse( url );
+      Template template = Parser.parseLiteral( url );
       Host host = template.getHost();
       String hostStr = null;
       if( host != null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceHostFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceHostFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceHostFunctionProcessor.java
index c9e7f9b..7448d12 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceHostFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceHostFunctionProcessor.java
@@ -44,7 +44,7 @@ public class ServiceHostFunctionProcessor
       for( String parameter : parameters ) {
         String url = lookupServiceUrl( parameter );
         if( url != null ) {
-          Template template = Parser.parse( url );
+          Template template = Parser.parseLiteral( url );
           Host host = template.getHost();
           if( host != null ) {
             parameter = host.getFirstValue().getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessor.java
index 5809eb8..c5c8116 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedAddressFunctionProcessor.java
@@ -72,7 +72,7 @@ public class ServiceMappedAddressFunctionProcessor
     String addr = parameter;
     String url = lookupServiceUrl( parameter );
     if( url != null ) {
-      Template template = Parser.parse( url );
+      Template template = Parser.parseLiteral( url );
       Host host = template.getHost();
       String hostStr = null;
       if( host != null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedHostFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedHostFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedHostFunctionProcessor.java
index d7ab283..770aecd 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedHostFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceMappedHostFunctionProcessor.java
@@ -59,7 +59,7 @@ public class ServiceMappedHostFunctionProcessor
       for( String parameter : parameters ) {
         String url = lookupServiceUrl( parameter );
         if( url != null ) {
-          Template template = Parser.parse( url );
+          Template template = Parser.parseLiteral( url );
           Host host = template.getHost();
           if( host != null ) {
             String hostStr = host.getFirstValue().getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePathFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePathFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePathFunctionProcessor.java
index d3a1229..1269ca9 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePathFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePathFunctionProcessor.java
@@ -44,7 +44,7 @@ public class ServicePathFunctionProcessor
       for( String parameter : parameters ) {
         String url = lookupServiceUrl( parameter );
         if( url != null ) {
-          Template template = Parser.parse( url );
+          Template template = Parser.parseLiteral( url );
           List<Path> path = template.getPath();
           if( path != null ) {
             parameter = toString( path );

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePortFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePortFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePortFunctionProcessor.java
index 7226922..d05620c 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePortFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServicePortFunctionProcessor.java
@@ -44,7 +44,7 @@ public class ServicePortFunctionProcessor
       for( String parameter : parameters ) {
         String url = lookupServiceUrl( parameter );
         if( url != null ) {
-          Template template = Parser.parse( url );
+          Template template = Parser.parseLiteral( url );
           Port port = template.getPort();
           if( port != null ) {
             parameter = port.getFirstValue().getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceSchemeFunctionProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceSchemeFunctionProcessor.java b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceSchemeFunctionProcessor.java
index 919f5c4..4c5f03b 100644
--- a/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceSchemeFunctionProcessor.java
+++ b/gateway-provider-rewrite-func-service-registry/src/main/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceSchemeFunctionProcessor.java
@@ -44,7 +44,7 @@ public class ServiceSchemeFunctionProcessor
       for( String parameter : parameters ) {
         String url = lookupServiceUrl( parameter );
         if( url != null && !url.equals( parameter ) ) {
-          Template template = Parser.parse( url );
+          Template template = Parser.parseLiteral( url );
           Scheme scheme = template.getScheme();
           if( scheme != null ) {
             parameter = scheme.getFirstValue().getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
index d7c2ba3..4f57f0f 100644
--- a/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
+++ b/gateway-provider-rewrite-func-service-registry/src/test/java/org/apache/hadoop/gateway/svcregfunc/impl/ServiceRegistryFunctionsTest.java
@@ -200,7 +200,7 @@ public class ServiceRegistryFunctionsTest {
       try {
         request.setAttribute(
             AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME,
-            Parser.parse( sourceUrl.toString() ) );
+            Parser.parseLiteral( sourceUrl.toString() ) );
       } catch( URISyntaxException e ) {
         throw new ServletException( e );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
index cbd26b7..9a9d0c7 100644
--- a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
+++ b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/DecryptUriProcessor.java
@@ -58,7 +58,7 @@ public class DecryptUriProcessor
   @Override
   public UrlRewriteStepStatus process( UrlRewriteContext context ) throws Exception {
     if( param != null && !param.isEmpty() ) {
-      Template template = Parser.parse( "{" + param + "}" );
+      Template template = Parser.parseTemplate( "{" + param + "}" );
       String resolvedTemplate = Expander.expandToString( template, context.getParameters(), context.getEvaluator() );
       String url = decode( resolvedTemplate );
       EncryptStepContextParams params = new EncryptStepContextParams();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriProcessor.java b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriProcessor.java
index d9cfd13..2b0554e 100644
--- a/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriProcessor.java
+++ b/gateway-provider-rewrite-step-encrypt-uri/src/main/java/org/apache/hadoop/gateway/encrypturi/impl/EncryptUriProcessor.java
@@ -59,7 +59,7 @@ public class EncryptUriProcessor
   @Override
   public UrlRewriteStepStatus process( UrlRewriteContext context ) throws Exception {
     if( param != null && !param.isEmpty() && template != null && !template.isEmpty() ) {
-      Template uri = Parser.parse( template );
+      Template uri = Parser.parseTemplate( template );
       String resolvedTemplate = Expander.expandToString( uri, context.getParameters(), context.getEvaluator() );
       if( resolvedTemplate != null && !resolvedTemplate.isEmpty() ) {
         String endcoedUrl = encode( resolvedTemplate );

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
index 37eec1c..c42233a 100644
--- a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
+++ b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessor.java
@@ -64,9 +64,9 @@ public class SecureQueryDecodeProcessor implements UrlRewriteStepProcessor<Secur
             // Need to take out any existing query param.
             // If we don't then someone could override something in the encoded param.
             map.remove( paramName );
-            newUrl.addQuery( paramName, "", paramValue );
+            newUrl.addQuery( paramName, "", paramValue, true );
           } else {
-            newUrl.addQuery( paramName, "", null );
+            newUrl.addQuery( paramName, "", null, true );
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptProcessor.java b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptProcessor.java
index 7cae01b..1e20ad1 100644
--- a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptProcessor.java
+++ b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryDecryptProcessor.java
@@ -74,9 +74,9 @@ public class SecureQueryDecryptProcessor implements UrlRewriteStepProcessor<Secu
             // Need to remove from the clear parameters any param name in the encoded params.
             // If we don't then someone could override something in the encoded param.
             map.remove( paramName );
-            newUrl.addQuery( paramName, "", paramValue );
+            newUrl.addQuery( paramName, "", paramValue, true );
           } else {
-            newUrl.addQuery( paramName, "", null );
+            newUrl.addQuery( paramName, "", null, true );
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessor.java b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessor.java
index eff1908..0b32c05 100644
--- a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessor.java
+++ b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessor.java
@@ -56,7 +56,7 @@ public class SecureQueryEncodeProcessor
     if( query != null ) {
       query = Base64.encodeBase64String( query.getBytes( "UTF-8" ) );
       query = removeTrailingEquals( query );
-      url = Parser.parse( path + "?" + ENCODED_PARAMETER_NAME +"=" + query );
+      url = Parser.parseLiteral( path + "?" + ENCODED_PARAMETER_NAME +"=" + query );
       context.setCurrentUrl( url );
     }
     return UrlRewriteStepStatus.SUCCESS;

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptProcessor.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptProcessor.java b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptProcessor.java
index 081978d..fe587ba 100644
--- a/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptProcessor.java
+++ b/gateway-provider-rewrite-step-secure-query/src/main/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptProcessor.java
@@ -66,7 +66,7 @@ public class SecureQueryEncryptProcessor
     }
     if( query != null ) {
       query = encode( query );
-      url = Parser.parse( path + "?" + ENCRYPTED_PARAMETER_NAME +"=" + query );
+      url = Parser.parseLiteral( path + "?" + ENCRYPTED_PARAMETER_NAME +"=" + query );
       context.setCurrentUrl( url );
     }
     return UrlRewriteStepStatus.SUCCESS;

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessorTest.java b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessorTest.java
index e8af9ce..b6a7c5c 100644
--- a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessorTest.java
+++ b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryDecodeProcessorTest.java
@@ -60,7 +60,7 @@ public class SecureQueryDecodeProcessorTest {
     String encQuery = encoder.encode( "test-query".getBytes("utf-8" ) );
     encQuery = encQuery.replaceAll( "\\=", "" );
     String inString = "http://host:0/root/path?_=" + encQuery;
-    Template inTemplate = Parser.parse( inString );
+    Template inTemplate = Parser.parseLiteral( inString );
 
     UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
     EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
@@ -101,7 +101,7 @@ public class SecureQueryDecodeProcessorTest {
     String encQuery = encoder.encode( inQuery.getBytes( "utf-8" ) );
     encQuery = encQuery.replaceAll( "\\=", "" );
     String inString = "http://host:0/root/path?_=" + encQuery + "&clear-param=clear-value";
-    Template inTemplate = Parser.parse( inString );
+    Template inTemplate = Parser.parseLiteral( inString );
 
     UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
     EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessorTest.java b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessorTest.java
index 3a9fe73..0b72e91 100644
--- a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessorTest.java
+++ b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncodeProcessorTest.java
@@ -51,7 +51,7 @@ public class SecureQueryEncodeProcessorTest {
     EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();    
     EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( Arrays.asList( "test-cluster-name" ) ).anyTimes();
 
-    Template inTemplate = Parser.parse( "http://host:0/root/path?query" );
+    Template inTemplate = Parser.parseLiteral( "http://host:0/root/path?query" );
     UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
     EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
     Capture<Template> outTemplate = new Capture<Template>();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptDecryptProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptDecryptProcessorTest.java b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptDecryptProcessorTest.java
index b2e6044..ddc2782 100644
--- a/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptDecryptProcessorTest.java
+++ b/gateway-provider-rewrite-step-secure-query/src/test/java/org/apache/hadoop/gateway/securequery/SecureQueryEncryptDecryptProcessorTest.java
@@ -44,7 +44,7 @@ public class SecureQueryEncryptDecryptProcessorTest {
   @Test
   public void testEncryptDecrypt() throws Exception {
     Query query;
-    Template origTemplate = Parser.parse( "http://host:0/path/file?query-param-name=query-param-value" );
+    Template origTemplate = Parser.parseLiteral( "http://host:0/path/file?query-param-name=query-param-value" );
 
     // Test encryption.  Results are left in encTemplate
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteActionRewriteProcessorExt.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteActionRewriteProcessorExt.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteActionRewriteProcessorExt.java
index 61dd609..a2bcb1b 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteActionRewriteProcessorExt.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteActionRewriteProcessorExt.java
@@ -40,9 +40,9 @@ public class UrlRewriteActionRewriteProcessorExt
   public void initialize( UrlRewriteEnvironment environment, UrlRewriteActionRewriteDescriptorExt descriptor ) throws Exception {
     this.expander = new Expander();
     if ( descriptor.parameter() != null ) {
-      this.template = Parser.parse( descriptor.parameter() );
+      this.template = Parser.parseTemplate( descriptor.parameter() );
     } else {
-      this.template = Parser.parse( "" );
+      this.template = Parser.parseTemplate( "" );
     }
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteMatchDescriptorExt.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteMatchDescriptorExt.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteMatchDescriptorExt.java
index 3cb8829..a8e1130 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteMatchDescriptorExt.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/ext/UrlRewriteMatchDescriptorExt.java
@@ -74,7 +74,7 @@ public class UrlRewriteMatchDescriptorExt
   @Override
   public UrlRewriteMatchDescriptor pattern( String pattern ) throws URISyntaxException {
     this.pattern = pattern;
-    this.template = Parser.parse( pattern );
+    this.template = Parser.parseTemplate( pattern );
     return this;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
index e97d8e1..3865d25 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRequest.java
@@ -93,7 +93,7 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements Resolver
       urlString.append( queryString );
     }
     try {
-      urlTemplate = Parser.parse( urlString.toString() );
+      urlTemplate = Parser.parseLiteral( urlString.toString() );
     } catch( URISyntaxException e ) {
       LOG.failedToParseValueForUrlRewrite( urlString.toString() );
       // Shouldn't be possible given that the URL is constructed from parts of an existing URL.
@@ -153,7 +153,7 @@ public class UrlRewriteRequest extends GatewayRequestWrapper implements Resolver
 
   private String rewriteValue( UrlRewriter rewriter, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( this, input, UrlRewriter.Direction.IN, rule );
       value = output.getPattern();
     } catch( URISyntaxException e ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/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 6898620..0f2b185 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
@@ -113,7 +113,7 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
 
   private String rewriteValue( String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( this, input, UrlRewriter.Direction.OUT, rule );
       if( output != null ) {
         value = output.getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
index d718921..af882df 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteRuleDescriptorImpl.java
@@ -110,7 +110,7 @@ public class UrlRewriteRuleDescriptorImpl extends UrlRewriteFlowDescriptorBase<U
   @Override
   public UrlRewriteRuleDescriptor pattern( String pattern ) throws URISyntaxException {
     this.pattern = pattern;
-    this.template = Parser.parse( pattern );
+    this.template = Parser.parseTemplate( pattern );
     return this;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/form/FormUrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/form/FormUrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/form/FormUrlRewriteFilterReader.java
index 5f01ba1..70e2173 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/form/FormUrlRewriteFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/form/FormUrlRewriteFilterReader.java
@@ -48,7 +48,7 @@ public class FormUrlRewriteFilterReader extends FormFilterReader {
   @Override
   protected String filterValue( String name, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( resolver, input, direction, rule );
       value = output.getPattern();
     } catch( URISyntaxException e ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlUrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlUrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlUrlRewriteFilterReader.java
index 340d6d1..76b7c38 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlUrlRewriteFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlUrlRewriteFilterReader.java
@@ -50,7 +50,7 @@ public class HtmlUrlRewriteFilterReader extends HtmlFilterReader {
   @Override
   public String filterValueString( String name, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( resolver, input, direction, rule );
       if( output != null ) {
         value = output.getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteFilterReader.java
index da54e22..af9a36f 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/javascript/JavaScriptUrlRewriteFilterReader.java
@@ -48,7 +48,7 @@ public class JavaScriptUrlRewriteFilterReader extends JavaScriptFilterReader {
   @Override
   public String filterValueString( String name, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( resolver, input, direction, rule );
       if( output != null ) {
         value = output.getPattern();

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonUrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonUrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonUrlRewriteFilterReader.java
index 4dc2df6..a5bbc82 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonUrlRewriteFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/json/JsonUrlRewriteFilterReader.java
@@ -52,7 +52,7 @@ public class JsonUrlRewriteFilterReader extends JsonFilterReader {
 
   protected String filterValueString( String name, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( resolver, input, direction, rule );
       value = output.getPattern();
     } catch( URISyntaxException e ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteFilterReader.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteFilterReader.java
index ee6ef0e..f9b39e5 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteFilterReader.java
@@ -53,7 +53,7 @@ public class XmlUrlRewriteFilterReader extends XmlFilterReader {
   //TODO: Need to limit which values are attempted to be filtered by the name.
   private String filterValueString( String name, String value, String rule ) {
     try {
-      Template input = Parser.parse( value );
+      Template input = Parser.parseLiteral( value );
       if( input != null ) {
         Template output = rewriter.rewrite( resolver, input, direction, rule );
         if( output != null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
index 86d8460..44a4e77 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
@@ -69,7 +69,7 @@ public class UrlRewriteProcessorTest {
         "xml", getTestResourceReader( "rewrite.xml", "UTF-8" ) );
     processor.initialize( environment, config );
 
-    Template inputUrl = Parser.parse( "test-scheme://test-host:1/test-input-path" );
+    Template inputUrl = Parser.parseLiteral( "test-scheme://test-host:1/test-input-path" );
     Template outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.IN, null );
 
     assertThat( "Expect rewrite to produce a new URL",
@@ -92,7 +92,7 @@ public class UrlRewriteProcessorTest {
         "xml", getTestResourceReader( "rewrite-with-same-rules.xml", "UTF-8" ) );
     processor.initialize( environment, config );
 
-    Template inputUrl = Parser.parse( "scheme://input-mock-host:42/test-input-path" );
+    Template inputUrl = Parser.parseLiteral( "scheme://input-mock-host:42/test-input-path" );
     Template outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, null );
 
     assertThat( "Expect rewrite to produce a new URL",
@@ -102,7 +102,7 @@ public class UrlRewriteProcessorTest {
         "Expect rewrite to contain the correct path.",
         outputUrl.toString(), is( "output-mock-scheme-1://output-mock-host-1:42/test-input-path" ) );
 
-    inputUrl = Parser.parse( "mock-scheme://input-mock-host:42/no-query" );
+    inputUrl = Parser.parseLiteral( "mock-scheme://input-mock-host:42/no-query" );
     outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, null );
 
     assertThat(
@@ -130,7 +130,7 @@ public class UrlRewriteProcessorTest {
         "xml", getTestResourceReader( "rewrite-with-same-rules.xml", "UTF-8" ) );
     processor.initialize( environment, config );
 
-    Template inputUrl = Parser.parse( "input-mock-scheme-1://input-mock-host-1:42/test-input-path" );
+    Template inputUrl = Parser.parseLiteral( "input-mock-scheme-1://input-mock-host-1:42/test-input-path" );
     Template outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, "test-rule-2" );
 
     assertThat( "Expect rewrite to produce a new URL",
@@ -165,13 +165,13 @@ public class UrlRewriteProcessorTest {
     Template inputUrl;
     Template outputUrl;
 
-    inputUrl = Parser.parse( "test-scheme://test-host:777/test-path" );
+    inputUrl = Parser.parseLiteral( "test-scheme://test-host:777/test-path" );
     outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.IN, "test-rule-with-complex-flow" );
     assertThat(
         "Expect rewrite to contain the correct path.",
         outputUrl.toString(), is( "test-scheme-output://test-host-output:42/test-path-output/test-path" ) );
 
-    inputUrl = Parser.parse( "test-scheme://test-host:42/~/test-path" );
+    inputUrl = Parser.parseLiteral( "test-scheme://test-host:42/~/test-path" );
     outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.IN, "test-rule-with-complex-flow" );
     assertThat(
         "Expect rewrite to contain the correct path.",
@@ -195,14 +195,14 @@ public class UrlRewriteProcessorTest {
     Template inputUrl;
     Template outputUrl;
 
-    inputUrl = Parser.parse( "test-scheme-input://test-host-input:42/test-path-input-one/test-path-input-two?test-query-name=test-query-value" );
+    inputUrl = Parser.parseLiteral( "test-scheme-input://test-host-input:42/test-path-input-one/test-path-input-two?test-query-name=test-query-value" );
     outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, "test-rule-2" );
 
     assertThat(
         "Expect rewrite to contain the correct path and query.",
         outputUrl.toString(), is( "test-scheme-output://test-host-output:777/test-path-output/test-path-input-one/test-path-input-two?test-query-name=test-query-value" ) );
 
-    inputUrl = Parser.parse( "test-scheme-input://test-host-input:42/test-path-input-one/test-path-input-two" );
+    inputUrl = Parser.parseLiteral( "test-scheme-input://test-host-input:42/test-path-input-one/test-path-input-two" );
     outputUrl = processor.rewrite( null, inputUrl, UrlRewriter.Direction.OUT, "test-rule-2" );
 
     assertThat(

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/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 de278ad..d33582c 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
@@ -724,7 +724,7 @@ public class UrlRewriteServletFilterTest {
       try {
         request.setAttribute(
             AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME,
-            Parser.parse( sourceUrl.toString() ) );
+            Parser.parseLiteral( sourceUrl.toString() ) );
       } catch( URISyntaxException e ) {
         throw new ServletException( e );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
index 2081706..014ce4f 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/FrontendFunctionProcessorTest.java
@@ -276,7 +276,7 @@ public class FrontendFunctionProcessorTest {
       try {
         request.setAttribute(
             AbstractGatewayFilter.SOURCE_REQUEST_URL_ATTRIBUTE_NAME,
-            Parser.parse( sourceUrl.toString() ) );
+            Parser.parseLiteral( sourceUrl.toString() ) );
       } catch( URISyntaxException e ) {
         throw new ServletException( e );
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImplTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImplTest.java b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImplTest.java
index 88587ea..7267b87 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImplTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteContextImplTest.java
@@ -52,7 +52,7 @@ public class UrlRewriteContextImplTest {
     Map<String,UrlRewriteFunctionProcessor> functions = new HashMap<String,UrlRewriteFunctionProcessor>();
 
     UrlRewriter.Direction direction = UrlRewriter.Direction.OUT;
-    Template template = Parser.parse( "scheme://host:port/dir/file" );
+    Template template = Parser.parseLiteral( "scheme://host:port/dir/file" );
 
     UrlRewriteContextImpl context = new UrlRewriteContextImpl( environment, resolver, functions, direction, template );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
index fbe7769..1e8bb56 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReaderTest.java
@@ -939,6 +939,17 @@ public class XmlFilterReaderTest {
     assertThat( output, containsString( "<tag>&amp;</tag>" ) );
   }
 
+  @Test
+  public void testSpecialTextNodeBugKnox394() throws IOException, ParserConfigurationException, XMLStreamException {
+    String inputXml = "<tag>${oozieTemplateMarkup}</tag>";
+    StringReader inputReader = new StringReader( inputXml );
+    XmlFilterReader filterReader = new NoopXmlFilterReader( inputReader, null );
+    String outputXml = new String( IOUtils.toCharArray( filterReader ) );
+    //System.out.println( "OUTPUT=" + outputXml );
+    assertThat( the( outputXml ), hasXPath( "/tag/text()", equalTo( "${oozieTemplateMarkup}" ) ) );
+  }
+
+
   private class TestXmlFilterReader extends XmlFilterReader {
 
     protected TestXmlFilterReader( Reader reader, UrlRewriteFilterContentDescriptor contentConfig ) throws IOException, ParserConfigurationException, XMLStreamException {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
index 3ff0abd..98ad94e 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayFilter.java
@@ -102,7 +102,7 @@ public class GatewayFilter implements Filter {
 
     Template pathTemplate;
     try {
-      pathTemplate = Parser.parse( path );
+      pathTemplate = Parser.parseLiteral( path );
     } catch( URISyntaxException e ) {
       throw new ServletException( e );
     }
@@ -253,7 +253,7 @@ public class GatewayFilter implements Filter {
 
     private Holder( String path, String name, Filter filter, Map<String,String> params, String resourceRole ) throws URISyntaxException {
 //      this.path = path;
-      this.template = Parser.parse( path );
+      this.template = Parser.parseTemplate( path );
       this.name = name;
       this.params = params;
       this.instance = filter;
@@ -274,7 +274,7 @@ public class GatewayFilter implements Filter {
 
     private Holder( String path, String name, String clazz, Map<String,String> params, String resourceRole ) throws URISyntaxException {
 //      this.path = path;
-      this.template = Parser.parse( path );
+      this.template = Parser.parseTemplate( path );
       this.name = name;
       this.params = params;
       this.instance = null;

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
index c0347cf..25de087 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/dispatch/UrlConnectionDispatch.java
@@ -94,8 +94,8 @@ public class UrlConnectionDispatch extends AbstractGatewayFilter {
     String targetPattern = getConfig().getInitParameter( "target" );
 
     //TODO: Some of the compilation should be done at servlet init for performance reasons.
-    Template sourceTemplate = Parser.parse( sourcePattern );
-    Template targetTemplate = Parser.parse( targetPattern );
+    Template sourceTemplate = Parser.parseTemplate( sourcePattern );
+    Template targetTemplate = Parser.parseTemplate( targetPattern );
 
     Resolver resolver = new DispatchParamResolver( getConfig(), request );
     URI sourceUri = new URI( sourcePathInfo );

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
index bd8002b..dda93ef 100644
--- a/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
+++ b/gateway-service-definitions/src/main/resources/services/oozie/4.0.0/rewrite.xml
@@ -47,8 +47,11 @@
         <match pattern="/~/{path=**}">
             <rewrite template="hdfs://{$serviceMappedAddr[NAMENODE]}/user/{$username}/{path=**}"/>
         </match>
+        <match pattern="{var=${*}}/{path=**}">
+            <rewrite template="{var}/{path=**}"/>
+        </match>
         <match pattern="{path=**}">
-            <rewrite template="hdfs://{$serviceMappedAddr[NAMENODE]}/{path=**}"/>
+            <rewrite template="{$serviceMappedUrl[NAMENODE]}/{path=**}"/>
         </match>
     </rule>
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
index d919575..084d296 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
@@ -19,13 +19,26 @@ package org.apache.hadoop.test;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.io.StringWriter;
 import java.net.URL;
 import java.util.UUID;
 
@@ -45,12 +58,30 @@ public class TestUtils {
     return url;
   }
 
+  public static URL getResourceUrl( String name ) throws FileNotFoundException {
+    URL url = ClassLoader.getSystemResource( name );
+    if( url == null ) {
+      throw new FileNotFoundException( name );
+    }
+    return url;
+  }
+
+  public static InputStream getResourceStream( String name ) throws IOException {
+    URL url = ClassLoader.getSystemResource( name );
+    InputStream stream = url.openStream();
+    return stream;
+  }
+
   public static InputStream getResourceStream( Class clazz, String name ) throws IOException {
     URL url = getResourceUrl( clazz, name );
     InputStream stream = url.openStream();
     return stream;
   }
 
+  public static Reader getResourceReader( String name, String charset ) throws IOException {
+    return new InputStreamReader( getResourceStream( name ), charset );
+  }
+
   public static Reader getResourceReader( Class clazz, String name, String charset ) throws IOException {
     return new InputStreamReader( getResourceStream( clazz, name ), charset );
   }
@@ -66,4 +97,21 @@ public class TestUtils {
     return tempDir;
   }
 
+  public static Document parseXml( InputStream stream ) throws ParserConfigurationException, IOException, SAXException {
+    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+    DocumentBuilder builder = factory.newDocumentBuilder();
+    Document document = builder.parse( new InputSource( stream ) );
+    return document;
+  }
+
+  public static void dumpXml( Document document ) throws TransformerException {
+    Transformer transformer = TransformerFactory.newInstance().newTransformer();
+    transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
+    StreamResult result = new StreamResult( new StringWriter() );
+    DOMSource source = new DOMSource( document );
+    transformer.transform( source, result );
+    String xmlString = result.getWriter().toString();
+    System.out.println( xmlString );
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
new file mode 100644
index 0000000..96d8fbd
--- /dev/null
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
@@ -0,0 +1,148 @@
+/**
+ * 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;
+
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteEnvironment;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteProcessor;
+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.UrlRewriteServletContextListener;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletEnvironment;
+import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
+import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteRequest;
+import org.apache.hadoop.gateway.services.GatewayServices;
+import org.apache.hadoop.gateway.services.registry.ServiceRegistry;
+import org.apache.hadoop.test.TestUtils;
+import org.apache.hadoop.test.mock.MockServletInputStream;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.InputStream;
+import java.io.Reader;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.xml.HasXPath.hasXPath;
+
+public class OozieServiceDefinitionTest {
+
+  @Test
+  public void testOozieRewriteRulesForLiteralTemplateValuesBugKnox394() throws Exception {
+
+    // This is a unique part of this test.
+    String testResource = "oozie-request-with-var.xml";
+
+    // Mock out the service url registry which is required for several url rewrite functions to work.
+    ServiceRegistry registry = EasyMock.createNiceMock( ServiceRegistry.class );
+    EasyMock.expect( registry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-scheme://test-host:42" ).anyTimes();
+
+    // Mock out the gateway services registry which is required for several url rewrite functions to work.
+    GatewayServices services = EasyMock.createNiceMock( GatewayServices.class );
+    EasyMock.expect( services.getService( GatewayServices.SERVICE_REGISTRY_SERVICE ) ).andReturn( registry ).anyTimes();
+
+    UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
+
+    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+    EasyMock.expect( servletContext.getAttribute( UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME ) ).andReturn( rewriteProcessor ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( services ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster" ).anyTimes();
+
+    HttpServletRequest servletRequest = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( servletRequest.getInputStream() ).andReturn( new MockServletInputStream( TestUtils.getResourceStream( OozieServiceDefinitionTest.class, testResource ) ) ).anyTimes();
+    EasyMock.expect( servletRequest.getContentType() ).andReturn( "text/xml" ).anyTimes();
+
+    FilterConfig filterConfig = EasyMock.createNiceMock( FilterConfig.class );
+    EasyMock.expect( filterConfig.getServletContext() ).andReturn( servletContext ).anyTimes();
+    EasyMock.expect( filterConfig.getInitParameter( UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM ) ).andReturn( "OOZIE/oozie/configuration" ).anyTimes();
+
+    EasyMock.replay( registry, services, servletContext, servletRequest, filterConfig );
+
+    UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext );
+
+    Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", "UTF-8" );
+    UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load( "xml", rulesReader );
+    rulesReader.close();
+
+    rewriteProcessor.initialize( rewriteEnvironment, rewriteRules );
+
+    UrlRewriteRequest rewriteRequest = new UrlRewriteRequest( filterConfig, servletRequest );
+
+    InputStream stream = rewriteRequest.getInputStream();
+
+    Document document = TestUtils.parseXml( stream );
+
+    assertThat( document,
+        hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",
+            equalTo( "${appPath}/workflow.xml" ) ) );
+  }
+
+  @Test
+  public void testOozieRewriteRulesForValuesRelativeToServiceRegistry() throws Exception {
+
+    // This is a unique part of this test.
+    String testResource = "oozie-request-relative.xml";
+
+    // Mock out the service url registry which is required for several url rewrite functions to work.
+    ServiceRegistry registry = EasyMock.createNiceMock( ServiceRegistry.class );
+    EasyMock.expect( registry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-scheme://test-host:42" ).anyTimes();
+
+    // Mock out the gateway services registry which is required for several url rewrite functions to work.
+    GatewayServices services = EasyMock.createNiceMock( GatewayServices.class );
+    EasyMock.expect( services.getService( GatewayServices.SERVICE_REGISTRY_SERVICE ) ).andReturn( registry ).anyTimes();
+
+    UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
+
+    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+    EasyMock.expect( servletContext.getAttribute( UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME ) ).andReturn( rewriteProcessor ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( services ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster" ).anyTimes();
+
+    HttpServletRequest servletRequest = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( servletRequest.getInputStream() ).andReturn( new MockServletInputStream( TestUtils.getResourceStream( OozieServiceDefinitionTest.class, testResource ) ) ).anyTimes();
+    EasyMock.expect( servletRequest.getContentType() ).andReturn( "text/xml" ).anyTimes();
+
+    FilterConfig filterConfig = EasyMock.createNiceMock( FilterConfig.class );
+    EasyMock.expect( filterConfig.getServletContext() ).andReturn( servletContext ).anyTimes();
+    EasyMock.expect( filterConfig.getInitParameter( UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM ) ).andReturn( "OOZIE/oozie/configuration" ).anyTimes();
+
+    EasyMock.replay( registry, services, servletContext, servletRequest, filterConfig );
+
+    UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext );
+
+    Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", "UTF-8" );
+    UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load( "xml", rulesReader );
+    rulesReader.close();
+
+    rewriteProcessor.initialize( rewriteEnvironment, rewriteRules );
+
+    UrlRewriteRequest rewriteRequest = new UrlRewriteRequest( filterConfig, servletRequest );
+
+    InputStream stream = rewriteRequest.getInputStream();
+
+    Document document = TestUtils.parseXml( stream );
+
+    assertThat( document,
+        hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",
+            equalTo( "test-scheme://test-host:42/workflow.xml" ) ) );
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-relative.xml
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-relative.xml b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-relative.xml
new file mode 100644
index 0000000..3b9ae46
--- /dev/null
+++ b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-relative.xml
@@ -0,0 +1,14 @@
+<configuration><property><name>oozie.use.system.libpath</name><value>true</value></property>
+    <property><name>cluster_name</name><value>hdp</value></property>
+    <property><name>knox_truth</name><value>true</value></property>
+    <property><name>oozie_port</name><value>11000</value>
+    </property><property><name>oozie_host</name><value>hostname</value></property>
+    <property><name>jobTracker</name><value>hostname</value></property>
+    <property><name>appPath</name><value>${nameNode}/user/svbigred/oozie-workflows/ecom_dmnd_tndr</value></property>
+    <property><name>oozie.wf.application.path</name><value>workflow.xml</value></property>
+    <property><name>knox_gateway_port</name><value>8443</value></property>
+    <property><name>knox_gateway_path</name><value>gateway</value></property>
+    <property><name>user.name</name><value>svbigred</value></property>
+    <property><name>ENV</name><value>dev</value></property>
+    <property><name>nameNode</name><value>hdfs://hostname:8020</value></property>
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-var.xml
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-var.xml b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-var.xml
new file mode 100644
index 0000000..ab535e3
--- /dev/null
+++ b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-var.xml
@@ -0,0 +1,14 @@
+<configuration><property><name>oozie.use.system.libpath</name><value>true</value></property>
+    <property><name>cluster_name</name><value>hdp</value></property>
+    <property><name>knox_truth</name><value>true</value></property>
+    <property><name>oozie_port</name><value>11000</value>
+    </property><property><name>oozie_host</name><value>hostname</value></property>
+    <property><name>jobTracker</name><value>hostname</value></property>
+    <property><name>appPath</name><value>${nameNode}/user/svbigred/oozie-workflows/ecom_dmnd_tndr</value></property>
+    <property><name>oozie.wf.application.path</name><value>${appPath}/workflow.xml</value></property>
+    <property><name>knox_gateway_port</name><value>8443</value></property>
+    <property><name>knox_gateway_path</name><value>gateway</value></property>
+    <property><name>user.name</name><value>svbigred</value></property>
+    <property><name>ENV</name><value>dev</value></property>
+    <property><name>nameNode</name><value>hdfs://hostname:8020</value></property>
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Builder.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Builder.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Builder.java
index 63ab4bc..f4c3bee 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Builder.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Builder.java
@@ -25,6 +25,7 @@ import java.util.Map;
 public class Builder {
 
   private String original;
+  private boolean literal;
   private boolean hasScheme;
   private Scheme scheme;
   private boolean hasAuthority;
@@ -48,6 +49,7 @@ public class Builder {
 
   public Builder( String original ) {
     this.original = original;
+    this.literal = false;
     this.hasScheme = false;
     this.scheme = null;
     this.hasAuthority = false;
@@ -171,7 +173,19 @@ public class Builder {
         fragment, hasFragment );
   }
 
-  public boolean getHashScheme() {
+  public boolean isLiteral() {
+    return literal;
+  }
+
+  public void setLiteral( boolean literal ) {
+    this.literal = literal;
+  }
+
+  public String getOriginal() {
+    return original;
+  }
+
+  public boolean getHasScheme() {
     return this.hasScheme;
   }
 
@@ -186,8 +200,8 @@ public class Builder {
     return this.scheme;
   }
 
-  public void setScheme( String paramName, String valuePattern ) {
-    this.scheme = new Scheme( paramName, valuePattern );
+  public void setScheme( String paramName, String valuePattern, boolean literal ) {
+    this.scheme = new Scheme( paramName, valuePattern, literal );
     setHasScheme( true );
   }
 
@@ -216,9 +230,9 @@ public class Builder {
     return username;
   }
 
-  public void setUsername( String paramName, String valuePattern ) {
+  public void setUsername( String paramName, String valuePattern, boolean literal ) {
     setHasAuthority( true );
-    username = new Username( new Token( paramName, valuePattern ) );
+    username = new Username( new Token( paramName, valuePattern, literal ) );
   }
 
   void setUsername( Token token ) {
@@ -230,9 +244,9 @@ public class Builder {
     return password;
   }
 
-  public void setPassword( String paramName, String valuePattern ) {
+  public void setPassword( String paramName, String valuePattern, boolean literal ) {
     setHasAuthority( true );
-    password = new Password( paramName, valuePattern );
+    password = new Password( paramName, valuePattern, literal );
   }
 
   void setPassword( Token token ) {
@@ -244,8 +258,8 @@ public class Builder {
     return host;
   }
 
-  public void setHost( String paramName, String valuePattern ) {
-    setHost( new Token( paramName, valuePattern ) );
+  public void setHost( String paramName, String valuePattern, boolean literal ) {
+    setHost( new Token( paramName, valuePattern, literal ) );
   }
 
   void setHost( Token token ) {
@@ -257,8 +271,8 @@ public class Builder {
     return port;
   }
 
-  public void setPort( String paramName, String valuePattern ) {
-    setPort( new Token( paramName, valuePattern ) );
+  public void setPort( String paramName, String valuePattern, boolean literal ) {
+    setPort( new Token( paramName, valuePattern, literal ) );
   }
 
   void setPort( Token token ) {
@@ -288,8 +302,8 @@ public class Builder {
     return path;
   }
 
-  public Builder addPath( String paramName, String valuePattern ) {
-    Path segment = new Path( paramName, valuePattern );
+  public Builder addPath( String paramName, String valuePattern, boolean literal ) {
+    Path segment = new Path( paramName, valuePattern, literal );
     path.add( segment );
     return this;
   }
@@ -313,10 +327,10 @@ public class Builder {
     return this.query;
   }
 
-  public Builder addQuery( String queryName, String paramName, String valuePattern ) {
+  public Builder addQuery( String queryName, String paramName, String valuePattern, boolean literal ) {
     if( Segment.STAR_PATTERN.equals( queryName ) || Segment.GLOB_PATTERN.equals( queryName ) ) {
       if( extra == null ) {
-        Query segment = new Query( queryName, paramName, valuePattern );
+        Query segment = new Query( queryName, paramName, valuePattern, literal );
         extra = segment;
       } else {
         // Can't have two extras: ?{*}&{**}
@@ -325,14 +339,14 @@ public class Builder {
     } else {
       Query segment = query.get( queryName );
       if( segment == null ) {
-        segment = new Query( queryName, paramName, valuePattern );
+        segment = new Query( queryName, paramName, valuePattern, literal );
         query.put( queryName, segment );
       } else {
         // Can't have two queryParam names for the same query name: ?query={param1}&query={param2} in a template.
         // Should probably throw an exception in this case.  However, you can have this in a valid URL.
         // This causes a problem with how templates are used for both URLs and Templates.
         // For a template only the first parameter name will be used.
-        segment.addValue( new Token( queryName, valuePattern ) );
+        segment.addValue( new Token( queryName, valuePattern, literal ) );
       }
     }
     return this;
@@ -377,7 +391,7 @@ public class Builder {
 
   public void setFragment( String paramName, String valuePattern ) {
     setHasFragment( true );
-    this.fragment = new Fragment( paramName, valuePattern );
+    this.fragment = new Fragment( paramName, valuePattern, literal );
   }
 
   void setFragment( Token t ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
index 443df8f..7ec2e91 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
@@ -41,7 +41,7 @@ public class Expander {
 
   public static Template expandToTemplate( Template template, Params params, Evaluator evaluator ) throws URISyntaxException {
     //TODO: This could be much more efficient if it didn't create and then parse a string.
-    return Parser.parse( expandToString( template, params, evaluator ) );
+    return Parser.parseLiteral( expandToString( template, params, evaluator ) );
   }
 
   public static String expandToString( Template template, Params params, Evaluator evaluator ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Fragment.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Fragment.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Fragment.java
index d7d6742..96d2534 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Fragment.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Fragment.java
@@ -19,8 +19,8 @@ package org.apache.hadoop.gateway.util.urltemplate;
 
 public class Fragment extends Segment {
 
-  public Fragment( String paramName, String valuePattern ) {
-    super( new Token( paramName, valuePattern ) );
+  public Fragment( String paramName, String valuePattern, boolean literal ) {
+    super( new Token( paramName, valuePattern, literal ) );
   }
 
   public Fragment( Fragment fragment ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Host.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Host.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Host.java
index 1273ee9..f1e9a7d 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Host.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Host.java
@@ -19,8 +19,8 @@ package org.apache.hadoop.gateway.util.urltemplate;
 
 public class Host extends Segment {
 
-  public Host( String paramName, String valuePattern ) {
-    super( new Token( paramName, valuePattern ) );
+  public Host( String paramName, String valuePattern, boolean literal ) {
+    super( new Token( paramName, valuePattern, literal ) );
   }
 
   public Host( Host host ) {


Mime
View raw message