views:

49

answers:

2

I'm using Restlet 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 http://mysite/New%20York/3 and have the service respond with something like [New York,New York,New York], so I need to pass in request attributes. Using this post for Restlet 1.1 (because I can't seem to find any documentation for this on the Restlet site), I wired up my application like so:

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

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

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

The problem is that the Map<String, Object> returned from getRequestAttributes() is always completely empty! This seems rather odd. Am I wiring the routing up wrong?

Of course, I could just use 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).

A: 

You can do this with 2.0 the same way as with 1.1.

See the tutorial, part 11: http://www.restlet.org/documentation/2.0/tutorial#part11

Restlet is great, BTW.

Avi Flax
A: 

My problem, is seems, is that router attachments must start with the / character. I should attached like so:

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

I can't seem to find this behavior documented and it seems rather odd, but it certainly fixed my issues.

Travis Gockel