views:

823

answers:

2

Using Restlet I needed to serve some simple static content in the same context as my web service. I've configured the component with a Directory, but in testing, I've found it will only serve 'index.html', everything else results in a 404.

router.attach("/", new Directory(context, new Reference(baseRef, "./content"));

So... http://service and http://service/index.html both work,

but http://service/other.html gives me a 404

Can anyone shed some light on this? I want any file within the ./content directory to be available.

PS: I eventually plan to use a reverse proxy and serve all static content off another web server, but for now I need this to work as is.

+2  A: 

Well, I figured out the issue. Actually Restlet appears to route requests based on prefix, but does not handle longest matching prefix correctly, it also seems to ignore file extensions.

So for example, if I had a resource attached to "/other"... and a directory on "/". And I request /other.html, what actually happens is I get the "/other" resource. (The extension is ignored?), and not the static file from the directory as I would expect.

If aynone knows why this is, or how to change it, I'd love to know. It's not a big deal, just for testing. I think we'll be putting apache or nginx in front of this in production anyway.

Mark Renouf
A: 

Routers in Restlet by default use the "Template.MODE_STARTS_WITH" matching mode. You could always set the Router default by doing router.setMatchingMode(Template.MODE_EQUALS). This will turn on strict matching by default for attach. You can choose to override individual routes with setMatchingMode.

Good documentation on Restlet Routing

backplane