Hello Robert,
from what I notice, the resolution of "a file" is more or less based on the
ability to discover ressources having the same base name. A file directory
is perfect because it is possible to list all ressources within the same
parent directory.
A classloader is more retrictive and gives access to a single resource...
which explains the behaviour of the "indexName" attribute of a Directory.
I check why it does not work from a jar file.
You can also connect the Directory with the jar file using the JAR protocol
or the ZIP protocol. Such protocol is based on the JDK ZipEntry class which
has the ability to list files (such as a directory).
directory = new Directory(getContext(), "zip:" +
LocalReference.createFileReference(new File("/your/path")) + "!/" );
Of course, it obliges you to reference the jarfile from itself. You can
consider this as a workaround.
Best regards,
Thierry Boileau
2013/1/10 Robert Brewer <[email protected]>
> 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
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042354