Program 1: URL Parser

CS 455/555, Fall 2007, Weigle
Assigned: Thursday, August 30, 2007
Due: Thursday, September 6, 2007 before class

CS 455/555 | Description Background Requirements Rules Testing Submission Java Intro

Description

During the semester, we will be building up to writing a text-based web client that can request and download a single file from a web server using HTTP, which is the protocol used by two computers to exchange information on the web. This first assignment will not involve any networking or socket programming, but will just get you started on the way to building an HTTP client in Java on the CS Unix systems.

Note: Do not wait until the last minute to start this assignment. If you are inexperienced with Java or Unix, please look at the tutorials posted on the course webpage and ask questions early.

Background

Your program will take a URL as its only command-line argument. The URL will be given in the following format:

http://hostname[:port][/path]

hostname - the web server's hostname
:port - an optional command that tells the web client to connect to a different port than the default of port 80 (we'll talk more about how this is used later on)
path - the path from the web server's main directory to the requested file, if this is not present, then the path is '/'

URL Examples:
http://www.cs.odu.edu/~mweigle/courses/cs455-f07/schedule.html
http://www.fakehost.com:765/fakepath/fakefile.html

The hostname is shown in bold font, and everything after the first '/' following the hostname is part of the path.

Requirements

Rules

Testing

Your program will be graded on how well it satisfies the requirements in handling a set of test URLs. You should test your program rigorously with various URLs before submitting.

Example 1

% java UrlParser http://www.cs.odu.edu/~mweigle/foo.txt 
 
URL : http://www.cs.odu.edu/~mweigle/foo.txt 
Host: www.cs.odu.edu 
Port: 80 
Path: /~mweigle/foo.txt

Example 2

% java UrlParser http://www.amazon.com:4567/Harry_Potter/this/is/a/book.html
  
URL : http://www.amazon.com:4567/Harry_Potter/this/is/a/book.html 
Host: www.amazon.com 
Port: 4567 
Path: /Harry_Potter/this/is/a/book.html

Example 3

% java UrlParser http://www.amazon.com 
 
URL : http://www.amazon.com 
Host: www.amazon.com 
Port: 80 
Path: /

Example 4

% java UrlParser http://www.amazon.com/ 
 
URL : http://www.amazon.com 
Host: www.amazon.com 
Port: 80 
Path: /

Example 5

% java UrlParser

Usage: java UrlParser URL

Submission

You must name your source file UrlParser.java. Make sure that you submit all files necessary to compile your program.

Directions for submitting your assignment through Blackboard

Getting Started with Java

If you've never programmed with Java before, here are a couple of helpful hints:

Here is the skeleton for Program 1 (to be saved as UrlParser.java):

 
// Insert Your Name 
// Insert Your Class (CS 455 or CS 555), Fall 2007 
// Program 1 - URL Parser 
 
import java.io.*; 
 
class UrlParser { 
 
   public static void main (String argv[]) 
   { 
 
       // insert your code here 
 
   } 
}