MCS-270 Lab 4: Three-Tier Development

Due: March 26, 2003

Introduction

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. I will also assume that you run the applet either through version 1.2.1 of Mozilla, or through appletviewer.

You will first set up a dummy server, which will not access the underlying database that the final, but instead gives a fixed answer regardless of your query. After deploying this dummy version, you will then write an real server which will accurately respond to your queries. In addition to allowing you to query your database, this will also provide you the ability to easily see more information about the movies, courtesy of The Internet Movie Database.

Following is a link to an applet connected to an (occasionally) running dummy server: dummyFindActor.html, which you can check out to see what the dummy server should do.

Necessary files

Following are the files I am providing for you:

Deployment process

In the following instructions, I am going to pretend your username is jstudent; you should substitute your real one. In fact, all the files have jstudent in them, and one of your first tasks is to do that substitution throughout.

  1. Same as the first step in Two-tier Example (courtesy JavaSoft(TM)) , so not necessary if you have already done it.

  2. Same as the second step in Two-tier Example (courtesy JavaSoft(TM)) , so not necessary if you have already done it.

  3. For your convenience, I have packaged all the files you need into a single directory (which contains subdirectories). So to get started, all you need do is copy the following directory to somewhere in or below your home directory. I will refer to this copied directory as source_dir in what follows. So go to wherever you want to copy these files and type:
             cp -r ~karl/public/mcs270/lab4 .
    
    Note that the trailing . is necessary. Go to this directory and see what is there, including in the subdirectories.

  4. Edit all of the java and html files in source_dir (as well as its sub-directories), replacing jstudent with your username.

    Warning: All of the commands below should have every instance of jstudent replaced by you username.

  5. Go to source_dir and compile the three interface files:
             javac -d ~/public_html/codebase *.java
    

  6. Copy the policy from source_dir to public_html:
             cp policy ~/public_html
    

  7. Set your class path:
             setenv KARL ~karl
             setenv CLASSPATH $KARL/public/mcs270/psql-movies/postgresql.jar:.
             setenv CLASSPATH $HOME/public_html/codebase:$CLASSPATH
    
    (Note: you don't actually need postgresql.jar for the dummy server, but I am including it here since you will need it later.)

  8. Go to clients directory and compile FindActor.java:
             cd clients
             javac -d ~/public_html/codebase FindActor.java
             cd ..
    

  9. Go to the dummy sub-directory and compile the dummy implementation:
             cd dummy
             javac -d ~/public_html/codebase *.java
             cd ..
    

  10. Run rmic to create skeletons/stubs:
             rmic -d ~/public_html/codebase edu.gac.jstudent.movies.dummy.StoreImpl
             rmic -d ~/public_html/codebase edu.gac.jstudent.movies.dummy.ChainImpl
    

  11. ssh to kilpinen:
             ssh kilpinen
    
    Warning: you should again insure that the version of java is 1.4.0; see step 1 of Two-tier Example (courtesy JavaSoft(TM)) , in order to see how this is done.

  12. Once you are logged on to kilpinen and checked that your java is correct, start the server (just ChainImpl is needed, but you need to repeat above to set up you your class path) by doing the following:
             setenv KARL ~karl
             setenv CLASSPATH $KARL/public/mcs270/psql-movies/postgresql.jar:.
             setenv CLASSPATH $HOME/public_html/codebase:$CLASSPATH
             java -Djava.rmi.server.codebase=http://kilpinen.mcs.gac.edu/~jstudent/codebase/ \
                  -Djava.security.policy=$HOME/public_html/policy \
                  edu.gac.jstudent.movies.dummy.ChainImpl
    

  13. Now that your dummy server is running, you should connect to it. Do so by copying the file dummyFindActor.html to somewhere in your www-docs/ directory, and accessing it through Mozilla.

  14. To kill off your server, just type control-c in the terminal window where it is running. If you don't kill your server, it will stay running until kilpinen crashes or is rebooted. For a real server, we could arrange that it was automatically restarted when kilpinen is rebooted, but you probably won't want that for this lab. (I've tried to do it with my own servers; let me know if they ever aren't running.)
  15. 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. One issue you'll run into is that in this lab, we're looking for movies given an actor's full name (e.g., "Claude Rains") rather than seperate first and last names (e.g., "Claude" and "Rains"). To deal with this, you can use SQL's string concatenation operator, ||. For example, to just find Claude Rains in the persons table, you could do

             select * from persons where fnames || ' ' || lname = 'Claude Rains';
    
    Of course, you want to do a more complex query that also takes the other tables into account. Make copies of ChainImpl.java and StoreImpl.java in a different directory. Change the package lines to a different package as well. Change the name ChainImpl rebinds under from jstudent-dummy-chain to jstudent-chain. Now edit in the JDBC code, compile, deploy, and test as above. As with everything, ask if you need help.

Submitting your code

To submit your code, do the following:

  • In a shell, go to the parent directory of the directory containing your Lab4 directory. Warning: You will probably have problems if this directory name has spaces in it, since Linux doesn't look kindly on so-named files/directorys.

  • Assuming that the directory containing your solution is named Lab4, now type:
         ~karl/bin/mcs270/submit Lab4
    


    Instructor: Karl Knight