|
Project #4 |
CMSC 132 |
|
Due Date: Thursday Oct 27, 6:00 pm |
Object-Oriented Programming II |
|
Type of Homework: Closed |
Fall 2005 |
Objective
This homework has several objectives. Those objectives are:
This homework is considered a closed homework. Make sure you read the Open/Closed policy before continuing working on this project.
Overview
For this project you will complete the following tasks:
Your project will be graded as follows:
Public JUnit tests 50 %
Release JUnit tests 30 %
Style 20 %
For this project:
We encourage you to start working on this project as soon as possible as there are a lot of details that can not be completely specified in this description. You should address these doubts ahead of time during lab session, or office hours. We encourage you to work every day on this project (even for a couple of minutes). This will allow you to submit this project on time.
Even if you are not planning to work on the project for a while make sure that:
You can compile a simple class using the provided code distribution. If you have problems compiling a simple class, see your TA immediately.
Submit your project using the "Submit Project" option in Eclipse and verify your submission has been received in the submit server. It is important that you submit your project using the "Submit Project" option rather than uploading a jar file to the submit server. If you are having problems with this submission process, contact your TA or instructor immediately.
You must debug your code using the Eclipse debugger and should not use "System.out.println" as a debug tool. TAs in office hours will require you to use the debugger to show any problems you are experiencing.
No secret testing is associated with this project.
Specifications
Generic Client and Server Classes
The basic functionality of a client/server environment is for the client to send a request to the server and wait for an answer. The server receives and process the request sending the answer back to the client. Your task is to implement generics client and server classes that we can use to develop more specific client and server applications.
GenericServer Class
In the generic package you will find an interface named CommandProcessor. A GenericServer object expects an object that implements the method defined in this interface. The GenericServer will call the method associated with the interface in order to complete requests submitted by the client. It is through the CommandProcessor interface that the Server is "generic".
This GenericServer class has only one public method:
public void startGeneric(CommandProcessor processor, ServerSocket serverSocket) - This method defines a server using the specified processor and serverSocket. The server will wait for clients to service. Once a client has been recognized, the server will process the client's requests until a request named "Disconnect" is sent by the client. The server will not reply to the "Disconnect" request and will just end servicing the client. Keep in mind that you must implement the server in such a way that you can run a client, submit some requests, disconnect, and then run the client again without having to restart the server. Notice that when you no longer need a client socket you should close the appropriate socket. Also keep in mind that to stop the server, we just stop the server program.
The CommandProcessor provided in the parameter is the object the server relies on to actually process a request. The server just receives a request and passes the request to the processor. The result generated by the processor is then returned to the client. It is this capability what makes the server a generic one. Usually subclasses will implement the expected processor for a particular server application.
Feel free to add any private instance variables and methods you understand are necessary. You may not add any additional public methods.
GenericClient Class
This class has three public methods:
public void startGeneric(String serverHostNameIP, int serverPortNumber) - This method establishes a communication with the server associated with the parameters.
public void sendRequest(String request) - This method sends a request to the server. The requests will always be strings.
public String receiveResponse() - This method waits for a server's response after a request has been sent. The server's response will be a string.
public void disconnect()- This method notifies the server it will no longer needs its services.
Feel free to add any private instance variables and methods you understand are necessary. You may not add any additional public methods.
Client and Server Classes
Using the above generic classes you can implement different kinds of clients and servers. To illustrate this capability, you will define client and server classes that rely on the generic classes defined above.
Server Class
The Server class will be a subclass of the GenericServer class and it will implement the CommandProcessor interface.
This class has two public methods:
public void start(int portNumber) - Initializes the superclass server with the appropriate reference to the command processor and starts the server on the specified port. Keep in mind that a portNumber value of 0 indicates that the port number is automatically selected. In Java when you create a ServerSocket using a port number equal to 0, the first available port number will be used. Keep this in mind while implementing the getPortNumber method described below.
public void start(ServerSocket serverSocket) - Initializes the superclass server with the appropriate command processor and starts the server using the specified serverSocket.
public String processRequest(String request) - Will take care of processing the request.
public int getPortNumber() - Returns the port number the server is using to accept client connections.
The requests the Server class must process are:
PING
The server replies to a ping request by sending the message "Server is Running: " followed by the date.
LOOKUP:Person'sName
where the LOOKUP command and the person's name are separated by a colon.
The file information.txt will contain information about individuals. The server will return the file entry associated with a specified individual or "NOTFOUND".
IMAGES:Web Site
The server will return the urls of images present in the specified web site. Keep in mind that you must specify the web site address starting with "http://". For example, if you want to look for images in www.cs.umd.edu, you need to provide the address as http://www.cs.umd.edu.
To recognize images, the server will search through the html code of the specified web page, looking for entries starting with "<img src=" where any number of spaces and options (e.g. border) may exist in between img and src. An image is represented by the string following "src=". The following is a representative example of one possible entry you will be searching for:
<img src="http://i.cnn.net/cnn/images/1.gif">
The server will return complete urls of images found. A complete url is defined as one that starts with "http://" and which provide the exact location of the image in such a way that we can cut and past the url in a browser and actually see the image. For this project you don't have to worry about sites that may use uppercase letters for img or src in the html code.
Keep in mind that the String class provides a set of methods that can prove extremely helpful for the parsing of a web site.
Feel free to add to the Server class any private instance variables and methods you understand are necessary. You may not add any additional public methods. Also, feel free to add any support classes you might need.
Notes:
- The Server class does not generate any output to the standard output device.
- In the code distribution we have left a class called StartServer that shows how we can use the Server class to run the server.
Client Class
The Client class will be a subclass of the GenericClient class. The class must implement the following public methods:
public String ping() - Returns the result of executing a ping request.
public String lookUp(String person) - Returns the result of looking up a person in the server.
public ArrayList<String> getImageURLsFrom(String hostName) - Returns the result of searching for images in a host. The method returns an ArrayList object were each entry represents an image url. The value null will be returned if no images are found.
Feel free to add to the Client class any private instance variables and methods you understand are necessary. You may not add any additional public methods. Also, feel free to add any support classes you might need.
In the code distribution we have left a class called ClientExample that shows how we can use the Client class to process some requests.
Java Construct Requirements
You must handle exceptions by defining the appropriate catch clause.
You may not use System.exit(0) in your code. If you understand that at some point you need to stop the program execution then throw an exception with an appropriate message as follows:
throw new IllegalArgumentException("Your message here");
Style Requirements
Honor Section Requirements
In addition to the above requirements, your class must satisfy the following requirements:
Submission
Submit your project using the submit project option associated with Eclipse.
Academic Integrity
Please make sure you read the academic integrity section of the syllabus so you understand what is permissible in our programming projects. We want to remind you that we check your project against other students' projects and any case of academic dishonesty will be referred to the University's Office of Judicial Program