How to retrieve attributes in hierarchical URI?
Using Restlet, how can I retrieve the attributes passed in the URL?
Example: http://localhost:8888/contacts/123
in here, I want to retrieve the 123 value.
I'm using the next set of lines code:
router.attach("contacts/{contact_id}", ContactResource.class);
public class ContactResource extends ServerResource
{
@Get
public ContactDetail retrieve()
{
//how to retrieve the contact_id value?
return null;
开发者_开发百科 }
}
Was a while since I last used Restlet, but if I recall correctly, this should work:
int contact_id = Integer.parseInt(getRequest().getAttributes().get("contact_id"));
edit: documentation on routing in Restlet 2.1
精彩评论