knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject [2/3] knox git commit: KNOX-394: Request and response URLs must be parsed as literals not templates
Date Tue, 03 Nov 2015 04:52:02 GMT
http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
index 8bf3586..e59cd32 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
@@ -80,16 +80,24 @@ public class Parser {
 
   private static Pattern PATTERN = Pattern.compile( "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?" );
 
-  private String template; // Kept this for debugging.
-  private Builder builder;
+  @Deprecated
+  public static final Template parse( String template ) throws URISyntaxException {
+    return Parser.parseTemplate( template );
+  }
+
+  public static final Template parseTemplate( final String template ) throws URISyntaxException {
+    Builder builder = new Builder( template );
+    return parseInternal( builder );
+  }
 
-  public static Template parse( String template ) throws URISyntaxException {
-    return new Parser().parseTemplate( template );
+  public static final Template parseLiteral( final String literal ) throws URISyntaxException {
+    Builder builder = new Builder( literal );
+    builder.setLiteral( true );
+    return parseInternal( builder );
   }
 
-  public Template parseTemplate( String template ) throws URISyntaxException {
-    this.template = template;
-    builder = new Builder( template );
+  private static final Template parseInternal( final Builder builder ) throws URISyntaxException {
+    String original = builder.getOriginal();
     builder.setHasScheme( false );
     builder.setHasAuthority( false ); // Assume no until found otherwise.  If true, will cause // in output URL.
     builder.setIsAuthorityOnly( false );
@@ -97,22 +105,22 @@ public class Parser {
     builder.setIsDirectory( false ); // Assume a file path until found otherwise.  If true, will cause trailing / in output URL.
     builder.setHasQuery( false ); // Assume no ? until found otherwise.  If true, will cause ? in output URL.
     builder.setHasFragment( false ); // Assume no # until found otherwise.  If true, will cause # in output URL.
-    Matcher match = PATTERN.matcher( template );
+    Matcher match = PATTERN.matcher( original );
     if( match.matches() ) {
-      consumeSchemeMatch( match );
-      consumeAuthorityMatch( match );
-      consumePathMatch( match );
-      consumeQueryMatch( match );
-      consumeFragmentMatch( match );
-      fixNakedAuthority();
+      consumeSchemeMatch( builder, match );
+      consumeAuthorityMatch( builder, match );
+      consumePathMatch( builder, match );
+      consumeQueryMatch( builder, match );
+      consumeFragmentMatch( builder, match );
+      fixNakedAuthority( builder );
     } else {
-      throw new URISyntaxException( template, RES.parseTemplateFailureReason( template ) );
+      throw new URISyntaxException( original, RES.parseTemplateFailureReason( original ) );
     }
     return builder.build();
   }
 
-  private final void fixNakedAuthority() {
-    if( builder.getHashScheme() &&
+  private static final void fixNakedAuthority( final Builder builder ) {
+    if( builder.getHasScheme() &&
         !builder.getHasAuthority() &&
         !builder.getIsAbsolute() &&
         !builder.getIsDirectory() &&
@@ -128,10 +136,10 @@ public class Parser {
     }
   }
 
-  private final Token makeTokenSingular( Token token ) {
+  private static final Token makeTokenSingular( Token token ) {
     final String effectivePattern = token.getEffectivePattern();
     if( Segment.GLOB_PATTERN.equals( effectivePattern ) ) {
-      token = new Token( token.getParameterName(), token.getOriginalPattern(), Segment.STAR_PATTERN );
+      token = new Token( token.getParameterName(), token.getOriginalPattern(), Segment.STAR_PATTERN, token.isLiteral() );
     }
     return token;
   }
@@ -143,28 +151,28 @@ public class Parser {
 //    return pattern;
 //  }
 
-  private void consumeSchemeMatch( Matcher match ) {
+  private static void consumeSchemeMatch( final Builder builder, final Matcher match ) {
     if( match.group( MATCH_GROUP_SCHEME ) != null ) {
       builder.setHasScheme( true );
-      consumeSchemeToken( match.group( MATCH_GROUP_SCHEME_NAKED ) );
+      consumeSchemeToken( builder, match.group( MATCH_GROUP_SCHEME_NAKED ) );
     }
   }
 
-  private void consumeSchemeToken( String token ) {
+  private static void consumeSchemeToken( final Builder builder, final String token ) {
     if( token != null ) {
-      Token t = parseTemplateToken( token, Segment.STAR_PATTERN );
+      Token t = parseTemplateToken( builder, token, Segment.STAR_PATTERN );
       builder.setScheme( t );
     }
   }
 
-  private void consumeAuthorityMatch( Matcher match ) {
+  private static void consumeAuthorityMatch( final Builder builder, final Matcher match ) {
     if( match.group( MATCH_GROUP_AUTHORITY ) != null ) {
       builder.setHasAuthority( true );
-      consumeAuthorityToken( match.group( MATCH_GROUP_AUTHORITY_NAKED ) );
+      consumeAuthorityToken( builder, match.group( MATCH_GROUP_AUTHORITY_NAKED ) );
     }
   }
 
-  private void consumeAuthorityToken( String token ) {
+  private static void consumeAuthorityToken( final Builder builder, final String token ) {
     if( token != null ) {
       Token paramPattern;
       String[] usernamePassword=null, hostPort;
@@ -177,115 +185,115 @@ public class Parser {
       }
       if( usernamePassword != null ) {
         if( usernamePassword[ 0 ].length() > 0 ) {
-          paramPattern = makeTokenSingular( parseTemplateToken( usernamePassword[ 0 ], Segment.STAR_PATTERN ) );
+          paramPattern = makeTokenSingular( parseTemplateToken( builder, usernamePassword[ 0 ], Segment.STAR_PATTERN ) );
           builder.setUsername( paramPattern );
         }
         if( usernamePassword.length > 1 && usernamePassword[ 1 ].length() > 0 ) {
-          paramPattern = makeTokenSingular( parseTemplateToken( usernamePassword[ 1 ], Segment.STAR_PATTERN ) );
+          paramPattern = makeTokenSingular( parseTemplateToken( builder, usernamePassword[ 1 ], Segment.STAR_PATTERN ) );
           builder.setPassword( paramPattern );
         }
       }
       if( hostPort[ 0 ].length() > 0 ) {
-        paramPattern = makeTokenSingular( parseTemplateToken( hostPort[ 0 ], Segment.STAR_PATTERN ) );
+        paramPattern = makeTokenSingular( parseTemplateToken( builder, hostPort[ 0 ], Segment.STAR_PATTERN ) );
         builder.setHost( paramPattern );
       }
       if( hostPort.length > 1 && hostPort[ 1 ].length() > 0 ) {
-        paramPattern = makeTokenSingular( parseTemplateToken( hostPort[ 1 ], Segment.STAR_PATTERN ) );
+        paramPattern = makeTokenSingular( parseTemplateToken( builder, hostPort[ 1 ], Segment.STAR_PATTERN ) );
         builder.setPort( paramPattern );
       }
     }
   }
 
-  private void consumePathMatch( Matcher match ) {
+  private static void consumePathMatch( final Builder builder, final Matcher match ) {
     String path = match.group( MATCH_GROUP_PATH );
     if( path != null ) {
       builder.setIsAbsolute( path.startsWith( "/" ) );
       builder.setIsDirectory( path.endsWith( "/" ) );
-      consumePathToken( path );
+      consumePathToken( builder, path );
     }
   }
 
-  private final void consumePathToken( final String token ) {
+  private static final void consumePathToken( final Builder builder, final String token ) {
     if( token != null ) {
       final StringTokenizer tokenizer = new StringTokenizer( token, "/" );
       while( tokenizer.hasMoreTokens() ) {
-        consumePathSegment( tokenizer.nextToken() );
+        consumePathSegment( builder, tokenizer.nextToken() );
       }
     }
   }
 
-  private final void consumePathSegment( final String token ) {
+  private static final void consumePathSegment( final Builder builder, final String token ) {
     if( token != null ) {
-      final Token t = parseTemplateToken( token, Segment.GLOB_PATTERN );
+      final Token t = parseTemplateToken( builder, token, Segment.GLOB_PATTERN );
       builder.addPath( t );
     }
   }
 
-  private void consumeQueryMatch( Matcher match ) {
+  private static void consumeQueryMatch( final Builder builder, Matcher match ) {
     if( match.group( MATCH_GROUP_QUERY ) != null ) {
       builder.setHasQuery( true );
-      consumeQueryToken( match.group( MATCH_GROUP_QUERY_NAKED ) );
+      consumeQueryToken( builder, match.group( MATCH_GROUP_QUERY_NAKED ) );
     }
   }
 
-  private void consumeQueryToken( String token ) {
+  private static void consumeQueryToken( final Builder builder, String token ) {
     if( token != null ) {
       StringTokenizer tokenizer = new StringTokenizer( token, "?&" );
       while( tokenizer.hasMoreTokens() ) {
-        consumeQuerySegment( tokenizer.nextToken() );
+        consumeQuerySegment( builder, tokenizer.nextToken() );
       }
     }
   }
 
-  private void consumeQuerySegment( String token ) {
+  private static void consumeQuerySegment( final Builder builder, String token ) {
     if( token != null && token.length() > 0 ) {
       // Shorthand format {queryParam} == queryParam={queryParam=*}
       if( TEMPLATE_OPEN_MARKUP == token.charAt( 0 ) ) {
-        Token paramPattern = parseTemplateToken( token, Segment.GLOB_PATTERN );
+        Token paramPattern = parseTemplateToken( builder, token, Segment.GLOB_PATTERN );
         String paramName = paramPattern.parameterName;
         if( paramPattern.originalPattern == null ) {
-          builder.addQuery( paramName, new Token( paramName, null, Segment.GLOB_PATTERN ) );
+          builder.addQuery( paramName, new Token( paramName, null, Segment.GLOB_PATTERN, builder.isLiteral() ) );
 //          if( Segment.STAR_PATTERN.equals( paramName ) || Segment.GLOB_PATTERN.equals( paramName ) ) {
 //            builder.addQuery( paramName, new Token( paramName, null, Segment.GLOB_PATTERN ) );
 //          } else {
 //            builder.addQuery( paramName, new Token( paramName, null, Segment.GLOB_PATTERN ) );
 //          }
         } else {
-          builder.addQuery( paramName, new Token( paramName, paramPattern.originalPattern ) );
+          builder.addQuery( paramName, new Token( paramName, paramPattern.originalPattern, builder.isLiteral() ) );
         }
       } else {
         String nameValue[] = split( token, '=' );
         if( nameValue.length == 1 ) {
           String queryName = nameValue[ 0 ];
-          builder.addQuery( queryName, new Token( Segment.ANONYMOUS_PARAM, null ) );
+          builder.addQuery( queryName, new Token( Segment.ANONYMOUS_PARAM, null, builder.isLiteral() ) );
         } else {
           String queryName = nameValue[ 0 ];
-          Token paramPattern = parseTemplateToken( nameValue[ 1 ], Segment.GLOB_PATTERN );
+          Token paramPattern = parseTemplateToken( builder, nameValue[ 1 ], Segment.GLOB_PATTERN );
           builder.addQuery( queryName, paramPattern );
         }
       }
     }
   }
 
-  private void consumeFragmentMatch( Matcher match ) {
+  private static void consumeFragmentMatch( final Builder builder, Matcher match ) {
     if( match.group( MATCH_GROUP_FRAGMENT ) != null ) {
       builder.setHasFragment( true );
-      consumeFragmentToken( match.group( MATCH_GROUP_FRAGMENT_NAKED ) );
+      consumeFragmentToken( builder, match.group( MATCH_GROUP_FRAGMENT_NAKED ) );
     }
   }
 
-  private void consumeFragmentToken( String token ) {
+  private static void consumeFragmentToken( final Builder builder, String token ) {
     if( token != null && token.length() > 0 ) {
-      Token t = parseTemplateToken( token, Segment.STAR_PATTERN );
+      Token t = parseTemplateToken( builder, token, Segment.STAR_PATTERN );
       builder.setFragment( t );
     }
   }
 
-  static final Token parseTemplateToken( final String s, final String defaultEffectivePattern ) {
+  static final Token parseTemplateToken( final Builder builder, final String s, final String defaultEffectivePattern ) {
     String paramName, actualPattern, effectivePattern;
     final int l = s.length();
     // If the token isn't the empty string, then
-    if( l > 0 ) {
+    if( l > 0 && !builder.isLiteral() ) {
       final int b = ( s.charAt( 0 ) == TEMPLATE_OPEN_MARKUP ? 1 : -1 );
       final int e = ( s.charAt( l-1 ) == TEMPLATE_CLOSE_MARKUP ? l-1 : -1 );
       // If this is a parameter template, ie {...}
@@ -318,7 +326,7 @@ public class Parser {
       actualPattern = s;
       effectivePattern = actualPattern;
     }
-    final Token token = new Token( paramName, actualPattern, effectivePattern );
+    final Token token = new Token( paramName, actualPattern, effectivePattern, builder.isLiteral() );
     return token;
   }
 

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

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Path.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Path.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Path.java
index 6bf55b0..6860e9b 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Path.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Path.java
@@ -19,8 +19,8 @@ package org.apache.hadoop.gateway.util.urltemplate;
 
 public class Path extends Segment {
 
-  public Path( String paramName, String pathPattern ) {
-    super( new Token( paramName, pathPattern ) );
+  public Path( String paramName, String pathPattern, boolean literal ) {
+    super( new Token( paramName, pathPattern, literal ) );
   }
 
   public Path( Path that ) {

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

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Query.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Query.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Query.java
index f77f231..d5043da 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Query.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Query.java
@@ -21,8 +21,8 @@ public class Query extends Segment {
 
   private String queryName;
 
-  public Query( String queryName, String paramName, String valuePattern ) {
-    super( new Token( paramName, valuePattern ) );
+  public Query( String queryName, String paramName, String valuePattern, boolean literal ) {
+    super( new Token( paramName, valuePattern, literal ) );
     this.queryName = queryName;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Rewriter.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Rewriter.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Rewriter.java
index ebe7e15..bb140fe 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Rewriter.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Rewriter.java
@@ -41,7 +41,7 @@ public class Rewriter {
       throws URISyntaxException {
     Rewriter rewriter = new Rewriter();
     rewriter.addRule( inputTemplate, outputTemplate );
-    Template inputUriTemplate = Parser.parse( inputUri.toString() );
+    Template inputUriTemplate = Parser.parseLiteral( inputUri.toString() );
     return rewriter.rewrite( inputUriTemplate, resolver, evaluator );
   }
 

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

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Segment.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Segment.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Segment.java
index 14e366d..8f9c819 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Segment.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Segment.java
@@ -164,7 +164,9 @@ abstract class Segment {
       this.token = token;
       this.regex = null;
       String effectivePattern = token.effectivePattern;
-      if( DEFAULT_PATTERN.equals( effectivePattern ) ) {
+      if( token.isLiteral() ) {
+        this.type = STATIC;
+      } else if( DEFAULT_PATTERN.equals( effectivePattern ) ) {
         this.type = DEFAULT;
       } else if( STAR_PATTERN.equals( effectivePattern ) ) {
         this.type = STAR;

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Token.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Token.java b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Token.java
index 5602df2..771a4b9 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Token.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Token.java
@@ -22,15 +22,17 @@ final class Token {
   String parameterName = null;
   String originalPattern = null;
   String effectivePattern = null;
+  boolean literal = false;
 
-  Token( String parameterName, String originalPattern, String effectivePattern ) {
+  Token( String parameterName, String originalPattern, String effectivePattern, boolean literal ) {
     this.parameterName = parameterName;
     this.originalPattern = originalPattern;
     this.effectivePattern = effectivePattern;
+    this.literal = literal;
   }
 
-  Token( String parameterName, String originalPattern ) {
-    this( parameterName, originalPattern, originalPattern );
+  Token( String parameterName, String originalPattern, boolean literal ) {
+    this( parameterName, originalPattern, originalPattern, literal );
   }
 
   public String getParameterName() {
@@ -45,5 +47,9 @@ final class Token {
     return effectivePattern;
   }
 
+  public boolean isLiteral() {
+    return literal;
+  }
+
 }
 

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

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
index 816144c..7c91e6e 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
@@ -31,6 +31,7 @@ import java.util.List;
 import static junit.framework.TestCase.assertNotNull;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalToIgnoringCase;
 import static org.junit.Assert.assertThat;
@@ -42,7 +43,7 @@ public class ExpanderTest {
   @Test
   public void testHostAndPortOnlyExpansionBugKnox381() throws Exception {
     String text = "{host}:{port}";
-    Template template = Parser.parse( text );
+    Template template = Parser.parseTemplate( text );
     MockParams params = new MockParams();
     params.addValue( "host", "test-host" );
     params.addValue( "port", "777" );
@@ -58,13 +59,13 @@ public class ExpanderTest {
     URI expanded;
 
     text = "foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose";
-    template = Parser.parse( text );
+    template = Parser.parseLiteral( text );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( text ) ) ;
 
     text = "{scheme}://{username}:{password}@{host}:{port}/{path=**}?query={queryParam}#{fragment}";
-    template = Parser.parse( text );
+    template = Parser.parseTemplate( text );
     params = new MockParams();
     params.addValue( "scheme", "http" );
     params.addValue( "username", "horton" );
@@ -87,89 +88,89 @@ public class ExpanderTest {
     MockParams params;
     URI expanded;
 
-    template = Parser.parse( "" );
+    template = Parser.parseTemplate( "" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "" ) ) ;
 
-    template = Parser.parse( "/" );
+    template = Parser.parseTemplate( "/" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/" ) ) ;
 
-    template = Parser.parse( "{path-name}" );
+    template = Parser.parseTemplate( "{path-name}" );
     params = new MockParams();
     params.addValue( "path-name", "path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "path-value" ) ) ;
 
-    template = Parser.parse( "/{path-name}" );
+    template = Parser.parseTemplate( "/{path-name}" );
     params = new MockParams();
     params.addValue( "path-name", "path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/path-value" ) ) ;
 
-    template = Parser.parse( "{path-name}/" );
+    template = Parser.parseTemplate( "{path-name}/" );
     params = new MockParams();
     params.addValue( "path-name", "path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "path-value/" ) ) ;
 
-    template = Parser.parse( "/{path-name}/" );
+    template = Parser.parseTemplate( "/{path-name}/" );
     params = new MockParams();
     params.addValue( "path-name", "path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/path-value/" ) ) ;
 
-    template = Parser.parse( "path-name" );
+    template = Parser.parseTemplate( "path-name" );
     params = new MockParams();
     params.addValue( "path-name", "other-path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "path-name" ) ) ;
 
-    template = Parser.parse( "/path-name" );
+    template = Parser.parseTemplate( "/path-name" );
     params = new MockParams();
     params.addValue( "path-name", "other-path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/path-name" ) ) ;
 
-    template = Parser.parse( "path-name/" );
+    template = Parser.parseTemplate( "path-name/" );
     params = new MockParams();
     params.addValue( "path-name", "other-path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "path-name/" ) ) ;
 
-    template = Parser.parse( "/path-name/" );
+    template = Parser.parseTemplate( "/path-name/" );
     params = new MockParams();
     params.addValue( "path-name", "other-path-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/path-name/" ) ) ;
 
-    template = Parser.parse( "?" );
+    template = Parser.parseTemplate( "?" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "" ) ) ;
 
-    template = Parser.parse( "?query-name={queryParam-name}" );
+    template = Parser.parseTemplate( "?query-name={queryParam-name}" );
     params = new MockParams();
     params.addValue( "queryParam-name", "queryParam-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query-name=queryParam-value" ) ) ;
 
-    template = Parser.parse( "?query-name-1={queryParam-name-1}&query-name-2={queryParam-name-2}" );
+    template = Parser.parseTemplate( "?query-name-1={queryParam-name-1}&query-name-2={queryParam-name-2}" );
     params = new MockParams();
     params.addValue( "queryParam-name-1", "queryParam-value-1" );
     params.addValue( "queryParam-name-2", "queryParam-value-2" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query-name-1=queryParam-value-1&query-name-2=queryParam-value-2" ) ) ;
 
-    template = Parser.parse( "?query-name=queryParam-value" );
+    template = Parser.parseTemplate( "?query-name=queryParam-value" );
     params = new MockParams();
     params.addValue( "queryParam-name", "other-queryParam-value" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query-name=queryParam-value" ) ) ;
 
-    template = Parser.parse( "?query-name-1=queryParam-value-1&query-name-2=queryParam-value-2" );
+    template = Parser.parseTemplate( "?query-name-1=queryParam-value-1&query-name-2=queryParam-value-2" );
     params = new MockParams();
     params.addValue( "queryParam-name-1", "other-queryParam-value-1" );
     params.addValue( "queryParam-name-2", "other-queryParam-value-2" );
@@ -196,22 +197,22 @@ public class ExpanderTest {
     MockParams params;
     URI expanded;
 
-    template = Parser.parse( "//host" );
+    template = Parser.parseTemplate( "//host" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "//host" ) ) ;
 
-    template = Parser.parse( "//:port" );
+    template = Parser.parseTemplate( "//:port" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "//:port" ) ) ;
 
-    template = Parser.parse( "//username@" );
+    template = Parser.parseTemplate( "//username@" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "//username@" ) ) ;
 
-    template = Parser.parse( "//:password@" );
+    template = Parser.parseTemplate( "//:password@" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "//:password@" ) ) ;
@@ -223,26 +224,26 @@ public class ExpanderTest {
     MockParams params;
     URI expanded;
 
-    template = Parser.parse( "/a/b/c" );
+    template = Parser.parseTemplate( "/a/b/c" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/a/b/c" ) ) ;
 
-    template = Parser.parse( "/top/{middle}/bottom" );
+    template = Parser.parseTemplate( "/top/{middle}/bottom" );
     params = new MockParams();
     params.addValue( "middle", "A" );
     params.addValue( "middle", "B" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/top/A/B/bottom" ) ) ;
 
-    template = Parser.parse( "/top/{middle=*}/bottom" );
+    template = Parser.parseTemplate( "/top/{middle=*}/bottom" );
     params = new MockParams();
     params.addValue( "middle", "A" );
     params.addValue( "middle", "B" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "/top/A/bottom" ) ) ;
 
-    template = Parser.parse( "/top/{middle=**}/bottom" );
+    template = Parser.parseTemplate( "/top/{middle=**}/bottom" );
     params = new MockParams();
     params.addValue( "middle", "A" );
     params.addValue( "middle", "B" );
@@ -256,26 +257,26 @@ public class ExpanderTest {
     MockParams params;
     URI expanded;
 
-    template = Parser.parse( "?query" );
+    template = Parser.parseTemplate( "?query" );
     params = new MockParams();
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query" ) ) ;
 
-    template = Parser.parse( "?query={queryParam}" );
+    template = Parser.parseTemplate( "?query={queryParam}" );
     params = new MockParams();
     params.addValue( "queryParam", "A" );
     params.addValue( "queryParam", "B" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query=A&query=B" ) ) ;
 
-    template = Parser.parse( "?query={queryParam=*}" );
+    template = Parser.parseTemplate( "?query={queryParam=*}" );
     params = new MockParams();
     params.addValue( "queryParam", "A" );
     params.addValue( "queryParam", "B" );
     expanded = Expander.expand( template, params, null );
     assertThat( expanded.toString(), equalTo( "?query=A" ) ) ;
 
-    template = Parser.parse( "?query={queryParam=**}" );
+    template = Parser.parseTemplate( "?query={queryParam=**}" );
     params = new MockParams();
     params.addValue( "queryParam", "A" );
     params.addValue( "queryParam", "B" );
@@ -303,7 +304,7 @@ public class ExpanderTest {
     params.addValue( "extra", "extraA" );
 
     text = "{scheme}://host/{path=*]?{query=*}";
-    template = Parser.parse( text );
+    template = Parser.parseTemplate( text );
     expandedTemplate = Expander.expandToTemplate( template, params, null );
     assertThat( expandedTemplate.toString(), equalTo( "schemeA://host/{path=*]?query=queryA" ) );
     expandedString = Expander.expandToString( template, params, null );
@@ -315,17 +316,17 @@ public class ExpanderTest {
       // Expected.
     }
 
-    template = Parser.parse( "{scheme}://host/{path=**}?{query=**}" );
+    template = Parser.parseTemplate( "{scheme}://host/{path=**}?{query=**}" );
     expandedUri = Expander.expand( template, params, null );
     assertThat( expandedUri.toString(), equalTo( "schemeA://host/pathA/pathB?query=queryA&query=queryB" ) );
 
-    template = Parser.parse( "{scheme}://host/{path=**}?{host}&{query=**}&{**}" );
+    template = Parser.parseTemplate( "{scheme}://host/{path=**}?{host}&{query=**}&{**}" );
     expandedUri = Expander.expand( template, params, null );
     assertThat(
         expandedUri.toString(),
         equalTo( "schemeA://host/pathA/pathB?host=hostA&query=queryA&query=queryB&extra=extraA" ) );
 
-    template = Parser.parse( "{scheme}://host/{path=**}?server={host}&{query=**}&{**}" );
+    template = Parser.parseTemplate( "{scheme}://host/{path=**}?server={host}&{query=**}&{**}" );
     expandedUri = Expander.expand( template, params, null );
     assertThat(
         expandedUri.toString(),
@@ -334,7 +335,7 @@ public class ExpanderTest {
     // In this case "server-host" is treated as a param name and not found in the params so it
     // is copied.  I'm not really sure what the correct behavior should be.  My initial thinking
     // is that if something within {} isn't resolve to a param it should be dropped from the output.
-    template = Parser.parse( "{scheme}://host/{path=**}?{server=host}&{query=**}&{**}" );
+    template = Parser.parseTemplate( "{scheme}://host/{path=**}?{server=host}&{query=**}&{**}" );
     expandedUri = Expander.expand( template, params, null );
     expandedString = expandedUri.toString();
     assertThat( expandedString, containsString( "schemeA://host/pathA/pathB?" ) );
@@ -355,7 +356,7 @@ public class ExpanderTest {
     URI expanded;
 
     text = "{scheme}://{host}:{port}/{path=**}?{**}";
-    template = Parser.parse( text );
+    template = Parser.parseTemplate( text );
     params = new MockParams();
     params.addValue( "scheme", "http" );
     params.addValue( "host", "hortonworks.com" );
@@ -370,7 +371,7 @@ public class ExpanderTest {
     assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?flag=&name=value" ) ) ;
 
     text = "{scheme}://{host}:{port}/{path=**}?{**}";
-    template = Parser.parse( text );
+    template = Parser.parseTemplate( text );
     params = new MockParams();
     params.addValue( "scheme", "http" );
     params.addValue( "host", "hortonworks.com" );
@@ -385,7 +386,7 @@ public class ExpanderTest {
     assertThat( expanded.toString(), equalTo( "http://hortonworks.com:8888/top/mid/bot/file?flag&name=value" ) ) ;
 
     text = "{scheme}://{host}:{port}/{path=**}?{name=*}&{**}";
-    template = Parser.parse( text );
+    template = Parser.parseTemplate( text );
     params = new MockParams();
     params.addValue( "scheme", "http" );
     params.addValue( "host", "hortonworks.com" );
@@ -410,9 +411,9 @@ public class ExpanderTest {
 
     inputUri = new URI( "https://knoxHost:8443/gateway/knoxTopo/templeton/v1/?version/hive" );
 
-    input = Parser.parse( inputUri.toString() );
-    pattern = Parser.parse( "*://*:*/**/templeton/v1/?{**}" );
-    template = Parser.parse( "{$serviceUrl[WEBHCAT]}/v1/?{**}" );
+    input = Parser.parseLiteral( inputUri.toString() );
+    pattern = Parser.parseTemplate( "*://*:*/**/templeton/v1/?{**}" );
+    template = Parser.parseTemplate( "{$serviceUrl[WEBHCAT]}/v1/?{**}" );
 
     matcher = new Matcher<Void>();
     matcher.add( pattern, null );
@@ -442,9 +443,9 @@ public class ExpanderTest {
 
     inputUri = new URI("https://internal-host:9443/context/?user.name=admin#/login");
 
-    input = Parser.parse( inputUri.toString() );
-    pattern = Parser.parse( "*://*:*/{contextRoot}/?{**}#{fragment}" );
-    template = Parser.parse( "{$gateway.url}/foo/{contextRoot}/?{**}#{fragment}" );
+    input = Parser.parseLiteral( inputUri.toString() );
+    pattern = Parser.parseTemplate( "*://*:*/{contextRoot}/?{**}#{fragment}" );
+    template = Parser.parseTemplate( "{$gateway.url}/foo/{contextRoot}/?{**}#{fragment}" );
 
     matcher = new Matcher<Void>();
     matcher.add( pattern, null );
@@ -464,4 +465,77 @@ public class ExpanderTest {
         is( "https://gateway-host:9443/gateway/default/foo/context/?user.name=admin#/login" ) );
   }
 
+  @Test
+  public void testLiteralsAndRegexInTemplates() throws Exception {
+    String output;
+    Matcher<Void> matcher;
+    Matcher<Void>.Match match;
+    Template input, template, rewrite;
+    Evaluator evaluator;
+
+    evaluator = new Evaluator() {
+      @Override
+      public List<String> evaluate( String function, List<String> parameters ) {
+        return Arrays.asList( "https://gateway-host:9443/gateway/default" );
+      }
+    };
+
+    // Check to make sure that you can use constants within the {}
+    template = Parser.parseTemplate( "{root=ROOT}/{path=**}" );
+    rewrite = Parser.parseTemplate( "{root}/{path}" );
+    matcher = new Matcher<Void>();
+    matcher.add( template, null );
+    input = Parser.parseLiteral( "ROOT/child/path" );
+    match = matcher.match( input );
+    assertThat( match, notNullValue() );
+    output = Expander.expandToString( rewrite, match.getParams(), evaluator );
+    assertThat( output, is( "ROOT/child/path" ) );
+
+    // Check to see what happens when you use the special { character within the {}.
+    template = Parser.parseTemplate( "{root={}/{path=**}" );
+    rewrite = Parser.parseTemplate( "{root}/{path}" );
+    matcher = new Matcher<Void>();
+    matcher.add( template, null );
+    input = Parser.parseLiteral( "{/child/path" );
+    match = matcher.match( input );
+    assertThat( match, notNullValue() );
+    output = Expander.expandToString( rewrite, match.getParams(), evaluator );
+    assertThat( output, is( "{/child/path" ) );
+
+    // Check to see what happens when you use the special } character within the {}.
+    template = Parser.parseTemplate( "{root=}}/{path=**}" );
+    rewrite = Parser.parseTemplate( "{root}/{path}" );
+    matcher = new Matcher<Void>();
+    matcher.add( template, null );
+    input = Parser.parseLiteral( "}/child/path" );
+    match = matcher.match( input );
+    assertThat( match, notNullValue() );
+    output = Expander.expandToString( rewrite, match.getParams(), evaluator );
+    assertThat( output, is( "}/child/path" ) );
+
+    // Check to see what happens when you use the special } character within the {}.
+    template = Parser.parseTemplate( "{root={}}/{path=**}" );
+    rewrite = Parser.parseTemplate( "{root}/{path}" );
+    matcher = new Matcher<Void>();
+    matcher.add( template, null );
+    input = Parser.parseLiteral( "{}/child/path" );
+    match = matcher.match( input );
+    assertThat( match, notNullValue() );
+    output = Expander.expandToString( rewrite, match.getParams(), evaluator );
+    assertThat( output, is( "{}/child/path" ) );
+
+    template = Parser.parseTemplate( "{var=${*}}/{path=**}" );
+    rewrite = Parser.parseTemplate( "{var}/{path}" );
+
+    matcher = new Matcher<Void>();
+    matcher.add( template, null );
+
+    input = Parser.parseLiteral( "${app.dir}/child/path" );
+    match = matcher.match( input );
+    assertThat( match, notNullValue() );
+
+    output = Expander.expandToString( rewrite, match.getParams(), evaluator );
+    assertThat( output, is( "${app.dir}/child/path" ) );
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/33bb1ce5/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
index 4d09a47..362f26f 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
@@ -41,14 +41,14 @@ import static org.junit.Assert.assertThat;
 public class MatcherTest {
 
   private void addTemplate( Matcher<String> matcher, String template ) throws URISyntaxException {
-    matcher.add( Parser.parse( template ), template );
+    matcher.add( Parser.parseTemplate( template ), template );
   }
 
   private void assertValidMatch( Matcher<String> matcher, String uri, String template ) throws URISyntaxException {
     if( template == null ) {
-      assertThat( matcher.match( Parser.parse( uri ) ), nullValue() );
+      assertThat( matcher.match( Parser.parseTemplate( uri ) ), nullValue() );
     } else {
-      Template uriTemplate = Parser.parse( uri );
+      Template uriTemplate = Parser.parseTemplate( uri );
       Matcher<String>.Match match = matcher.match( uriTemplate );
       assertThat( "Expected to find a match.", match, notNullValue() );
       assertThat( match.getValue(), equalTo( template ) );
@@ -62,17 +62,17 @@ public class MatcherTest {
     Matcher<String>.Match match;
 
     matcher = new Matcher<String>();
-    patternTemplate = Parser.parse( "*://*:*/a/{pathB=**}/c" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/a/{pathB=**}/c" );
     matcher.add( patternTemplate, "webhdfs" );
-    inputTemplate = Parser.parse( "s://h:5/a/b1/b2/c" );
+    inputTemplate = Parser.parseLiteral( "s://h:5/a/b1/b2/c" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
     assertThat( match.getValue(), is( "webhdfs" ) );
     assertThat( match.getParams().resolve( "pathB" ), hasItems( "b1", "b2" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "s://h:5/a/b/c" );
-    patternTemplate = Parser.parse( "{scheme=*}://{host=*}:{port=*}/a/{pathB=**}/c" );
+    inputTemplate = Parser.parseLiteral( "s://h:5/a/b/c" );
+    patternTemplate = Parser.parseTemplate( "{scheme=*}://{host=*}:{port=*}/a/{pathB=**}/c" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
@@ -89,8 +89,8 @@ public class MatcherTest {
 //    assertThat( match.getValue(), is( "webhdfs" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "s://h:5/a/b" );
-    patternTemplate = Parser.parse( "{scheme=*}://{host=*}:{port=*}/{pathA=**}/b" );
+    inputTemplate = Parser.parseLiteral( "s://h:5/a/b" );
+    patternTemplate = Parser.parseTemplate( "{scheme=*}://{host=*}:{port=*}/{pathA=**}/b" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
@@ -113,32 +113,32 @@ public class MatcherTest {
     Matcher<String>.Match match;
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://127.0.0.1:8443/webhdfs/v1/tmp?op=LISTSTATUS" );
-    patternTemplate = Parser.parse( "*://*:*/webhdfs/{version}/{path=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1:8443/webhdfs/v1/tmp?op=LISTSTATUS" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/webhdfs/{version}/{path=**}?{**}" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
     assertThat( match.getValue(), is( "webhdfs" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://127.0.0.1:8443/top/webhdfs/v1/tmp?op=LISTSTATUS" );
-    patternTemplate = Parser.parse( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1:8443/top/webhdfs/v1/tmp?op=LISTSTATUS" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
     assertThat( match.getValue(), is( "webhdfs" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://127.0.0.1:8443/a/b/c" );
-    patternTemplate = Parser.parse( "*://*:*/**/c" );
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1:8443/a/b/c" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/c" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
     assertThat( match.getValue(), is( "webhdfs" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://127.0.0.1:8443/a/b/c/d" );
-    patternTemplate = Parser.parse( "*://*:*/{pathA=**}/b/{pathC=**}/d" );
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1:8443/a/b/c/d" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/{pathA=**}/b/{pathC=**}/d" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
@@ -147,8 +147,8 @@ public class MatcherTest {
     assertThat( match.getParams().resolve( "pathC" ), hasItems( "c" ) );
 
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://127.0.0.1:8443/a1/a2/b/c1/c2/d" );
-    patternTemplate = Parser.parse( "*://*:*/{pathA=**}/b/{pathC=**}/d" );
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1:8443/a1/a2/b/c1/c2/d" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/{pathA=**}/b/{pathC=**}/d" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
@@ -183,26 +183,26 @@ public class MatcherTest {
 
     // First verify that if .../test_table/test_row/family1... works.
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://localhost:8443/gateway/sandbox/hbase/test_table/test_row/family1:row2_col1,family2/0,9223372036854775807?v=1" );
-    patternTemplate = Parser.parse( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "https://localhost:8443/gateway/sandbox/hbase/test_table/test_row/family1:row2_col1,family2/0,9223372036854775807?v=1" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
 
     // Then reproduce the issue with .../test_table/*/family1..
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://localhost:8443/gateway/sandbox/hbase/test_table/*/family1:row2_col1,family2/0,9223372036854775807?v=1" );
-    patternTemplate = Parser.parse( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "https://localhost:8443/gateway/sandbox/hbase/test_table/*/family1:row2_col1,family2/0,9223372036854775807?v=1" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
     matcher.add( patternTemplate, "webhdfs" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
 
     // Reproduce the issue where the wrong match was picked when there was a "*" in the input URL template.
     matcher = new Matcher<String>();
-    inputTemplate = Parser.parse( "https://localhost:8443/gateway/sandbox/hbase/test_table/*/family1:row2_col1,family2/0,9223372036854775807?v=1" );
-    patternTemplate = Parser.parse( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "https://localhost:8443/gateway/sandbox/hbase/test_table/*/family1:row2_col1,family2/0,9223372036854775807?v=1" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/webhdfs/{version}/{path=**}?{**}" );
     matcher.add( patternTemplate, "webhdfs" );
-    patternTemplate = Parser.parse( "*://*:*/**/hbase/{path=**}?{**}" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**/hbase/{path=**}?{**}" );
     matcher.add( patternTemplate, "hbase" );
     match = matcher.match( inputTemplate );
     assertThat( match.getValue(), is( "hbase" ) );
@@ -215,52 +215,52 @@ public class MatcherTest {
     Matcher<String>.Match match;
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*" );
+    patternTemplate = Parser.parseTemplate( "*://*:*" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
-    inputTemplate = Parser.parse( "test-scheme://test-host:42" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*/" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
-    inputTemplate = Parser.parse( "test-scheme://test-host:42" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*/*" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/*" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
-    inputTemplate = Parser.parse( "test-scheme://test-host:42" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*/**" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/**" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
@@ -271,27 +271,27 @@ public class MatcherTest {
 //    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
 //    match = matcher.match( inputTemplate );
 //    assertThat( match, ? );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*/{path=*}" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/{path=*}" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
-    inputTemplate = Parser.parse( "test-scheme://test-host:42" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/" );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
 
     ///////
-    patternTemplate = Parser.parse( "*://*:*/{path=**}" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/{path=**}" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-match" );
 
@@ -302,7 +302,7 @@ public class MatcherTest {
 //    inputTemplate = Parser.parse( "test-scheme://test-host:42/" );
 //    match = matcher.match( inputTemplate );
 //    assertThat( match, ? );
-    inputTemplate = Parser.parse( "test-scheme://test-host:42/test-path" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host:42/test-path" );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
   }
@@ -313,15 +313,15 @@ public class MatcherTest {
     Template patternTemplate, inputTemplate;
     Matcher<String>.Match match;
 
-    patternTemplate = Parser.parse( "{*}://{host}:{*}/{**=**}?{**}" );
-    inputTemplate = Parser.parse( "test-scheme://test-input-host:42/test-path/test-file?test-name=test-value" );
+    patternTemplate = Parser.parseTemplate( "{*}://{host}:{*}/{**=**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-input-host:42/test-path/test-file?test-name=test-value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-math" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because the path ** should include both test-path and test-file", match, notNullValue() );
 
-    patternTemplate = Parser.parse( "{*}://{host}:{*}/{**}?{**}" );
-    inputTemplate = Parser.parse( "test-scheme://test-input-host:42/test-path/test-file?test-name=test-value" );
+    patternTemplate = Parser.parseTemplate( "{*}://{host}:{*}/{**}?{**}" );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-input-host:42/test-path/test-file?test-name=test-value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "test-math" );
     match = matcher.match( inputTemplate );
@@ -334,23 +334,23 @@ public class MatcherTest {
     Template patternTemplate, inputTemplate;
     Matcher<String>.Match match;
 
-    patternTemplate = Parser.parse( "/path?{query}" );
-    inputTemplate = Parser.parse( "/path" );
+    patternTemplate = Parser.parseTemplate( "/path?{query}" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should not match because input does not contain the required query.", match, nullValue() );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/path?{query}" ), "T1" );
-    matcher.add( Parser.parse( "/path" ), "T2" );
-    inputTemplate = Parser.parse( "/path" );
+    matcher.add( Parser.parseTemplate( "/path?{query}" ), "T1" );
+    matcher.add( Parser.parseTemplate( "/path" ), "T2" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because there is an entry in the matcher without a query.", match, notNullValue() );
     assertThat( match.getValue(), equalTo( "T2") );
 
-    patternTemplate = Parser.parse( "/path?{query}" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?{query}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -358,22 +358,22 @@ public class MatcherTest {
     assertThat( match.getParams().resolve( "query" ), hasItem( "value" ) );
     assertThat( match.getParams().resolve( "query" ).size(), equalTo( 1 ) );
 
-    patternTemplate = Parser.parse( "/path?{*}" );
-    inputTemplate = Parser.parse( "/path" );
+    patternTemplate = Parser.parseTemplate( "/path?{*}" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should not match because input does not contain the required query.", match, nullValue() );
 
-    patternTemplate = Parser.parse( "/path?*" );
-    inputTemplate = Parser.parse( "/path" );
+    patternTemplate = Parser.parseTemplate( "/path?*" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should not match because input does not contain the required query.", match, nullValue() );
 
-    patternTemplate = Parser.parse( "/path?*" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?*" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -384,38 +384,38 @@ public class MatcherTest {
         "Should not have extracts any parameters since pattern template didn't contain {}",
         match.getParams().resolve( "query" ), nullValue() );
 
-    patternTemplate = Parser.parse( "/path?{*}" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?{*}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because input does contain the required query.", match, notNullValue() );
     assertThat( match.getParams().resolve( "query" ), hasItem( "value" ) );
 
-    patternTemplate = Parser.parse( "/path?{**}" );
-    inputTemplate = Parser.parse( "/path" );
+    patternTemplate = Parser.parseTemplate( "/path?{**}" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because the template has an optional query.", match, notNullValue() );
 
-    patternTemplate = Parser.parse( "/path?**" );
-    inputTemplate = Parser.parse( "/path" );
+    patternTemplate = Parser.parseTemplate( "/path?**" );
+    inputTemplate = Parser.parseLiteral( "/path" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because the template has an optional extra query.", match, notNullValue() );
 
-    patternTemplate = Parser.parse( "/path?**" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?**" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should match because the template has an optional extra query.", match, notNullValue() );
     assertThat( match.getParams().resolve( "query" ), nullValue() );
 
-    patternTemplate = Parser.parse( "/path?{**}" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?{**}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -423,15 +423,15 @@ public class MatcherTest {
     assertThat( match.getParams().resolve( "query" ), hasItem( "value" ) );
     assertThat( match.getParams().resolve( "query" ).size(), equalTo( 1 ) );
 
-    patternTemplate = Parser.parse( "/path?{query}&{*}" );
-    inputTemplate = Parser.parse( "/path?query=value" );
+    patternTemplate = Parser.parseTemplate( "/path?{query}&{*}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
     assertThat( "Should not match because input does not contain the required extra query.", match, nullValue() );
 
-    patternTemplate = Parser.parse( "/path?{query}&{*}" );
-    inputTemplate = Parser.parse( "/path?query=value&extra=extra-value" );
+    patternTemplate = Parser.parseTemplate( "/path?{query}&{*}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value&extra=extra-value" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -439,8 +439,8 @@ public class MatcherTest {
     assertThat( match.getParams().resolve( "query" ), hasItem( "value" ) );
     assertThat( match.getParams().resolve( "query" ).size(), equalTo( 1 ) );
 
-    patternTemplate = Parser.parse( "/path?{query=**}" );
-    inputTemplate = Parser.parse( "/path?query=value1&query=value2" );
+    patternTemplate = Parser.parseTemplate( "/path?{query=**}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value1&query=value2" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -449,8 +449,8 @@ public class MatcherTest {
     assertThat( match.getParams().resolve( "query" ), hasItem( "value2" ) );
     assertThat( match.getParams().resolve( "query" ).size(), equalTo( 2 ) );
 
-    patternTemplate = Parser.parse( "/path?{query}" );
-    inputTemplate = Parser.parse( "/path?query=value1&query=value2" );
+    patternTemplate = Parser.parseTemplate( "/path?{query}" );
+    inputTemplate = Parser.parseLiteral( "/path?query=value1&query=value2" );
     matcher = new Matcher<String>();
     matcher.add( patternTemplate, "T" );
     match = matcher.match( inputTemplate );
@@ -469,26 +469,26 @@ public class MatcherTest {
 
     matcher = new Matcher<String>();
     pattern = "foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "foo://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
 
     input = pattern;
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match, notNullValue() );
 
     input = "not://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match, nullValue() );
   }
@@ -502,11 +502,11 @@ public class MatcherTest {
 
     matcher = new Matcher<String>();
     pattern = "path";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     assertThat( matcher.get( patternTemplate ), is( pattern ) );
     input = "path";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
@@ -514,50 +514,50 @@ public class MatcherTest {
 
     matcher = new Matcher<String>();
     pattern = "/path";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "/path";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "path/path";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "path/path";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "*/path";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "pathA/path";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "**/path";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "pathA/pathB/path";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "path-1/{path=**}/path-4";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "path-1/path-2/path-3/path-4";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
@@ -566,20 +566,20 @@ public class MatcherTest {
 
     matcher = new Matcher<String>();
     pattern = "/";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "/";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
 
     matcher = new Matcher<String>();
     pattern = "";
-    patternTemplate = Parser.parse( pattern );
+    patternTemplate = Parser.parseTemplate( pattern );
     matcher.add( patternTemplate, pattern );
     input = "";
-    inputTemplate = Parser.parse( input );
+    inputTemplate = Parser.parseLiteral( input );
     match = matcher.match( inputTemplate );
     assertThat( match.getTemplate(), sameInstance( patternTemplate ) );
     assertThat( match.getValue(), equalTo( pattern ) );
@@ -588,14 +588,14 @@ public class MatcherTest {
   @Test
   public void testVariousPatterns() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs" ), "/webhdfs" );
-    matcher.add( Parser.parse( "/webhdfs/dfshealth.jsp" ), "/webhdfs/dfshealth.jsp" );
-    matcher.add( Parser.parse( "/webhdfs/*.jsp" ), "/webhdfs/*.jsp" );
-    matcher.add( Parser.parse( "/webhdfs/other.jsp" ), "/webhdfs/other.jsp" );
-    matcher.add( Parser.parse( "/webhdfs/*" ), "/webhdfs/*" );
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
-    matcher.add( Parser.parse( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
-    matcher.add( Parser.parse( "/webhdfs/**/middle/*.xml" ), "/webhdfs/**/middle/*.xml" );
+    matcher.add( Parser.parseTemplate( "/webhdfs" ), "/webhdfs" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/dfshealth.jsp" ), "/webhdfs/dfshealth.jsp" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/*.jsp" ), "/webhdfs/*.jsp" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/other.jsp" ), "/webhdfs/other.jsp" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/*" ), "/webhdfs/*" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**/middle/*.xml" ), "/webhdfs/**/middle/*.xml" );
 
     assertValidMatch( matcher, "/webhdfs", "/webhdfs" );
     assertValidMatch( matcher, "/webhdfs/dfshealth.jsp", "/webhdfs/dfshealth.jsp" );
@@ -612,7 +612,7 @@ public class MatcherTest {
   @Test
   public void testStar() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/*" ), "/webhdfs/*" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/*" ), "/webhdfs/*" );
     assertValidMatch( matcher, "/webhdfs/*", "/webhdfs/*" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/*" );
     assertValidMatch( matcher, "/webhdfs/path/", "/webhdfs/*" );
@@ -623,7 +623,7 @@ public class MatcherTest {
   @Test
   public void testGlob() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/path/", "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/path/file", "/webhdfs/**" );
@@ -633,23 +633,23 @@ public class MatcherTest {
   @Test
   public void testMatrixParam() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
-    matcher.add( Parser.parse( "/webhdfs/browseDirectory.jsp;dn=*" ), "/webhdfs/browseDirectory.jsp;dn=*" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/browseDirectory.jsp;dn=*" ), "/webhdfs/browseDirectory.jsp;dn=*" );
     assertValidMatch( matcher, "/webhdfs/browseDirectory.jsp;dn=X", "/webhdfs/browseDirectory.jsp;dn=*" );
   }
 
   @Test
   public void testTwoGlobsAtDifferentDepths() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
-    matcher.add( Parser.parse( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/v1/file", "/webhdfs/v1/**" );
 
     // Reverse the put order.
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/v1/**" ), "/webhdfs/v1/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/v1/file", "/webhdfs/v1/**" );
   }
@@ -657,15 +657,15 @@ public class MatcherTest {
   @Test
   public void testGlobsVsStarsAtSameDepth() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/*" ), "/webhdfs/*" );
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/*" ), "/webhdfs/*" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/*" ); // The star should be picked in preference to the glob.
     assertValidMatch( matcher, "/webhdfs/path/file", "/webhdfs/**" );
 
     // Reverse the put order.
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/webhdfs/**" ), "/webhdfs/**" );
-    matcher.add( Parser.parse( "/webhdfs/*" ), "/webhdfs/*" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/**" ), "/webhdfs/**" );
+    matcher.add( Parser.parseTemplate( "/webhdfs/*" ), "/webhdfs/*" );
     assertValidMatch( matcher, "/webhdfs/path/file", "/webhdfs/**" );
     assertValidMatch( matcher, "/webhdfs/file", "/webhdfs/*" );
   }
@@ -673,19 +673,19 @@ public class MatcherTest {
   @Test
   public void testMatchingPatternsWithinPathSegments() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/path/{file}" ), "default" );
+    matcher.add( Parser.parseTemplate( "/path/{file}" ), "default" );
     assertValidMatch( matcher, "/path/file-name", "default" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/path/{file=*}" ), "*" );
+    matcher.add( Parser.parseTemplate( "/path/{file=*}" ), "*" );
     assertValidMatch( matcher, "/path/some-name", "*" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/path/{more=**}" ), "**" );
+    matcher.add( Parser.parseTemplate( "/path/{more=**}" ), "**" );
     assertValidMatch( matcher, "/path/some-path/some-name", "**" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "/path/{regex=prefix*suffix}" ), "regex" );
+    matcher.add( Parser.parseTemplate( "/path/{regex=prefix*suffix}" ), "regex" );
     assertValidMatch( matcher, "/path/prefix-middle-suffix", "regex" );
     assertValidMatch( matcher, "/path/not-prefix-middle-suffix", null );
   }
@@ -693,19 +693,19 @@ public class MatcherTest {
   @Test
   public void testMatchingPatternsWithinQuerySegments() throws URISyntaxException {
     Matcher<String> matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "?query={queryParam}" ), "default" );
+    matcher.add( Parser.parseTemplate( "?query={queryParam}" ), "default" );
     assertValidMatch( matcher, "?query=value", "default" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "?query={queryParam=*}" ), "*" );
+    matcher.add( Parser.parseTemplate( "?query={queryParam=*}" ), "*" );
     assertValidMatch( matcher, "?query=some-value", "*" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "?query={queryParam=**}" ), "**" );
+    matcher.add( Parser.parseTemplate( "?query={queryParam=**}" ), "**" );
     assertValidMatch( matcher, "?query=some-value", "**" );
 
     matcher = new Matcher<String>();
-    matcher.add( Parser.parse( "?query={queryParam=prefix*suffix}" ), "regex" );
+    matcher.add( Parser.parseTemplate( "?query={queryParam=prefix*suffix}" ), "regex" );
     assertValidMatch( matcher, "?query=prefix-middle-suffix", "regex" );
     assertValidMatch( matcher, "?query=not-prefix-middle-suffix", null );
   }
@@ -730,8 +730,8 @@ public class MatcherTest {
     Matcher<?>.Match match;
     Params params;
 
-    template = Parser.parse( "{scheme}://{username}:{password}@{host}:{port}/{root}/{path}/{file}?queryA={paramA}&queryB={paramB}#{fragment}" );
-    input = Parser.parse( "http://horton:hadoop@hortonworks.com:80/top/middle/end?queryA=valueA&queryB=valueB#section" );
+    template = Parser.parseTemplate( "{scheme}://{username}:{password}@{host}:{port}/{root}/{path}/{file}?queryA={paramA}&queryB={paramB}#{fragment}" );
+    input = Parser.parseLiteral( "http://horton:hadoop@hortonworks.com:80/top/middle/end?queryA=valueA&queryB=valueB#section" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -793,11 +793,11 @@ public class MatcherTest {
 
     // This is just a reverse of the above.  The order caused a bug.
     stringMatcher = new Matcher<String>();
-    template = Parser.parse( "*://*:*/**/webhdfs/v1/{path=**}?{**=*}" );
+    template = Parser.parseTemplate( "*://*:*/**/webhdfs/v1/{path=**}?{**=*}" );
     stringMatcher.add( template, "test-value-B" );
-    template = Parser.parse( "*://*:*/**/webhdfs/data/v1/{path=**}?host={host=*}&port={port=*}&{**=*}" );
+    template = Parser.parseTemplate( "*://*:*/**/webhdfs/data/v1/{path=**}?host={host=*}&port={port=*}&{**=*}" );
     stringMatcher.add( template, "test-value-C" );
-    input = Parser.parse( "http://localhost:53221/gateway/cluster/webhdfs/v1/tmp/GatewayWebHdfsFuncTest/testBasicHdfsUseCase/dir?user.name=hdfs&op=MKDIRS" );
+    input = Parser.parseLiteral( "http://localhost:53221/gateway/cluster/webhdfs/v1/tmp/GatewayWebHdfsFuncTest/testBasicHdfsUseCase/dir?user.name=hdfs&op=MKDIRS" );
     match = stringMatcher.match( input );
     assertThat( match.getValue(), notNullValue() );
     assertThat( (String)match.getValue(), is( "test-value-B" ) );
@@ -812,8 +812,8 @@ public class MatcherTest {
     Matcher<?>.Match match;
     Params params;
 
-    template = Parser.parse( "{path-queryParam}" );
-    input = Parser.parse( "path-value" );
+    template = Parser.parseTemplate( "{path-queryParam}" );
+    input = Parser.parseLiteral( "path-value" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -823,8 +823,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path-queryParam" ).size(), equalTo( 1 ) );
     assertThat( params.resolve( "path-queryParam" ), hasItem( "path-value" ) );
 
-    template = Parser.parse( "/some-path/{path-queryParam}" );
-    input = Parser.parse( "/some-path/path-value" );
+    template = Parser.parseTemplate( "/some-path/{path-queryParam}" );
+    input = Parser.parseLiteral( "/some-path/path-value" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -834,8 +834,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path-queryParam" ).size(), equalTo( 1 ) );
     assertThat( params.resolve( "path-queryParam" ), hasItem( "path-value" ) );
 
-    template = Parser.parse( "/some-path/{path-queryParam}/some-other-path" );
-    input = Parser.parse( "/some-path/path-value/some-other-path" );
+    template = Parser.parseTemplate( "/some-path/{path-queryParam}/some-other-path" );
+    input = Parser.parseLiteral( "/some-path/path-value/some-other-path" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -845,8 +845,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path-queryParam" ).size(), equalTo( 1 ) );
     assertThat( params.resolve( "path-queryParam" ), hasItem( "path-value" ) );
 
-    template = Parser.parse( "{path=**}" );
-    input = Parser.parse( "A/B" );
+    template = Parser.parseTemplate( "{path=**}" );
+    input = Parser.parseLiteral( "A/B" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -857,8 +857,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path" ), hasItem( "A" ) );
     assertThat( params.resolve( "path" ), hasItem( "B" ) );
 
-    template = Parser.parse( "/top/{mid=**}/end" );
-    input = Parser.parse( "/top/A/B/end" );
+    template = Parser.parseTemplate( "/top/{mid=**}/end" );
+    input = Parser.parseLiteral( "/top/A/B/end" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -869,8 +869,8 @@ public class MatcherTest {
     assertThat( params.resolve( "mid" ), hasItem( "A" ) );
     assertThat( params.resolve( "mid" ), hasItem( "B" ) );
 
-    template = Parser.parse( "*://*:*/{path=**}?{**}" );
-    input = Parser.parse( "http://host:port/pathA/pathB" );
+    template = Parser.parseTemplate( "*://*:*/{path=**}?{**}" );
+    input = Parser.parseLiteral( "http://host:port/pathA/pathB" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -878,8 +878,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path" ), hasItem( "pathB" ) );
     assertThat( params.resolve( "path" ).size(), is( 2 ) );
 
-    template = Parser.parse( "*://*:*/{path=**}?{**}" );
-    input = Parser.parse( "http://host:port/pathA/pathB" );
+    template = Parser.parseTemplate( "*://*:*/{path=**}?{**}" );
+    input = Parser.parseLiteral( "http://host:port/pathA/pathB" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -887,8 +887,8 @@ public class MatcherTest {
     assertThat( params.resolve( "path" ), hasItem( "pathB" ) );
     assertThat( params.resolve( "path" ).size(), is( 2 ) );
 
-    template = Parser.parse( "*://*:*/{path=**}?{**}" );
-    input = Parser.parse( "http://host:port/pathA/pathB" );
+    template = Parser.parseTemplate( "*://*:*/{path=**}?{**}" );
+    input = Parser.parseLiteral( "http://host:port/pathA/pathB" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -905,8 +905,8 @@ public class MatcherTest {
     Matcher<?>.Match match;
     Params params;
 
-    template = Parser.parse( "?query-queryParam={queryParam-name}" );
-    input = Parser.parse( "?query-queryParam=queryParam-value" );
+    template = Parser.parseTemplate( "?query-queryParam={queryParam-name}" );
+    input = Parser.parseLiteral( "?query-queryParam=queryParam-value" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -916,8 +916,8 @@ public class MatcherTest {
     assertThat( params.resolve( "queryParam-name" ).size(), equalTo( 1 ) );
     assertThat( params.resolve( "queryParam-name" ), hasItem( "queryParam-value" ) );
 
-    template = Parser.parse( "?query-queryParam={queryParam-name}" );
-    input = Parser.parse( "?query-queryParam=queryParam-value" );
+    template = Parser.parseTemplate( "?query-queryParam={queryParam-name}" );
+    input = Parser.parseLiteral( "?query-queryParam=queryParam-value" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -936,8 +936,8 @@ public class MatcherTest {
     Matcher<?>.Match match;
     Params params;
 
-    template = Parser.parse( "" );
-    input = Parser.parse( "" );
+    template = Parser.parseTemplate( "" );
+    input = Parser.parseLiteral( "" );
     matcher = new Matcher<Void>( template, null );
     match = matcher.match( input );
     params = match.getParams();
@@ -953,16 +953,16 @@ public class MatcherTest {
     Matcher<?>.Match match;
 
     matcher = new Matcher<String>();
-    template = Parser.parse( "*://*:*/**/webhdfs/v1/{path=**}?{**}" );
+    template = Parser.parseTemplate( "*://*:*/**/webhdfs/v1/{path=**}?{**}" );
     matcher.add( template, "test-value" );
 
-    input = Parser.parse( "http://kminder-os-u14-23-knoxha-150922-1352-2.novalocal:1022/gateway/sandbox/webhdfs/v1/user/hrt_qa/knox-ha/knox_webhdfs_client_dir/test_file?op=CREATE&delegation=XXX&namenoderpcaddress=nameservice&createflag=&createparent=true&overwrite=true" );
+    input = Parser.parseLiteral( "http://kminder-os-u14-23-knoxha-150922-1352-2.novalocal:1022/gateway/sandbox/webhdfs/v1/user/hrt_qa/knox-ha/knox_webhdfs_client_dir/test_file?op=CREATE&delegation=XXX&namenoderpcaddress=nameservice&createflag=&createparent=true&overwrite=true" );
 
     match = matcher.match( input );
     assertThat( match, notNullValue() );
     assertThat( (String)match.getValue(), is( "test-value" ) );
 
-    template = Parser.parse( "http://host:42/root/webhdfs/v1/{path=**}?{**}" );
+    template = Parser.parseTemplate( "http://host:42/root/webhdfs/v1/{path=**}?{**}" );
     URI expandedUri = Expander.expand( template, match.getParams(), null );
     String expandedStr = expandedUri.toString();
     assertThat( expandedStr, containsString( "http://host:42/root/webhdfs/v1/user/hrt_qa/knox-ha/knox_webhdfs_client_dir/test_file?" ) );


Mime
View raw message