Get Request Attributes in Restlet 2.0

admin

Administrator
Staff member
I'm using <a href="http://www.restlet.org/" rel="nofollow noreferrer">Restlet</a> to make a RESTful platform. I haven't used it before, but I decided to use 2.0 because it is better to start with the latest and greatest technology, right?

The key thing I am looking for is the ability to have someone to put in a URL like
Code:
http://mysite/New%20York/3
and have the service respond with something like
Code:
[New York,New York,New York]
, so I need to pass in request attributes. Using this post for <a href="http://danilogurovich.wordpress.com/2008/09/23/a-simple-restlet-demo-application/" rel="nofollow noreferrer">Restlet 1.1</a> (because I can't seem to find <em>any</em> documentation for this on the Restlet site), I wired up my application like so:

Code:
router.attach("{text}/{count}", RepeaterResource.class);

The new way to do this is apparently in the
Code:
UniformResource#doInit()
method, so mine looks like (without error checking):

Code:
@Override
public void doInit()
{
    magicText = "" + getRequestAttributes().get("text");
    repeatAmount = Integer.parseInt("" + getRequestAttributes().get("count"));
}

The problem is that the
Code:
Map&lt;String, Object&gt;
returned from
Code:
getRequestAttributes()
is always completely empty! This seems rather odd. Am I wiring the routing up wrong?

Of course, I could just use
Code:
getQuery()
and parse it myself, but that is definitely the wrong way to go about doing this and it seems like there should be an easy way to do this (similar to the way previous versions worked).