Hello Luis,

if you use the file "protocol", you must provide the absolute path. Which leads to determine how to get the "current" path. This info could be passed by the servlet container to the application via a context property. In order to achieve this, you can extend the ServerServlet class (thus, you will have to update the web.xml configuration file) and rely on the ServletContext properties (see ServerServlet#getServerContext method).

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org <http://www.restlet.org/>
Noelios Technologies ~ Co-founder ~ http://www.noelios.com <http://www.noelios.com/>


Hi Thierry,

Thanks!

One other question -- because my WAR file is expanded to a directory when
it is deployed to the application server, does that mean I can use
"file:///" instead of "war:///"?

If so, do I need to provide the absolute path or can the parent of the
deployed-WAR directory be found from the servlet context?

    - Lu


Hello Luis,

Just to satisfy my curiosity, would you mind answering these questions
for
me?

Of source not!

1. Why does content negotiation have to be disabled for this to work?

In order to anwser exactly to your question, I've just made a test, and
it is not necessary to turn off the content negotiation at the level of
the directory.
However, I would like to add a few words.
Our implementation of the content negotiation relies on the ability to
look for the entire list of files that share the same base name (e.g.
{"index.html.en", "index.txt", etc} when "index.html" is requested).
Thus, you can confront the client preferences and the listed files in
order to find the "best" representation of the resource.
This is possible when you are relying on a directory (something pointed
by "file:///"), but WAR files does not provide easy and sure way to look
for the content of a "directory" inside a WAR file. Thus, we decided to
make such low level connectors unable to support content negotiation. If
you want a file in a war, you need to provide its exact path and name.
In your case, you wanted to get the index file  when requesting  for a
directory. Therefore, we can play with the "index" property of Directory
Restlet and give it the exact name of your index files.

2. Are there any other side-effects due to disabling content
negotiation?

Disabling content negotiation should have as only consequence to let the
client request for the exact URI of the resource.
3. What is the difference between "/doc" and "/doc/" in the URI template
parsing logic?

Good question. This point was the main cause of your problem.
If you request for "http://abc.com.mywar/doc"; though your application is
routed to "http://abc.com.mywar/doc/";, the routing logic can not infer
that you are actually looking for a "directory" identified
"http://abc.com.mywar/doc/";.
Actually, "/doc" and "/doc/" are not equivalent. The latter clearly
identifies the root of a hierarchy, in your case, a directory. But
"/doc" does not. It can be a resource.
Having said that, our implementation of the Directory Restlet is able to
know if you are really requesting the "doc" directory. If the target Uri
does not end with a "/", it asks the client to make another request to
the "/doc/" URI.
You can try to request "http://www.restlet.org/documentation/1.1";, you
will see that you are redirected to
"http://www.restlet.org/documentation/1.1/";

I hope I answer to your questions.

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org
<http://www.restlet.org/>
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
<http://www.noelios.com/>



Thanks again,

    - Lu


-----Original Message-----
From: Thierry Boileau [mailto:[EMAIL PROTECTED]
Sent: Monday, October 13, 2008 2:01 AM
To: [email protected]
Subject: Re: serving static files from servlet WAR with Directory class:
index.html not served automatically

Hi Luis,

it should work if you attach the directory like this (please note the
removes trailing "/"):

Directory docsDir = new Directory(getContext(), "war:///doc");
docsDir.setNegotiateContent(false);
docsDir.setIndexName("index.html");
router.attach("/doc", docsDir);

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Original Message-----
Hi Jerome,

Thanks for the suggestion.

I tried it, but unfortunately that didn't work either. The explicit URL
still works, but the index file is still not served when you access the
parent URL.

Let me know if you have any other ideas or if you think this is due to a
bug. Thanks again!

    - Lu


-----Original Message-----
From: Jerome Louvel [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 08, 2008 2:03 AM
To: [email protected]
Subject: RE: serving static files from servlet WAR with Directory class:
index.html not served automatically


Hi Luis,

This is due to the fact that directory listing isn't possible with the
war:// client connector, as opposed to the file:// client.

However, could you try this:

      // expose static API docs
      Directory docsDir = new Directory(getContext(), "war:///doc");
        docsDir.setNegotiateContent(false);
        docsDir.setIndexName("index.html");
      router.attach("/doc/", docsDir);

Let us know if this doesn't solve your issue and we'll look at the code.

Best regards,
Jérôme Louvel

PS: No problem for the HTML mail, I think most people can read them
fine.
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Envoyé : mercredi 8 octobre 2008 01:25
À : [email protected]
Objet : serving static files from servlet WAR with Directory class:
index.html not served automatically

(Apologies for my previous non-text email; trying again.)

I'm using restlet 1.1-RC2 with the ServerServlet extension on Oracle AS
10.1.3 with the web.xml configuration method.

I was able to successfully serve static files (included in the
'webapp/doc' directory within the WAR) using an instance of the
Directory
class, as follows:

      // expose static API docs
      Directory docsDir = new Directory(getContext(), "war:///doc");
      router.attach("/doc/", docsDir);

My problem, however, is that the 'index.html' file within the
'webapp/doc'
folder is not served automatically by the NRE when I use the following
URL
(instead the server returns 404):

      http://abc.com/mywar/doc

But it does work when I use the following explicit URL:

      http://abc.com/mywar/doc/index.html

Is there a configuration that needs to be set so that the Directory
class
will return the index file when a parent URL is accessed? Using log
output, I have verified that Directory.getIndexName() does in fact
return
"index".

Does anyone have a solution? Thanks,

    - Lu

Reply via email to