Use a URI template when you attach the resource to the router

  router.attach("/account/{id}", AccountServerResource.class);

and extract the id as an attribute in the server resource Get method
implementation

  String idString = getRequestAttributes().get("id");
  if (idString == null) { ... }
  int id = Integer.valueOf(idString);
  if (!isValid(id)) { ... }
  return doSomethingToGetAccount(id);

You'll want to encapsulate common error handling more neatly than this.

--tim

On Thu, Jul 26, 2012 at 12:36 AM, Norm Deane <norm.de...@vanderbilt.edu>wrote:

> Is it possible to do something like this...
>
> public interface AccountResource
> {
>    @Get
>    public Account get(int id);
> }
>
> public class AccountServerResource implements AccountResource
> {
>    public Account get(int id)
>    {
>      return doSomethingToGetAccount(id);
>    }
> }
>
> If there is I'm missing it. I can't figure out how the framework would
> parse the id out of the request and pass it to the annotated method?
>
>
> Norm
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2993117
>

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

Reply via email to