MC39 Lab 4: Three-Tier Development (Spring 1999)

Due: March 23, 1999 (changed from original syllabus)

In this lab, you will extend your work from the previous lab into the three-tier architecture. All the instructions below assume you are working on one of the MCS department PCs running Linux.

First, try using a working version of the client applet, which is linked from the web version of this lab handout. You can also try a variant that connects to a dummy server (which gives a fixed answer regardless of your query). These two use the identical Java applet code, and the HTML files differ only in one line, which is

<param name="chainServer" value="max-chain">
in the first case and
<param name="chainServer" value="max-dummy-chain">
in the second. This illustrates how you can try out your server (dummy or real) with my client applet: only this one line will need changing. (More on this below, where it becomes relevant.)

You discovered above that one client can contact different servers, so long as they implement the same protocol. The converse is true as well: one server can be used by multiple clients. For example, in the interest of accessibility, we should have a textual client as well as the GUI applet. This is useful for testing as well. I have a (crude) textual client for you to try out, which can access any server: my real one, which uses a database; my dummy one, with fixed answers; or the ones you will write. To try out the textual client with my real server, do the following in a shell window (assuming you are running the csh or tcsh):

setenv CLASSPATH ~max/public_html/codebase
java edu.gac.max.movies.textual.FindActor \
 rmi://kilpinen.mcs.gac.edu/max-chain
To instead connect to my dummy server, you would simply replace max-chain by max-dummy-chain in the last line. (Note that the second line ends with a space and then a backslash, to allow the third line to serve as a continuation of what would otherwise be one very long line.)

The interface that defines the common protocol that any client can use to access any server is given by the following three files; you should look at them, since they serve as the basis for the code you will write:

Your first server should be another dummy server, like mine, just to make sure that you have the mechanics down of how to compile and deploy a server. (These mechanics are a bit messy. I strongly advise using the mouse to copy commands from the web version of this lab handout and paste them into your shell, rather than retyping.) I am providing you with the code for my dummy server; all you absolutely need to do is change the package line at the top of each file (to show these classes as being in some package of your own), change the RMI name from max-dummy-chain to one of your own in the call to Naming.rebind, compile, deploy, and test. However, I strongly urge you to also make some modification in the fixed response that is provided, so that when you test, you will be able to see for sure that it is really your own server that is being contacted. The two files are:

In the following instructions, I am going to pretend your username is jstudent; substitute your real one.
  1. Edit the two files so that the package line at the top indicates a package somewhere subordinate to edu.gac.jstudent rather than edu.gac.max. (I will assume you use edu.gac.jstudent.movies.dummy.)
  2. Further edit ChainImpl.java to rebind under the name jstudent-dummy-chain instead of max-dummy-chain.
  3. Further edit ChainImpl.java to offer your own favorite fixed choice of stores, and StoreImpl.java to offer your own favorite fixed movies. (These are to make your server recognizable.)
  4. You will need a public_html/codebase directory to hold your compiled classes, in order that the web server on kilpinen can distribute your remote-access classes to clients. (It is simplest to put the other class files there as well.) Create this directory as follows:
    mkdir ~/public_html
    mkdir ~/public_html/codebase
    
  5. Now compile your program as following
    setenv CLASSPATH ~max/public_html/codebase:$HOME/public_html/codebase
    javac -d ~/public_html/codebase StoreImpl.java
    rmic -d ~/public_html/codebase edu.gac.jstudent.movies.dummy.StoreImpl
    javac -d ~/public_html/codebase ChainImpl.java
    rmic -d ~/public_html/codebase edu.gac.jstudent.movies.dummy.ChainImpl
    
  6. Because your server makes use of the basic Chain, Store, and Movie classes I provided (the client/server interface), you need to copy my class files for these three classes into your public_html/codebase directory as well. You can do this as follows:
    mkdir ~/public_html/codebase/edu/gac/max
    mkdir ~/public_html/codebase/edu/gac/max/movies
    cp -p ~max/public_html/codebase/edu/gac/max/movies/{Chain,Store,Movie,FindActor}.class \
      ~/public_html/codebase/edu/gac/max/movies
    
    (Again, the last two lines are conceptually one long line; the backslash tells the shell to treat them as thought they are one.)
  7. To run your server, and have it automatically restarted every time kilpinen is rebooted, you will need to create a directory in your home directory called .onboot (note the dot at the beginning) and a file within that directory saying how to run the server. Both the directory and the file need to have special protection modes. To create the directory, do
    mkdir ~/.onboot
    
    Now save the sample file linked from this web page into the file dummy-chain in the .onboot directory. Change the protection modes as follows:
    chmod 755 ~/.onboot
    chmod 700 ~/.onboot/dummy-chain
    
    At this point, your server should be automatically started every time kilpinen reboots. However, in order to start it manually now, you need to login to kilpinen, which you can do using the ssh command:
    ssh kilpinen
    
    Once on kilpinen, you can run your server as follows:
    ~/.onboot/dummy-chain &
    
  8. Now that your dummy server is running, try connecting to it from a client. First (and most simply) use the textual client, specifying jstudent-dummy-chain at the end of the command. To use your server with the applet client, you will need to access the web page on which the applet is, save it into a .html file in your www-docs directory, and edit your name in place of mine in the codebase and edit your chainServer name in. Then you can browse your .html file.
  9. See the separate directions for killing your server.

Now it is time to make a real server that connects using JDBC to your database (yielding three tiers), building on the work you did in the previous lab on SQL and JDBC. Make copies of ChainImpl.java and StoreImpl.java in a different directory. Change the package lines to a different package as well. Now edit in the JDBC code, and compile, deploy, and test as above. (You will need to make another file in .onboot, analogous to dummy-chain. As with everything, ask if you need help.)

If you have time on your hands and want to look at the client side, it is in the file

If you want, you could make a modified version, or replicate (or improve upon!) the textual client, the source of which I'm intentionally hiding.


Instructor: Max Hailperin