0

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).

Travis Gockel
  • 26,877
  • 14
  • 89
  • 116
  • 1
    *"... because it is better to start with the latest and greatest technology, right?"* - Not necessarily. You need to figure out if the benefits of using the new technology outweigh the risks and costs for your project. And don't neglect the long term problems your successors will have if the technology is just a fad that everyone abandons in a couple of years. – Stephen C Jul 10 '10 at 04:09
  • :-P I agree with you, although this irritating little issue seems easily resolvable by someone who knows what they are doing (which means I have no idea). – Travis Gockel Jul 10 '10 at 04:14
  • I agree with Stephen, but just to bring this down to the concrete: Restlet has been in use in production systems for years, is well maintained, and has a strong community. 2.0 has been in development for a very long time, over a year, and is at this point very stable - the current version is RC4, and the final release will be out soon. So I think it's a safe choice — not as safe as 1.1, which is even more mature, but safe nonetheless. – Avi Flax Jul 11 '10 at 13:57

2 Answers2

2

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
  • 26,877
  • 14
  • 89
  • 116
0

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
  • 50,872
  • 9
  • 47
  • 64