Hi Thierry,

Thanks you very much for ur help.

thanks
Prashant


> Hi,
> 
> if you let the default variable type (which is "URI_SEGMENT"),  
> "/language/temp/12345.12345/java/" will match 
> "/language/{var1}/{var2}/java/" and won't match "/language/{var1}/{var2}/" .
> 
> If you need to play with the variable types , things become difficult, 
> because when creating the routes, you need to know how to update such 
> variable for such route.
> A solution is to rely on a convention and to associate type and name of 
> a variable in the URI template: for example 
> "/language/{var1-digit}/{var2-all}/java/".
> By convention, you can say that  "var1-digit" means variable with name 
> "var1" and type "TYPE_DIGIT".
> This is not very pretty and is just an idea, but I don't see obvious and 
> simple solution since the start point is a map of key/value.
> 
> best regards,
> Thierry Boileau
> 
> 
> > Hi Thierry,
> >
> > Thanks for response.
> > At this point of time please ignore my first mail.
> > Currently
> > My use case is something like the one given below:
> >
> > I have a map object containing all the URIs to be attached in router.
> > Entries in this map are like:
> >
> > map.put("/language/{var1}/{var2}/java/","com.mypackage.Restlet1");
> >
> > map.put("/language/{var1}/{var2}/","com.mypackage.Restlet2");
> >
> > in my application class's createRoot() method 
> > I iterate over this map and attach each entry in router. 
> >
> > Now,I have a filter class and In beforeHandle() method of that class I am 
> > trying to iterate over each template from Router list and want to find out 
> > the exact matching template for the formatted  URI string from request i.e. 
> > /language/temp/12345.12345/java/
> > To achieve this I have written the code as given in my previous mail.
> >
> > But the code in previous mail does not match with exact URI but it matches 
> > with both the entries of map.
> >
> > So, my question is how should I modify my code to get only one entry i.e. 
> > /language/{var1}/{var2}/java/ for request 
> > /language/temp/12345.12345/java/ and not 
> > /language/{var1}/{var2}/
> >
> > Hope it clears.
> >
> > Thanks
> > Prashant
> >
> >   
> >> Hi Prashant,
> >>
> >> the problem is that the type of the variable is "Variable.TYPE_URI_ALL" 
> >> which means that it matches every characters. So 
> >> "/language/test/12345/java/" can match "/language/{var1}/{var2}/"
> >> with "var1 variable valuated to "test/12345" and "var2" to "java".
> >> By default, a variable matches a URI segment.
> >>
> >> Could you explain a little bit more your use case?
> >> Coming back to your first mail, you told us that "/language/12345/java/" 
> >> cannot match "/language/{var1}/{var2}/". But why? What are the rules 
> >> applied to each variables?
> >>
> >> Best regards,
> >> Thierry Boileau
> >> --
> >> Restlet ~ Core developer ~ http://www.restlet.org
> >> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
> >>
> >>     
> >>> Hi Thierry,
> >>>
> >>> Thank you very much for your response.
> >>> Whatever you explained its fine. But problem in my application is, I have 
> >>> to write code to match the incoming formatted URI with a template(stored 
> >>> in a collection).
> >>>
> >>> I am using Template.match(String) method in my code to match formatted 
> >>> URI with a template pattern. 
> >>>
> >>> Now, what this match method is doing it is returning two matches.
> >>>
> >>> E.g.
> >>> /language/{var1}/{var2}/
> >>> /language/{var1}/{var2}/java/
> >>>
> >>> If i send a request to my application with URI
> >>> /language/test/12345/java/
> >>>
> >>> and try to match using Template.match() method, it is returning 
> >>>
> >>> two results.
> >>>
> >>> Code is something like:
> >>>
> >>> Reference URI = request.getResourceRef();
> >>> Router router = (Router) getNext();
> >>> RouteList list = router.getRoutes();
> >>> Iterator<Route> itr = list.listIterator();
> >>> while(itr.hasNext())
> >>> {
> >>>   Route route = itr.next();
> >>>  route.getTemplate().getDefaultVariable().setType(Variable.TYPE_URI_ALL);
> >>>                   
> >>> route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
> >>>                   
> >>> if(route.getTemplate().match(URI.getRemainingPart())!=-1)
> >>> {
> >>> logger.debug("Match found:");
> >>> }
> >>> }
> >>>
> >>> The above given code logs "Match found:" two times for both the URIs.
> >>>
> >>>
> >>> Thanks
> >>> Prashant
> >>>
> >>>   
> >>>       
> >>>> Hello prashant,
> >>>>
> >>>> you can specify the type of a single variable as follow:
> >>>> Route route = router.attach("/language/{var1}/{var2}/", restlet1);
> >>>> route.getTemplate().getVariables().put("var1", new 
> >>>> Variable(Variable.TYPE_ALPHA));
> >>>>
> >>>>
> >>>> I also send you a sample application that illustrates this.
> >>>>
> >>>> best regards,
> >>>> Thierry Boileau
> >>>>
> >>>>     
> >>>>         
> >>>>> Hi All,
> >>>>>
> >>>>> I am new to Restlets even after working for around last 8 months on 
> >>>>> restlets. :-)
> >>>>>
> >>>>> I am facing a problem with my application.
> >>>>>
> >>>>> Description is as follows:
> >>>>>
> >>>>> In my application class I have two REST URIs as given below:
> >>>>>
> >>>>> (1st) "/language/{var1}/{var2}/"
> >>>>> (2nd) "/language/{var1}/{var2}/java/"
> >>>>>
> >>>>> I have also set Default matching mode of the router to MODE_EQUALS.
> >>>>>
> >>>>> Now, if I test second URI with not providing value for one of the 
> >>>>> varibales e.g.
> >>>>> /language/12345/java/ 
> >>>>> (Note: value for var1 is missing in this URI)
> >>>>>
> >>>>> My Router is matching this URI with first URI template and executes 
> >>>>> restlet class assgined to first URI i.e "/language/{var1}/{var2}/"
> >>>>>
> >>>>> Ideally if i have set matching mode to MODE_EQUALS for router it should 
> >>>>> show a message "server has not found anything matching requested URI" 
> >>>>> with response code "404".
> >>>>>
> >>>>> Please help me coming out of this problem. I have also tries with 
> >>>>> changin type of default varibale but no luck.
> >>>>>
> >>>>> Thanks in advance.
> >>>>> Prashant
> >>>>>
> >>>>> ------------------------------------------------------
> >>>>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=989509
> >>>>>           
> >
> >

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=991303

Reply via email to