Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Server Assignment1 Reference (http://java.sun.com/products/jdk/1.3/docs/api/packages.html) Main class (for example : MyServer.java) –Initialization.

Similar presentations


Presentation on theme: "Web Server Assignment1 Reference (http://java.sun.com/products/jdk/1.3/docs/api/packages.html) Main class (for example : MyServer.java) –Initialization."— Presentation transcript:

1 Web Server Assignment1 Reference (http://java.sun.com/products/jdk/1.3/docs/api/packages.html) Main class (for example : MyServer.java) –Initialization : Read in configuration files and make proper data structures (recommend to create a new class what separates the configuration part) httpd.conf : document root and aliases including ScriptAlias, port number and etc mime.conf : make a data structure that associates between extension and type Hints for Your Web Server Structure

2 Web Server Assignment2 Main class (continue) –Create Serversocket and socket and repeat waiting for connection & processing the request ServerSocket ding = new ServerSocket(Portnumber); Socket dong = null; while (true) { –wait for connection using dong = ding.accept(); –process request by »1. parse the request (create a HTTP message class) »2. apply the configurations such as Alias, DocumentRoot and etc »3. process the request »4. generate a response }

3 Web Server Assignment3 Java Classes –Use InputStream and OutputStream to communicate between Server and browser, between server and subprocess (for CGI) –Utilize InputStreamReader, BufferedReader to make your life easier InputStream input = clSock.getInputStream(); // Socket clSock; inReader = new InputStreamReader(inS); //InputStream inS; bf = new BufferedReader(inReader); String inStr = bf.readLine(); –Utilize StringTokenizer for parsing request message StringTokenizer st = new StringTokenizer(inStr, ": "); token = st.nextToken(); setHeaders(st, token); –Utilize Process, Runtime class for invoking a new process Process sub; Runtime r = Runtime.getRuntime(); // Setup the environment variables into ‘env’, the array of String sub = r.exec(cgifile, env); OutputStream clOs = clSock.getOutputStream(); BufferedInputStream bis = new BufferedInputStream(sub.getInputStream());

4 Web Server Assignment4 Read and Parse HTTP message Create a class that reads, parses the HTTP message and stores each processed value (QUERY_STRING, URL, etc). Read first line –If GET method is used, Extract URL, protocol. –Check if ‘?’ exists within URL if then, extract QUERY_STRING –Read following lines and process header and its value pairs –If Post method is used, process body (read in for passing it to sub process) Apply DocumentRoot, ScripAliase, or Aliase to generate an absolute path (or relative to the server program) of the requested document or script

5 Web Server Assignment5 Process the request –Check if the request is valid (available, readable, or executable) –Check if the request is text- read in html/plain file image - read in image file script - execute the script and retrieve the result –Generate a response with proper status, headers and attach the body Return the response


Download ppt "Web Server Assignment1 Reference (http://java.sun.com/products/jdk/1.3/docs/api/packages.html) Main class (for example : MyServer.java) –Initialization."

Similar presentations


Ads by Google