Assignment - 08


Assignment 8    [Due - Tues. Mar. 26, 2002]

General Requirements
Assignment 8 consists of implementing the "ServiceHandler" class for Web Server. The purpose of this assignment is threefold. First, to gain an understanding of the fundamental task of the Web Server. Second, to learn the precise format of the HTTP request and response messages as well as to understand the importance of the data within the message structure. And thirdly, to solidify the significance of the web server's document root. Thus, learn as much as you can about the message structures and experiment with as many headers as possible. Also, experiment with different document roots, along with making requests for: files, directories (with and without html files), etc.

Please follow these overall instructions:

 

Setting up and Testing Development Environment
  1. Use the PC assigned to your team, in Lab 301 and student# directory that you used for assignment 7.
    (If your student# directory was accidently used by another team member, use the next available directory.)
  2. In C:\assign8\student#\ServiceHandler.java
    • change the package name from "studentLastName" to your last name
    • save the file
  3. In C:\assign8\student#\config\httpserver-config.xml
    • change the "studentLastName" in:
      <ServiceHandler>studentLastName.ServiceHandler</ServiceHandler>
      to your package name (i.e. your last name, it MUST be the exact name you entered in ServiceHandler.java)
    • save the file
  4. Compile and Execute your web server
    (use the compiling and excuting instructions below.)
  5. Test your environment with the default data
    • launch a browser
    • if you are on the same host as the web server you just started,
      enter: http://localhost:8085/index.html
    • if you are on a different host then the web server you just started,
      enter: http://<IP address of web server>:8085/index.html

 

Compiling ServiceHandle.java
  1. open a DOS window;
  2. go to your student directory (C:\assign8\student#\)
  3. execute the compile batch command:

          compile ServiceHandler.java

    where:       compile = compiler batch file
          ServiceHandler.java = name of program

     

    Executing the web server
    1. open a DOS window, or use the one you used for compilation
    2. go to your student directory (C:\assign8\student#\)
    3. execute the web server batch command:

            startup [package_name]

        Notes:
      • you will know server is ready when the following line is displayed:
        Server runnning on <hostname>/IP address at port: 8085
      • this batch command will add your program to the jar,
        and then execute the jar. You will then notice serveral new files in your C:\assign8\student#\ directory.
    4. when you are done with the web server; stop it by: [control] [c] in the DOS window you started it

     

    Configuring the web server
    All configurations are sent in:
          C:\assign8\student#\config\httpserver-config.xml
    • changing the document root
      • In C:\assign8\student#\config\httpserver-config.xml
      • change the "C:\assign8" in:
              <DocRoot>C:\assign8</DocRoot>
              to your desired document root
      • save the file

    • changing the port number
      • In C:\assign8\student#\config\httpserver-config.xml
      • change the "8085" in:
              <Port>8085</Port>
              to your desired document root
      • save the file

    Problem 0:    Assignment Status

    **Important**
    The three problems 1-3 described in this assignment are progressive; meaning the previous problem(s) is needed in order complete the next problem. Since this the case, I will only be looking at your final problem, as it will imply you were able to complete the previous ones. Although I will only be looking at your final submission, it is highly reccomended that you keep separate working versions of each of your programs for back-up and solid development techniques. [simply rename it to ServiceHandlerV1, etc.]

    On your web page indicate where your work can be found, along with the last problem you were able to complete.
    For example:

    My work can be found at: Team B,   student3
    I completed work through: Problem 2

     

    Problem 1:     Creating a valid status line

    Part A:

    1. Change the ServiceHandler, doGet( ) to create and return a response message. The response message should:
      • contain an accurate status line
      • contain an entity body with a constant message that will be seen in the browser
        [i.e. Just hard-code a simple html file and pass that in. ]
      Note: Use good o-o techniques. Do not put all you code "in" the doGet( ). Create and call as many methods as needed to keep code clean, flexible, and readable!
    2. Add a comments section to the "beginning" of the program. In it, indicate what problem(s) you completed.
    3. Test you program using different document roots, but the same file name (e.g. fileA.html) where the files contain different content. For Example:
      • Test1: use Document Root-1 and fileA.html    (containing data A)
      • Test2: use Document Root-2 and fileA.html     (containing data B)

    Part B:
    On your web page, briefly describe your tests and corresponding results. Explain why you got the results you did.

     

    Problem 2:     Creating a fully qualified resource name

    Part A:

      Now the you know you have a correctly formatted status line, develop the code that creates the fully qualified name of the requested resource.
    1. Enhance the ServiceHandler, to do the following:
      • obtain the resource name from the request message
      • create a fully qualified name
        {the complete path name, starting with C: }
      • display both the original resource name that was in the request, as well as the fully qualified name.
    2. Test you program using different document roots and the same file name; as well as the same document root and different file names.
      • Test1: use Document root-1 and file-A
      • Test2: use Document root-2 and file-A
      • Test3: use Document root-2 and file-B

    Part B:
    On your web page, explain the relationship and significance of the document root and the request's resource name.

     

    Problem 3:     Get the resource and send to client

    Part A:

      Now the you have the full name of the requested resource, develop the code to locate it, read it and send it back to the client. Enhance the ServiceHandler, to do the following:
    1. Locate the resource on the host (your PC)
    2. Create and return the correct response message for the requested resource.
      • if the resource does not exist, send back the appropriate status code and your message stating the resource did not exist.
      • if the resource exists, return the resource in the entity body along with the appropriate status code.

    Compile and test the changes.

    Part B:

      On your web page:
    1. Explain the code conditions under which your error message (resource did not exist) will appear, as well as the code needed to display the browsers standard error message. Additionally, describe what you learned from this error processing.
    2. Name the different headers you used in your messages and what they do. If you did not use any headers, explain why you did not need to add any headers to your messages.

     

    Problem 4:     Web Server Enhancements

    On your web page, describe how you would change the web server program to handle serving (returning) binary files such as jpg or gif, in addition to the html pages it can currently serve.

     

    What to hand in:
    Turn in a hardcopy of your Assignment-08 web page.
    You may be asked to execute your code at a time to yet be determined, or I may simply logon to your team PC and excute the client. Thus, be sure it IS compiled, I will only excute the startup command.

    Questions ? ?

  4. Send Ravi Pakala an e-mail at  rvpakala@yahoo.com
  5. Use the subject: "assign08 question topic "

     


    Additional Thoughts

    1. Where to do your work:
      Questions are sure to arise about where you 'have' to do your work. The answer is anywhere you choose, with the caveat that you are responsible for making sure your student# directory is completely workable on the due date. In other words, when I test your web server, all I will do is execute the startup command and check from that point. Fair warning: NO second chances here!!

      To help you work on your own PC:

      • Download this file to your root level: c:\
      • You may need to remove the read-only property from the files you need to change
      • You need to have JDK 1.3

    Sample ServiceHandler Code

    package  studentLastName;
    
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.io.*;
    import java.util.*;
    import net.rvpakala.service.*;
    import net.rvpakala.httpServer.*;
    
    public class ServiceHandler extends ServiceProcessor
    {
       public ServiceHandler()
       {
       }
    
       // Process GET requests
       public void doGet(HTTPRequest request,HTTPResponse response) throws IOException
       {
        super.doGet(request,response);
    
        //----------------------------------------------------
        // The following sample/psuedo code is to:
        //    (a) illustrate generically what you are to do
        //    (b) help you recall the super class methods
        //        available to you
        //
        //   String  responseLine1 = "<html>"     +
        //                           "<head>"     +
        //                           " From HTTP Server Code"  +
        //                           "</head>"     +
        //                           "<body>"     +
        //                           " this is my message"  +
        //                           "</body>"     +
        //                           "</html>";
        //   String  responseLine2= "status line detail";
        //
        //   response.getWriter().write(responseLine1);
        //   response.getWriter().write(responseLine2);
        //
        //
        // ** NOTE: you "must" flush and close the Writer as
        //    well as close th Reader, when you have completed
        ///   creating your response message. This is shown in
        //    the next 3 lines:
        //   response.getWriter().flush();
        //   response.getWriter().close();
        //   response.getReader().close();
        //
        // -------------------------------------------------------
       }
    
    }