handlers
filters
FilterHandler
that permits content obtained from other handlers to be rewritten.
templates
TemplateFilter
or TemplateHandler
that allow html/XML content to be processed on an entity by
entity basis.
When the server
is created, it is provided with a Java
Properties
object, which both defines the interrelationships
among the components (handlers, filters, and templates),
as well as providing the
means for information to be shared among them. This document presents
several configurations -- Java properties
objects -- that
are represented as Java properties
files, which may be
used directly by the sample Main
program.
The trivial example
provides the server with no properties
.
In this case, the server, listening on port 8080, uses the
FileHandler
to deliver ordinary files, using the current directory as the document root.
This allows the system to be tested out of the box, with no
configuration provided.
The following configuration could be used as a simple, traditional
web-server. It delivers normal files, runs CGI scripts, provides
directory listings, and a "custom" page for not-found documents.
On Unix systems, it permits individual users to have "personal pages".
handler=simple simple.class=sunlabs.brazil.server.ChainHandler simple.handlers=home file cgi directory missing home.class=sunlabs.brazil.handler.HomeDirHandler file.class=sunlabs.brazil.server.FileHandler cgi.class=sunlabs.brazil.handler.CgiHandler cgi.suffix=.cgi directory.class=sunlabs.brazil.handler.DirectoryHandler missing.class=sunlabs.brazil.handler.NotFoundHandler |
Since the server dispatches all requests to a single handler,
The ChainHandler
allows for multiple handlers to
have a chance at servicing the request.
The HomeDirHandler
demonstrates the use of
side effects, or the ability of one handler to communicate with
another by changing the server configuration "on the fly", by modifying
the server properties. In this case, the document root the
fileHandler
uses to find files.
/moved
.
Changes from the previous configuration are in
bold face.
handler=simple simple.class=sunlabs.brazil.server.ChainHandler simple.handlers=home moved protected publish file cgi directory missing home.class=sunlabs.brazil.handler.HomeDirHandler file.class=sunlabs.brazil.server.FileHandler cgi.class=sunlabs.brazil.handler.CgiHandler cgi.suffix=.cgi directory.class=sunlabs.brazil.handler.DirectoryHandler missing.class=sunlabs.brazil.handler.NotFoundHandler # # Redirect all request in /moved/... to a new site # moved.class=sunlabs.brazil.handler.UrlMapperHandler moved.match=/moved/(.*) moved.replace=http://www.moved.here/new/\\1 moved.ignoreCase=true moved.redirect=true # # require basic authentication for all files under /protected/... # protected.class=sunlabs.brazil.handler.BasicAuthHandler protected.realm=a-secret protected.prefix=/protected/ protected.mapFile=data.credentials # # Allow netscape style publishing of pages # publish.class=sunlabs.brazil.handler.PublishHandler publish.realm=Sample server web site administration publish.mapFile=publish.credentials publish.prefix=/ |
# Company telephone directory application, demonstrating a sample
# use of the TemplateHandler, incorporating:
# - SetTemplate for substituting data into html "Template" pages
# - SqlTemplate for doing data base queries
# - BSLTemplate for allowing conditional html code, and dynamic
# table generation
#
handler=org
org.class=sunlabs.brazil.template.TemplateHandler
org.templates= \
sunlabs.brazil.template.SetTemplate \
sunlabs.brazil.template.SqlTemplate \
sunlabs.brazil.template.BSLTemplate
#
# Place all query data into the |
The server configuration operates with the following HTML file. Notice
that additional HTML entities are incorporated along with the ordinary
HTML, and used by the template
s to generate dynamic
content. Each template defines one or more new "html entities", that
it processes, replacing them with standard HTML, In this example,
the SqlTemplate
processes the text between
<sql>...</sql>
and provides data to the
other two templates. The SetTemplate
replaces
entities of the form
<get name=xxx>
with the value of xxx
.
The BSLTemplate
implements a simple HTML based
scripting language (the Brazil Scripting Language)
that processes entities of the form:
to allow for dynamic and conditional HTML generation.
Note that the form embedded in the page submits the form data back to
itself, which is used to create the next version of the page.
<title>Sample company phone book using the SQLtemplate</title> <h1>Welcome to the company telephone book</h1> <p> This page uses SQL to retrieve phonebook information from an SQL database. <hr> <form> Last name:<input name=name> </form> <p> <if org.error> <center><font color=red>Error: <b> <get org.error> </b></font></center> </if> <if Query.name> <sql debug eval prefix=names> select id, last, first, mi , phone, location from namelist where last='${Query.name}' </sql> <table border=2> <foreach name=index property=names.rows> <tr> <foreach name=field list="first mi last phone location"> <td><get name=names.namelist.${field}.${index}></td> </foreach> </tr> </foreach> </table> </if> |
More than a dozen example Brazil applications are included with this
distribution, in the samples
directory.
Some are complete, working applications, whereas others are examples
that demonstrate how to use a particular set of features.
See the included README file for more information.