Resin's File support allows several URL
schemes beyond the usual filesystem. Scripts can use the File
object to send mail and to retrieve HTTP documents. Future
supported filesystems will include FTP and may eventually include
WebDav, IMAP, and LDAP.
The virtual filesystem lets scripts use the familiar file and
stream APIs to send and retrieve internet
resources. Script writers can avoid learning new APIs for each new
resource type.
Filesystems
|
file: |
The file: filesystem provides access to local
files. |
mailto: |
mailto: lets scripts send mail using SMTP (the internet
mail protocol). |
http: |
Retrieves HTTP resources from the web. |
The file: filesystem provides access to local
files. All file paths use forward slashes to separate path
segments, independent of operating system.
Resin will translate the path to the local filesystem path.
Internally, and hidden from scripts, Resin will use '\' as the
Windows separator and ':' for the Macintosh.
/foo/bar |
\foo\bar |
/f:/foo/bar |
f:\foo\bar |
file:/c:/foo/bar |
f:\foo\bar |
mailto: lets scripts send mail using SMTP (the internet
mail protocol). The syntax follows the mailto url syntax ( rfc2368) summarized below.
mailto: allows multiple recipients. Just separate them by
commas. It also lets script set mail headers by setting query
variables. Certain mail headers are protected, e.g. Sender
and Date .
Scripts use a normal write stream to send the message body. Just open
the URL using openWrite and use the normal stream functions. When the stream is closed,
Resin will send the message.
Query Variable |
Meaning
|
Subject |
The subject of the message
|
To |
Additional message recipients
|
Cc |
Additional message recipients
|
Bcc |
Additional message recipients (hidden)
|
From |
Useful for mail lists
|
Reply-to |
Changes reply address
|
var file = File("mailto:resin@caucho.com?subject=Feedback");
file.writeString(@<<END);
Thanks for creating an awesome product.
John W. Doe
END
|
var file = File("mailto:survey,john.doe?subject='User Survey'");
var stream = file.openWrite();
for (var key in request.query) {
stream.writeln(key, " : ", request.query[key]);
}
stream.close();
|
Retrieves HTTP resources from the web. Getting a file is a
single HTTP operation. Optimizations such as keepalives and caching
are handled transparently by Resin.
To GET a file, use openRead
To POST , use openReadWrite . Writing provides the
POST data. The first read will post the data and retrieve the reply.
Writing after reading is illegal.
var file = File("http:/www.caucho.com/index.html");
var stream = file.openRead();
out.writeStream(stream);
stream.close();
|
var file = File("http:/www.caucho.com/post.jsp");
var stream = file.openReadWrite();
stream.write(@<<END);
first.name=john
last.name=doe
END
|
Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Thu, 16 Sep 1999 14:56:49 -0700 (PDT)
|