Hello,
Using Variable.TYPE_ALL is not a good solution in your case, since it
catches all characters.
If you use the default type, only the value of the segment (i.e., what
is inside two '/') will be caught.
It also simplifies your code:
router.attach("/neighbors/{ISO3}", NeighborsResource.class);
router.attach("/neighbors/{ISO3}/language/{lang}",
NeighborsByEachLanguageResource.class);
You can also use the TunnelService [1]. It helps to set the client's
preferences (typically the media type, and the language).
The idea is to have only one route:
router.attach("/neighbors/{ISO3}", NeighborsResource.class);
Then, there are two solutions:
1/ If you activate the extension filter (see the TunnelService), clients
can request "/neighbors/ken.en".
2/ If you activate the query filter (see the TunnelService), clients can
request "/neighbors/ken?language=en" (note that you can rename
"language" to "lang", or whatever suits you).
You are required to ensure your languages are registered in the
MetadataService of your application.
I hope this helps.
Best regards,
Thierry Boileau
[1]
http://www.restlet.org/documentation/1.1/api/org/restlet/service/TunnelService.html
> Dear all;
>
> How are you?
> I am trying to develop web service for geopolitical ontology.
>
> I created one resources like
>
> ws/neighbors/{ISO3} --> show all neighbors including 6 language translations,
> by given country ISO3 code
>
> i.e. ws/neighbors/ken --> show all neighbors including 6 lanuage translations
> ,by given country kenya.
>
>
> Then, I also would like to serve another resource like showing neighbor
> information only one selected language translation, by given country code"
>
> So, I designed like
> ws/neighbors/{iso}/language/{languagecode} such as EN,ES,FR} --> but for me,
> it is not a good design, since these hierarchical structure is not logically
> correct.
>
> Is it good design in terms of REST?
>
> If so, I think implementation of createRoot() could be like .
> ==============
> Route neighborWithISO3Route = router.attach("/neighbors/{ISO3}",
> NeighborsResource.class);
> neighborWithISO3Route.getTemplate().getVariables().put("ISO3",
> new Variable(Variable.TYPE_ALL));
>
>
> Route NeighborsByEachLanguageRoute =
> router.attach("/neighbors/{ISO3}/language/{lang}",
> NeighborsByEachLanguageResource.class);
> NeighborsByEachLanguageRoute.getTemplate().getVariables().put("lang",
> new Variable(Variable.TYPE_ALL));
>
> ==============
> But, the first neighborWithISO3Route is working fine. But, the second
> NeighborsByEachLanguageRoute is not working. When I tried to GET two
> arguments "ISO3" and "lang" in NeighborsByEachLanguageResource with the
> following codes
> =============
> this.ISO3 = ((String)request.getAttributes().get("ISO3")).toUpperCase();
> this.lang = ((String)request.getAttributes().get("lang")).toUpperCase();
> ==============
> Then, ISO3 had a value like "{ISO3}/language/{lang}" and lang was null.
>
> What was wrong??
>
> Thanks for your answer in advance.
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2063049
>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2066738