Provided Example Servlets

There are a number of example servlets, with source code, provided with this distribution. This document explains and discusses how to use each one.

  1. SendMail
  2. Shutdown
  3. AuthExample
  4. OneWireServlet
  5. RequestInfo
  6. DeviceInfo
  7. FastOneWireServlet
  8. SimpleOneWireServlet
  9. ServerPush
com.qindesign.servlet.SendMailServlet

Sends mail to a single address specified by the init. parameter, mailTo. Mail is sent via a POST request and there are four parameters. They are:

  1. from – the sender's address.
  2. subject – the subject line.
  3. content – the message content.
  4. nextPath – location to forward the request once the mail is sent.

All four parameters are optional, however, not including any of the information is probably of limited value.

It is required that both the mailTo initialization parameter and the mailhost be set, or else this will throw a ServletException. The parameter is set in the servlets.props file like this:

SendMail.initParams=mailTo=some@mail.address

Included in the distribution are two files that make use of this servlet: feedback.html and feedback-sent.html. These are found in the sample http-root/ directory. The first is a form that allows a user to fill out an email. Once this is sent, they are forwarded to the second document.

[Top]

com.qindesign.servlet.ShutdownServlet

Capable of shutting down the server. This makes use of Basic authentication to authorize a shutdown. An initilization parameter named passwd stores the username and password. The format is: passwd=user:pass.

This servlet is only capable of shutting down the server if two conditions are satisfied. First, the tynamo.server.shutdownEnabled server property must be set to true, and second, the tynamo.server.shutdownPasswordAttribute property must be set to some value. If the user passes the authentication, then the browser is redirected to a special shutdown URL.

[Top]

com.qindesign.servlet.example.AuthExampleServlet
Demonstrates the use of authentication in a servlet. The username & password are "test" & "test", and the realm is "realm".

[Top]

com.qindesign.servlet.example.OneWireServlet

Allows exploration of the 1-Wire network attached to the device. This servlet allows you to drill down from the adapters, through the devices, and into the internal memory of each device.

This servlet can be configured to provide alternative information for each family code by specifying an "include" servlet in the list of initialization parameters. For example, here is a possible snippet for the servlets.props file:

[Very important NOTE: The property loading code does not support continuation lines with the '\' character. Thus, make sure you put the initParams on one line. The use of this in the following example is just for illustration.]

#
# Useful servlet that can explore all aspects of a 1-Wire system
#
OneWireServlet.mapping=/servlet/OneWireServlet
OneWireServlet.class=com.qindesign.servlet.example.OneWireServlet
OneWireServlet.initParams=familyCode10=TemperatureInclude,\
                          familyCode21=TemperatureInclude,\
                          familyCode12=SwitchInclude,\
                          familyCode20=FamilyCode20Include,\
                          familyCode2c=PotentiometerInclude
#
# Family code includes for use by OneWireServlet
#
TemperatureInclude.mapping=
TemperatureInclude.class=com.qindesign.servlet.example.TemperatureInclude
SwitchInclude.mapping=
SwitchInclude.class=com.qindesign.servlet.example.SwitchInclude
FamilyCode20Include.mapping=
FamilyCode20Include.class=com.qindesign.servlet.example.FamilyCode20Include
PotentiometerInclude.mapping=
PotentiometerInclude.class=com.qindesign.servlet.example.PotentiometerInclude

Note the use of four additional "include" servlets. You can write your own family code servlets simply by adding yours to the initialization parameters of this serlvet. Specify familyCodeXX=<servlet name>.

There are two request attributes that will be passed to these servlets. These are container and queryString. The container attribute will contain an instance of the specific container class appropriate for the family code, and queryString will contain the exact query string necessary to append to the request for access to the included servlet.

In addition, there is a base OneWireSensorInclude class that provides checking for a valid request, and also prints a small header summarizing the name and address of the device. The TemperatureInclude and SwitchInclude servlets extend this class.

Please consult the source code for additional information.

[Top]

com.qindesign.servlet.example.RequestInfoServlet
Displays details about your HTTP request. This includes information about the Request-Line, and a list of all the request headers and parameters.

[Top]

com.qindesign.servlet.example.DeviceInfoServlet
Displays detailed information about the device on which the server is running. The server uptime is also shown.

[Top]

com.qindesign.servlet.example.FastOneWireServlet

Explores the 1-Wire network connected to the device. The output is XML. This means it is more easily machine-parsable than the output from OneWireServlet. It also means it is a little bit faster.

The servlet is flexible in that it allows you to list adapters and devices. Please consult the source code and Javadocs for a description of the request format and XML output.

[Top]

com.qindesign.servlet.example.SimpleOneWireServlet
Shows information from one 1-Wire device. The output is plain text. Please consult the source code and Javadocs for a description of the request format and output.

[Top]

com.qindesign.servlet.example.ServerPushServlet
Demonstrates how to send data using a "server push" technique. It is known to work with the Netscape and Opera browsers, but not with Internet Explorer.

The page counts from one to the value specified in a "count" parameter.

[Top]