Anyone have any thoughts on this? Is nobody else serving up static HTML/CSS/JS content from jar files? Should I create a GitHub issue?
Thanks. On Fri, May 10, 2013 at 6:41 PM, Robert S Brewer <[email protected]> wrote: > Hello Thierry B. My dissertation is finished, so I can finally get > back to debugging this problem :) > > Your sample code & project were quite helpful, however, it differed > from my code in one way: my static files are contained in a > subdirectory of the jar file. So I made 2 tiny modifications to your > sample: the path to the directory is now "/stat", and I created a > "stat" directory in the jar file that contains the index.html file. > > Once I made these changes, it replicates the problem I am having. The > modified sample code behaves just like my application: if I go to > http://localhost:8182/stat/ my browser downloads a zero-length file, > but localhost:8182/stat/index.html works fine. > > Am I misunderstanding something, or is this a bug? > > I have attached a zip file with my modified version of the project. > There are two jar files: testRobert.jar is the original jar file, > while newTestRobert.jar is my modified version so one can see the > differences easily. > > Thank you for your assistance with this bedeviling problem. > > On Fri, Jan 11, 2013 at 12:07 AM, Thierry Boileau <[email protected]> > wrote: >> oops, I missed the project file. >> >> Best regards, >> Thierry Boileau >> >> >> 2013/1/11 Thierry Boileau <[email protected]> >>> >>> Hi Robert, >>> >>> I send you a zip file of the eclipse project (testRobert.zip), and the jar >>> file generated by eclipse. >>> I launch the application on command line as follow: >>> java -cp testRobert.jar:/home/thierry/restlet/branches/2.1/org.restlet.jar >>> test.MyApplication >>> >>> >>> Best regards, >>> Thierry Boileau >>> >>> >>> 2013/1/11 Robert Brewer <[email protected]> >>>> >>>> Hmm, I could not clap and jars for a directory to work. Do you have >>>> the test code that worked available? I will try reducing my code to a >>>> bare minimum to see what is going on, but another project has come up >>>> so I have to investigate later. >>>> >>>> Thanks for your help. >>>> >>>> On Wed, Jan 9, 2013 at 10:36 PM, Thierry Boileau <[email protected]> >>>> wrote: >>>> > Hi Robert, >>>> > >>>> > I've just tried the clap connector using a jar file and it works for me >>>> > (I >>>> > mean such url works : "http://localhost:8182/stat/index.html", >>>> > "http://localhost:8182/stat/"). Just take care to complete properly the >>>> > classpath when lauching your application from the command line. >>>> > >>>> > Best regards, >>>> > Thierry Boileau >>>> > >>>> > >>>> > 2013/1/10 Thierry Boileau <[email protected]> >>>> >> >>>> >> 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 >>>> >>>> -- >>>> Robert Brewer >>>> http://excitedcuriosity.wordpress.com/ >>>> https://www.facebook.com/kukuicup >>>> >>>> ------------------------------------------------------ >>>> >>>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3042617 > > -- > Robert Brewer > http://excitedcuriosity.wordpress.com/ > https://www.facebook.com/kukuicup -- Robert Brewer http://excitedcuriosity.wordpress.com/ https://www.facebook.com/kukuicup ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3056813

