CISC474, Homework H07, Spring 2007
Java Web App Best Practices
(Ant, JUnit, Javadoc, WAR files)

Introduction

In this assignment, you'll redo the product servlet you did in H06, using "best practices".

I've provided code for you for a new version of the Beer MVC Servlet from HFSJ, that uses Ant, JUnit, Javadoc and WAR files in a way that represents (as far as I understand them) "best practices" for doing Java web app development.

Best Practices? Well, a "whole lot better" in any case...

Ok, "best practice" is a bit of a buzzword. It is probably overstating the case to call what we are doing here "best practices". I'm sure that if we look into it more deeply, we'll find many ways we could improve our coding practices over what we are doing here.

Let's just say we are "upping our game" a bit from what we did on H06, and moving in the direction of how folks in the real world tell me that professional web app development is typically done.

An outline of how H07 is different from H06

Several things we are doing differently, all of which (I'm told) are considered by real-world Java developers to be good practice:

So, you'll also need to be familiar with Ant, JUnit, and JavaDoc

If you coasted through P05 by relying on other team members to do the Ant and JUnit work—well, now those chickens are coming home to roost. The Wiki pages for Ant and JUnit may help. You may also want to consult your fellow team members to help you if you are having trouble.

Also from now on, all Java code in this course should be commented with comments suitable for making documentation with Javadoc. There is a wiki page for JavaDoc also.

A few words about Problem Based Learning, and the next few assignments...

As you run into problems with Ant, JUnit, and Javadoc, and other technologies —and as you work through the answers to these problems—you are strongly encouraged to post the problems and solutions on the Wiki. Then, come see me, so that you can get choice point credit for your contributions!

This is Problem-Based Learning!

This is the style of learning you will need after you graduate.

Assignments that must be completed first

Overview

In this assignment, you will:

Step-by-Step Instructions

Step 1: Reading

The following reading is recommended:

Step 2: Unpack, Review, and deploy the beerAdvisor.tgz source

You can obtain the source either as:

Download this to your development directory. You can do this directly on porsche as follows. This script shows getting both files, though in fact, you only need to get one or the other.

porsche[196] > cd
porsche[197] > cd web-dev
porsche[198] > pwd
/usa/pconrad/web-dev
porsche[199] > ls
A08/  A08.new/  A08.zip  beerAdvisor/  beerDBV1/  beerDBV1.src.tgz*  beer.tar*
porsche[200] >  wget http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.tgz
--21:49:02--  http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.tgz
           => `beerAdvisor.tgz'
Resolving www.udel.edu... 128.175.13.63
Connecting to www.udel.edu|128.175.13.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,771 (7.6K) [text/plain]

100%[======================================================================================================================================================================>] 7,771         --.--K/s             

21:49:02 (168.43 MB/s) - `beerAdvisor.tgz' saved [7771/7771]

porsche[201] > wget http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.zip
--21:49:06--  http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.zip
           => `beerAdvisor.zip'
Resolving www.udel.edu... 128.175.13.63
Connecting to www.udel.edu|128.175.13.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19,556 (19K) [application/zip]

100%[======================================================================================================================================================================>] 19,556        --.--K/s             

21:49:06 (105.37 MB/s) - `beerAdvisor.zip' saved [19556/19556]

porsche[202] > ls
A08/  A08.new/  A08.zip  beerAdvisor/  beerAdvisor.tgz  beerAdvisor.zip  beerDBV1/  beerDBV1.src.tgz*  beer.tar*
porsche[203] > 



(Note that this will not work from the clients of porsche, since they are not directly connected to the Internet—so download on porsche, then ssh into your client to do the rest of the steps below.)

Step 2a: Review the development environment (build.xml, directory structure)

Note the build.xml file, and especially note the global.properties file. Note how we can take everything that would have to be change to move from one system to another, or one user to another, and we can factor it out into a file called global.properties.

Step 2b: Review the model (noting the Javadoc and JUnit tests)

Note that the package name is not com.example.*, but rather edu.udel.cisc474.pconrad.beerAdvisor.*

Note that every class and every method has Javadoc style comments.

Note that the model is tested with JUnit tests

Step 2c: Modify the global.properties, test the model, and review the Javadoc

Now, change the global.properties file so that instead of trying to deploy the javadocs and war files to pconrad's directories are porsche, the javadoc and war files are directed into your own directories on porsche.

Then, type ant, and notice the menu that comes up. Try all the various options in that menu.

Step 2d: Review the View

The view consists of the files index.html and result.jsp in the web directory.

Note that form.html is now index.html.

Note the header comments in both index.html and result.jsp

Note how both files contain proper XHTML that will validate. Note that we can validate the result of a JSP by doing a view source, and cutting and pasting the resulting X/HTML code into the box at Validate by Direct Input box http://validator.w3.org.

Note how this version of the JSP uses the for each construct of Java 5.0.

Step 2e: Review the Controller

Note that the controller also has Javadoc comments.

Step 2f: Try deploying as a WAR, and test the Webapp

If you modified the global.properties file correctly, you should be able to go to your own tomcat, and type in http://porsche.cis.udel.edu:xxxxx/beerAdvisor and see the servlet come up.

Try modifying something in the view, in the Model and in the Controller, and type ant deploy-war

Make sure that everything is working properly, and that you understand all the magic that is taking place!

If it is all working, you are ready to try your own version of this.

The purpose is get comfortable with all of these "best practices", so that you can use them in your group project, and in your choice projects (if you are using Java). If you are not using Java, you should still follow similar practices in PHP, or whatever technology you are using.

Step 3: Create your own product advisor web app, following the same model

Now, create your own app, using the product you selected in H05. This will be an update of the product servlet you did in H06, but using all the "best practices" that you just reviewed in my "new improved beerAdvisor" code.

For each of the steps below, refer back to the equivalent part of Step 2 to be sure that you are "getting" the things you should be "getting" for that step. You may also want to look over the grading rubric at the bottom of this assignment.

Step 3a: Create the development environment (build.xml, directory structure)

Step 3b: Code the model (along with Javadoc and JUnit tests)

Step 3c: Test the model, and review the Javadoc

Step 3d: Code the View

Step 3e: Code the Controller

Step 3f: Deploy as a WAR

Step 3g: Test the Webapp

Step 4: Prepare a static page (on copland) to document your work

You'll create a static HTML page http://copland.udel.edu/~jstudent/cisc474/H07 that contains

Step 5: Prepare a tarball (or zipfile) of your source distribution

Here is some advice from the wiki on creating a tarball and creating a zip file

Step 6: Upload the tarball (or zipfile) to your download directory, and submit to WebCT

Be sure that the link you created in Step 4 works properly for downloading your source distribution.

Be sure when you go into WebCT, that you both upload and submit.

(The reason to have you also submit on WebCT as well as putting the code on the web is that submitting on WebCT (a) creates a permanent archive, (b) establishes a submission time, and (c) enables the TA to give you a grade.)

Grading Rubric (100 pts total)

Item Description Points
Java code Your Java code works and is well commented and structured 20
Javadoc Your code has proper javadoc
(i.e. not the Javadoc that was in my code, still unmodified!)
10
Ant Your build.xml file looks reasonable 10
JUnit You have reasonable JUnit tests 15
WAR file You used a WAR file 10
Scripting and Submitted You followed instructions for scripting and submitting 10
Reasonable package names No example.com type package names 5
index.html Not form.html 5
tarball or zip file of source distribution
works properly
Top level directory is correct, you can unpack and do Ant, and get a menu. global.properties need to be changed only for classpath, and for deployment reasons. 5
HTML validates as HTML 4.0.1 strict, XHTML 1.0 strict, or XHTML 1.1 You should have a validation icon on your index.html, and your "result" HTML should validate when you copy and paste the view source of the resulting HTML (not the JSP source) into the "validate by direct input" box at http://validator.w3.org (the third one down). 10
TOTAL POINTS    

Due Date: Fri 04/13, 5:00pm


Valid XHTML 1.0 Valid CSS!