This material is adapted from Embedded Ethernet and Internet Complete by Jan Axelson (www.Lvr.com).
In writing an ordinary Java program for use on a TINI, you compile the program to one or more .class files and use the TINIConvertor utility to convert the file(s) to a .tini file. You can then use an FTP program to copy the file to the TINI. Or you can use the build utility Ant to automate the process of creating and copying the files. When the file or files have been transferred to the TINI, you can run the program from a Telnet session by typing java, followed by the name of the .tini file.
With servlets, things are more complicated. The Tynamo Web server functions both as a Web server, which responds to HTTP requests, and as a servlet container, which contains and manages the servlets. A variety of configuration files contain information about the servlets and Web server. The Ant utility is the recommended way to compile, convert, and deploy the Web server and servlets on the TINI.
With Ant, you can compile your .java files and create the file webserver.tini, which contains both the object code required to respond to HTTP requests and the code for your servlets.
If you use another servlet container, such as TiniHttpServer (www.smartsc.com), the details will vary, but the information about how to use Ant, TiniAnt, and the configuration files are likely to be similar.
These are the required components for creating and running servlets on a TINI with the Tynamo Web server:
The Tynamo Web server uses four configuration files. You must edit at least three of these to provide information that is specific to your development PC and your servlets. The build.properties file contains the locations and names of various files and directories on the development computer. The servlets.props file contains information about the servlets. The deploy.properties file contains your TINI's IP address and other information that the Ant utility uses in copying the Web server's files to the TINI. The webserver.props file enables you to specify a default directory, home page, and other properties of your server. (Many servers can use the default webserver.props file, with no editing.) You can edit these files in any text editor.
Below is more information about each of these files, followed by instructions for how to use the files in compiling, converting, and deploying files to the Web server.
The build.properties file is in the home directory of the Tynamo distribution. The file contains the locations and names of the TINI's home directory and the servlets on the development computer. The Ant utility uses the information in the file in building the TINI's executable file.
The build.properties file contains information that Ant uses in compiling the servlets.
Listing is an example build.properties file.
#example build.properties file
tini.path=C:/tini1.11
src.paths=/myservlets
src.files=DeviceController.java, FormResponse.java
include.servletReloading=false
dependency.files=
dependency.groups=
dependency.classpath=
reflect.classes=DeviceController, FormResponse
For each of the following items, edit the existing text by inserting the information
that applies to your system and servlets. Use forward slashes as separators
even if the operating system of your developement computer (such as Windows)
uses back slashes. Ant converts to back slashes as needed.
Set tini.path equal to the location of the TINI SDK on the development computer:
tini.path=/tini1.11
Set src.paths equal to the location of the source code for your servlets on the development computer:
src.paths=/myservlets
The path is an absolute path, not relative to the Tynamo directory.
If there are multiple locations, separate the paths with colons or semicolons:
src.paths=/myservlets;/test
Set src.files equal to the names of your servlets, separating multiple names with commas or spaces:
src.files=DeviceController.java, FormResponse.java
Set reflect.classes equal to the full class name of each servlet, separating multiple names with commas or spaces:
reflect.classes=DeviceController, FormResponse
Three dependency entries
can contain information about the classes that a servlet uses, or depends on.
Not every servlet requires dependency information.
A dependency.files entry specifies the name and location of a file that contains
dependency information for one or more servlets. An example entry is:
dependency.files=examples/servlet_examples_dep.txt
Below is the information provided in the dependency file for Tynamo's example servlet RequestInfoServlet:
RequestInfoServlet=com.qindesign.servlet.example.RequestInfoServlet;com.qindesign.servlet.example.Common
The RequestInfoServlet entry has two values separated by a semicolon. The first value is the full name of the servlet's class. The second value informs the build process that the servlet depends on the com.qindesign.servlet.example.Common class.
The servlets.props file is in the \bin directory of the Tynamo installation and must contain information required by the servlet container to run your servlets. The file provides information about each servlet supported by the server. The servlets.props file contains configuration information for your servlets. Here is a servlets.props file for the servlets DeviceController and FormResponse.:
DeviceController.mapping=/servlet/DeviceController
DeviceController.class=DeviceController
FormResponse.mapping=/servlet/FormResponse
FormResponse.class=FormResponse
A servlet name identifies the servlet in the file. The servlet names in the example are DeviceController and FormResponse. A mapping specifies how clients can request to run the servlet and has the following format:
servlet_name.mapping=mapping
where servlet_name is a servlet name and mapping is the text that clients can use to request the servlet from the server.
The following mapping enables clients to request to run the servlet DeviceController by typing the TINI's IP address or domain name followed by /servlet/DeviceController in a browser's Address text box:
DeviceController.mapping=/servlet/DeviceController
For example, if the IP address
is 192.168.111.9, the user would enter the following:
http://192.168.111.9/servlet/DeviceController
The servlets.props file must also specify the full class name of the class that implements the javax.servlet.Servlet interface for each servlet. The class name is the name of the servlet's class in the source code, preceded by its package name, if any. This information uses the following format:
servlet_name.class=class
where servlet_name is the servlet name and classname is the class name. In the example, the class name for the servlet DeviceController is also DeviceController. In this case it seems redundant, but other classes might use a different name for the class name and servlet name.
If the servlet is in a package,
the class name must specify the package name as well, as in this example:
Shutdown.class=com.qindesign.servlet.ShutdownServlet
The optional initParams entry can specify one or more initialization parameters to use when the servlet starts:
Shutdown.initParams=passwd=shut:down
The optional loadOnStartup entry can specify that the servlet should load when the server starts, rather than on first use:
Shutdown.loadOnStartup=true
The number sign (#) indicates a comment, which the server ignores:
# Shutdown servlet
The example servlets.props file included with the Tynamo Web server has additional examples.
The deploy.properties file simplifies the process of transferring files to a TINI. The file contains information specific to the TINI that will run the Web server. Here is an example:
deploy.server=192.168.111.2
deploy.userid=root
deploy.password=tini
deploy.rootdir=/web
Four deploy properties contain information about the TINI. The server property is the TINI's IP address. The userid and password properties are the user ID and password required to log onto the TINI's FTP server. The rootdir property is the directory the deploy process should use as the root directory on the TINI when transferring files. The deploy process creates the directory if it doesn't exist.
The webserver.props file enables you to specify properties of the server. The default file will work with no changes, but you can edit the entries if you wish. To use a default directory other than /web/http-root for files on the server, edit this entry with the desired directory path.
server.rootDir=/web/http-root
To use a default home page other than index.html, edit this entry with the desired default file's name:
server.welcomeFile=index.html
The entries in the provided file show additional options you can change.
When you've obtained the necessary components and have written a servlet such as the DeviceController servlet above, these are the steps required to use Tynamo to run the servlet on a TINI:
1. Install Ant and TiniAnt on your development PC, following the instructions provided with each, including setting the recommended environment variables to identify file locations.
2. As described above, edit
build.properties, servlets.props, deploy.properties, and webserver.props with
the appropriate information for your TINI and servlets.
3. Follow these steps to build webserver.tini with Ant. Open a window with a
command prompt. Under Windows XP, click Start, then Run, and enter cmd in the
Open: text box that appears. Change to Tynamo's home directory and enter ant.
This runs the file ant.bat included with the Ant distribution. Ant uses the
information in build.properties and Tynamo's build.xml file to locate the needed
files, compile, and convert the result to the file webserver.tini. The file
contains the executable code for the servlet container and the servlets the
Web server can run.
4. Copy any static HTML files, images, or other files the Web server will need to access to the appropriate directories under the Tynamo's home directory on the development computer. The webserver.props file specifies the root directory for these files. The default is http-root.
5. From a command prompt
in Tynamo's home directory, enter ant
deploy. This runs ant.bat again, but this time runs the deploy task instead
of the default build task. (Tynamo's build.xml file specifies the default task.)
The deploy task copies the Web server's files to the TINI. Using the default
settings, the files copied are the following files under Tynamo's home directory:
\bin\webserver.tini
(the Web server application)
\bin\WebServer (a script to run the Web server)
\bin\webserver.props (configuration information about the Web server)
\bin\servlets.props (information about the servlets)
\bin\mimeTypes.props (MIME definitions for file types)
\http-root\* (all files in this directory)
6. To run the Web server, in a Telnet session, at a command prompt in the root
directory, enter the following command:
source web/bin/WebServer
This executes the WebServer script, which contains the following text:
java /web/bin/webserver.tini /web/bin/webserver.props &
When the Telnet window displays:
HttpServer: Server Started
The TINI is ready to run the servlets named in servlets.props.