Hello Restlet folks. I have a problem serving static files using
Restlet's Directory class and the CLAP pseudo protocol (apparently a
popular topic right now :)
I have a standalone web application that uses Restlet to provide a
RESTful API. Some students taking a class have written a nice client
for the web application as a Single Page Application (SPA) consisting
of HTML5/CSS/Javascript. I would like to store a directory containing
the static SPA files in my web application's jar file and to serve
them under a specific URI so the SPA client and server are
self-contained
The way I am trying to do this is:
public synchronized Restlet createInboundRoot() {
...
Directory directory = new Directory(getContext(), "clap://class/spa/");
router.attach("/spa/", directory);
...
Unfortunately, this doesn't work. When I run the server from my jar
file and point a browser at "/spa/", the browser downloads an empty
file (Chrome calls it "download", Safari calls it "spa") rather than
rendering the page. Browsing to "/spa/index.html" does work, but I
don't want users to have to remember to add the "index.html".
Am I doing something wrong here? It seems like this should work. I'm
open to other ways to accomplish this goal.
Annoyingly, the server behaves differently when running from Eclipse
than when running from a jar file, which makes troubleshooting this
problem more painful since I have to build the jar file to test
fixes.For example, when running from Eclipse, "/spa/" gives a 404
error, instead of downloading an empty file.
I also tried playing with setIndexName(). If I set it to "index.html"
(including the extension despite the Javadoc saying the parameter
should be without extension), then it works when run from Eclipse but
not from the jar file.
Thanks in advance for any suggestions on how to make this work!
--
Robert Brewer
http://excitedcuriosity.wordpress.com/
https://www.facebook.com/kukuicup
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042270