Building Servlets for TINI on MacOS 8.6 or 9.0

Provided by Martin Minow

These notes describe the steps I took to install the SmartSC Servlet manager on a TINI internet appliance and write and compile my own servlet.

The Macintosh does not support class file libraries very well because of the 31-character file name limit. This prevented previous versions of TINIConvertor from accessing all classes. The version of TINIConvertor shipped with 1.0, however, now has jar file support which allows files with long filenames to be placed in a jar file and accessed correctly by TINIConvertor.

Collecting the Components

  1. These notes presume you are running MacOS 8.6 or 9.0 and MRJ 2.2. CodeWarrior Java Edition will be used for compilation and class file management.
  2. Create a folder to hold your working servlet code. This will be called "ServletSupport" in subsequent documentation.
  3. Get the TINI 1.0 software distribution from http://www.ibutton.com/TINI/ and unpack the distribution into a subfolder within the ServletSupport folder (this is actually a bad idea but, for my initial experimentation, it's easier to keep everything in one place.) You actually only need the binary components from the TINI 1.0 distribution.
  4. Get the "smartsc" Servlet distribution from http://www.smartsc.com/tini/TiniHttpServer/ and unpack the distribution into a subfolder within the ServletSupport folder. To build a servlet, you must (currently) link your servlet with the ServletSupport library to create a single TINI binary image.
  5. Download Java's servlet development distribution from http://java.sun.com/products/servlet/download.html . For Macintosh, choose the Windows/NT release 2.1.
  6. Use Stuffit Expander to unzip the files into a convenient temporary directory.
  7. Copy servlet.jar from the Java distribution to a convenient place in the ServletSupport directory, renaming it smallservlet.jar.
  8. Use the CodeWarrior ClassWrangler application to modify smallservlet.jar. You will be removing a number of classes that are not used, and others that are provided by the SmallServlet distribution.
    1. Launch ClassWrangler, open smallservlet.jar.
    2. In the Package Menu, uncheck "Compressed." (This may be unnecessary.)
    3. Delete the following entries from smallservlet.jar by selecting each entry and selecting the Edit/Cut menu option:
      • javax/servlet/LocalStrings.properties
      • javax/servlet/ServletOutputStream.class
      • javax/servlet/http/Cookie.class
      • javax/servlet/http/HttpServlet.class
      • javax/servlet/http/HttpUtils.class
      • javax/servlet/http/LocalStrings.properties
      • javax/servlet/http/NoBodyOutputStream.class
      • javax/servlet/http/NoBodyResponse.class
      • javax/servlet/jsp/HttpJspPage.class
      • javax/servlet/jsp/JSPPage.class
      • javax/servlet/jsp (automatic)
      • meta-inf/Manifest.mf (if found)
      • meta-inf (directory, not extracted)
      • javax/servlet/http/HttpSessionContext.class
        The TINIConvertor distributed with Beta 2.2 fails to convert HttpSessionContext (and it isn't used by the TINI servlet). This may be a problem with the way the Macintosh (or the convertor) handles the "deprecated" attribute.
    You now have an implementation of servlet.jar that does not conflict with the SmartSC Servlet Manager.
  9. As noted above, copy the tini1.0 folder and its children from the TINI distribution to the ServletSupport directory.

Directory Structure

At this point, your directory structure will look like the following:
ServletSupport
  bin (Created to store the generated tini image)
  tini1.0 (Holds the Tini 1.0 distribution)
  TiniHttpServer0.10 (SmartSC Servlet sources go here)
smallservlet.jar
tini.jar

Compiling the Servlet

When you change the servlet source, you must recompile it and convert the Jar file to a TINI binary.
  1. Launch CodeWarrior Java Edition (or CodeWarrior Professional).
  2. Create a new "Library" project named ServletSupport.mcp, choosing the "JDK 1.1, java library" stationary. Delete the TrivialClass.java file and delete it from the project.
  3. The project should have the following options set:
    Target / Target Settings
    Target Name Servlet Support
    Linker Java Linker
    Pre-linker None
    Post-linker None
    Output Directory {Project}:
    Linker / Java MacOS Settings
    MacOS Java Output Type MacOS Zip
    Create 'old' MacOS resources Unchecked
    Create New File Unchecked
    Java Output Jar File
    Name ServletSupport.jar
    Compress Unchecked
    Generate Manifest Unchecked
  4. Add the Tini1.0/bin/tiniclasses.jar file to the project by dragging the file to the project window.
  5. Add the smallservlet.jar file to the project by dragging the file to the project window. This is the modified Java servlet library created above.
  6. Drag the src folder inside the TiniHttpServer distribution folder to the ServletSupport project window.
  7. (If you want to add your own servlets, drag their source files to the ServletSupport project window. If you want to remove the TiniHttpServer's sample servlets, remove them from the project.)
  8. Compile the servlet files. This will generate the ServletSupport.jar file. This file, after conversion, will be downloaded (uploaded?) to the TINI.

Convert the class files to a TINI download

  1. Run TINIConvertor. It reads the JAR files and writes the download image.

Copy the download image to the TINI

  1. Boot TINI and connect using either the serial support or Telnet and make sure that the following directories are present:
  2. Using Fetch or some other FTP client, connect to the TINI, login as root, and transfer the following files. You only need to transfer the files that have changed, in particular, the instance of TiniHttpServer.tini created by the previous steps. (If TiniHttpServer is currently running on your TINI board, be sure to stop it before overwriting the file.)

Writing Your Own Servlet to Run on the TINI

  1. Launch CodeWarrior Java Edition (or CodeWarrior Professional).
  2. Create a new "Library" project named MyServlet.mcp, choosing the "JDK 1.1, java library" stationary. Delete the TrivialClass.java file and delete it from the project. Of course, replace "MyServlet" by the name you prefer.
  3. The project should have the following options set:
    Target / Target Settings
    Target Name MyServlet
    Linker Java Linker
    Pre-linker None
    Post-linker None
    Output Directory {Project}:
    Linker / Java MacOS Settings
    MacOS Java Output Type MacOS Zip
    Create 'old' MacOS resources Unchecked
    Create New File Unchecked
    Java Output Jar File
    Name MyServlet.jar
    Compress Unchecked
    Generate Manifest Unchecked
  4. Add the tiniclasses.jar file to the project.
  5. Add the smallservlet.jar file to the project.
  6. Add the ServletSupport.jar file to the project.
  7. Drag the src folder inside the TiniHttpServer distribution folder to the project. Remove any sample servlets that you don't need.
  8. Write and compile your servlet.
  9. Edit a copy of tini/docs/index.html from the HttpServlet distribution (or a new version) and copy it to /docs/index.html on the TINI. This file identifies your servlet to the Servlet server.
  10. Edit a copy of tini/etc/servlets.props from the HttpServlet distribution (or a new version) to add your new Servlet and set its configuration parameters then copy it to /etc/servlets.props on the TINI. This makes your servlet accessable to external users.

Recompiling and installing your servlet

You need to do the following steps each time you edit your servlet.
  1. Edit and compile your servlet, using the project defined above. Note that you must compile using tiniclasses.jar, smallservlet.jar, ServletSupport.jar and the TiniHttpServer sources.
  2. Run TINIConvertor to convert your servlet's .jar file to the downloadable .tini file that will be transferred to the TINI. To run TINIConvertor on the Macintosh, you must either use JBindery to launch TINIConvertor with the appropriate parameters or write a small stub application that calls the TINIConvertor main method with the parameters needed to create your servlet.
  3. On the TINI, stop the current servlet, and delete its file from the /bin directory. (I keep a separate Telnet session open to do this.)
  4. Use Fetch to copy bin/TiniHttpServer.tini created above to /bin/TiniHttpServer.tini on the TINI.
  5. On the TINI, type source /bin/TiniHttpServer to launch the servlet manager and install the servlets. Alternatively, you can use the direct command, "java /bin/TiniHttpServer.tini /etc/server.props &".