java - URI template needs to match with variable value that is a set of folders -


i using org.springframework.web.util.uritemplate , trying match uri template:

http://{varname1}/path1/path2/{varname2}/{varname3}/{varname4} 

with following uri:

http://hostname/path1/path2/design/99999/product/schema/75016tc806aa/tc806aa.tar 

currently following uri variables:

{varname1=hostname, varname2=design/99999/product/schema, varname3=75016tc806aa,varname4=tc806aa.tar} 

but following uri variables:

{varname1=hostname, varname2=design varname3=99999, varname4=product/schema/75016tc806aa/tc806aa.tar} 

i tried use wildcards * or + in template, doesn't seems work:

http://{varname1}/path1/path2/{varname2}/{varname3}/{varname4*}  http://{varname1}/path1/path2/{varname2}/{varname3}/{+varname4} 

edited

string url = http://localhost/path1/path2/folder1/folder2/folder3/folder4/folder5 uritemplate uritemplate = new uritemplate(urltemplatetomatch); map<string, string> urivariables = uritemplate.match(url);  string urltemplatetomatch1 = http://{varname1}/path1/path2/{varname2}/{varname3}/{varname4} urivariables1 = {varname1=localhost, varname2=folder1/folder2/folder3, varname3=folder4, varname4=folder5}  string urltemplatetomatch2 = http://{varname1}/test1/test2/{varname2:.*?}/{varname3:.*?}/{varname4} urivariables2 = {varname1=localhost, varname2:.*?=folder1/folder2/folder3, varname3:.*?=folder4, varname4=folder5}  string urltemplatetomatch3 = http://{varname1}/test1/test2/{varname2:\\w*}/{varname3:.\\w*}/{varname4} urivariables3 = {varname1=localhost, varname2:\w*=folder1/folder2/folder3, varname3:\w*=folder4, varname4=folder5} 

try with:

http://{varname1}/path1/path2/{varname2:.*?}/{varname3:.*?}/{varname4}

or may

http://{varname1}/path1/path2/{varname2:\\w*}/{varname3:\\w*}/{varname4}

edit

@runwith(blockjunit4classrunner.class) public class uritemplatetest {      private string uri = "http://hostname/path1/path2/design/99999/product/schema/75016tc806aa/tc806aa.tar";     private string template_word = "http://{varname1}/path1/path2/{varname2:\\w*}/{varname3:\\w*}/{varname4}";     private string template_reluctant = "http://{varname1}/path1/path2/{varname2:.*?}/{varname3:.*?}/{varname4}";     private map<string, string> expected;      @before     public void init() {         expected = new hashmap<string, string>();         expected.put("varname1", "hostname");         expected.put("varname2", "design");         expected.put("varname3", "99999");         expected.put("varname4", "product/schema/75016tc806aa/tc806aa.tar");     }      @test     public void testtemplateword() {         testtemplate(template_word);     }      @test      public void testtemplatereluctant() {         testtemplate(template_reluctant);     }       private void testtemplate(string template) {         uritemplate ut = new uritemplate(template);         map<string, string> map = ut.match(uri);         assert.assertequals(expected, map);     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -