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-chainTo 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:
mkdir ~/public_html mkdir ~/public_html/codebase
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
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.)
mkdir ~/.onbootNow 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-chainAt 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 kilpinenOnce on kilpinen, you can run your server as follows:
~/.onboot/dummy-chain &
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