Web Server Project More tips on How to. Getting started – think of what to do (1) Process configuration –Port –MaxThreads –ScriptAlias –Alias –DocumentRoot.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
System Programming Practical session 11 Multiple clients server Non-Blocking I/O.
Multithreading Threads Concept
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 Streams Files are a computer’s long term memory Need ability for programs to –get information from files –copy information from program variables to.
Website Development with PHP and MySQL Saving Data.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Lab 2C Primer I/O in Java Sockets Threads More Java Stuffs.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
The Java I/O Classes and Interfaces cont’d
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Lab 2 Primer Assignment 3 Structure File I/O More parsing and HTTP Formatting.
Introduction to Java Network Programming and HTTP
Form Data Encoding GET – URL encoded POST – URL encoded
CSC 480 Software Engineering Socket. What is Socket? A socket is one end-point of a two-way communication link between two programs running on the network.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Jigsaw Performance Analysis Potential Bottlenecks.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Java Server Programming Web Interface for Java Programs.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
More than one site? Use multiple configuration files Use multiple configuration files  httpd –d {path}  Assumes “conf/httpd.conf” Logging transactions.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Using Applets as Front Ends to Server-Side Programs.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Web Server Assignment1 Reference ( Main class (for example : MyServer.java) –Initialization.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil, Simon Roberts, IBM Corp Advanced Java Programming CSE 7345/5345/ NTU 531 Multithreaded/Sockets/Server Welcome.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Sockets, Routing, Sessions, Handlers
Threads in Java Two ways to start a thread
Block 15 Developing the Calculator application
Java Exceptions and I/O
Networking with Java 2.
I/O Basics.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
CSCD 330 Network Programming
Web Design & Development Lecture 8
Multiplexing/Demux.
Presentation transcript:

Web Server Project More tips on How to

Getting started – think of what to do (1) Process configuration –Port –MaxThreads –ScriptAlias –Alias –DocumentRoot –ServerRoot –log –Mime.types

Getting started – think of what to do (2) Parse HTTP request –Method –URI with query string or arguments –Read in headers –Is Authentication required? –Is caching used? –Is the CGI invoked?

Getting started – think of what to do (3) Generate HTTP response –Status code –Create headers –Attach body (optional) Should handle binary properly

Getting started – think of how to invoke CGI String[] env = createEnvVariables(); Process proc = Runtime.getRuntime().exec(request.getPath(), env); // For POST send the parameters to STDIN if(request.getMethod().equals("POST")) servePostParameters(proc); BufferedInputStream in = new BufferedInputStream(proc.getInputStream()); // read in the execution results return contentLen; } l.addElement("SERVER_PORT=" + MyServer.htProp.getPort()); … String[] returner = new String[l.size()]; for(int i = 0; i < l.size(); i++) returner[i] = (String)l.elementAt(i); EnvVariables

/*** Used for the POST BufferedReader in */ private void readParameterString( BufferedReader in ) throws Exception { StringBuffer buf = new StringBuffer(); // Read characters one by one from the input stream while(in.ready()) buf.append( (char)in.read() ); parameterString = buf.toString(); } // end-readParameterString /*** Used for the GET method */ private void extractParameterString() throws Exception { // Were there any parameters passed? int paramPtr = path.indexOf("?"); if( paramPtr > 0 ) { // Set parameter string parameterString = path.substring( paramPtr + 1 ); // Strip path of the parameters path = path.substring(0, paramPtr); } } // end-extractParameterString______________________________________ How to set Parameter String for GET/POST

/** Process p - running CGI process * * Writes the post body message into the input stream of the * running CGI process */ void servePostParameters(Process p) throws Exception { BufferedOutputStream args = new BufferedOutputStream(p.getOutputStream()); String input = request.getParameterString(); for(int i = 0; i < input.length(); i++) args.write((int)input.charAt(i)); args.close(); } // end-servePostParameters How to pass Parameter String to CGI

Etc… File file; writer.println("Content-Length: " + (valid ? ((contentLen > -1) ? contentLen : file.length()) : 128)); writer.println("Last-Modified: " + new Date(file.lastModified()));

Getting started – think of how to mix PrintWriter & binary stream in the response private void serveFile() throws Exception { byte[] inBuffer = new byte[BUF_LEN]; int bytesRead; FileInputStream in = new FileInputStream(file); try { do { bytesRead = in.read(inBuffer); if(bytesRead > 0) out.write( inBuffer, 0, bytesRead ); } while( bytesRead == BUF_LEN ); } catch( SocketException e ) {} in.close(); out.close(); } OutputStream out; PrintWriter writer = new PrintWriter( out, true ); writer.println(request.getProtocol() + " " + code + " " + reasonPhrase);

Multithread example I A server class starts max number threads of request_handler that extends Thread class. for(i=0; i<maxthreads;i++){ request_handler server_thread = new request_handler(ss,i,hc,mc,l); server_thread.start(); } hconfig = new httpd_config("httpd.conf"); if(!hconfig.isValid()){ System.out.println("Configuration file not correct"); return;} mime = new mime_config(hconfig.getValue("TypesConfig")); mime.setDefault(hconfig.getValue("DefaultType")); s = new server(hconfig,mime); if(s.isReady()){ s.run(); } Server.run

public void run(){ while(true){ reset(); s = get_socket(); if(s==null){ // got an error, // return and kill thread return; } set_streams(); get_request(); process_request(); send_reply(); close_socket(); } Request_handler.run private void reset(){ env.reset(); r_method = null; r_page = null; r_http_version = null; r_address = ""; r_agent = "-"; r_accept = null; r_referer = "-"; r_ctype = null; r_clength = "0"; r_command = ""; error_code = 0; script = false; filename = null; scriptname = null; filelength = 0; filestream = null; } Request_handler.reset

private synchronized Socket get_socket(){ try{ Socket incoming = ss.accept(); return(incoming); } catch(IOException e){ System.out.println(e); } return(null); } Request_handler.get_socket

Multithread example II A main server class waits for connections and creates new thread when a new request arrives. The ServerHandler extends thread class. while( true ) { Socket socket = sSocket.accept(); new ServerHandler( socket, numThreadsCreated, srmProp ).start(); } BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream())); request.readRequest(in); response = new HResponse(request,socket.getOutputStream()); socket.close(); ServerHandler.run

Grading Philosophy Grading is based on functionality developed by you. You may develop authentication utilizing instead of.htaccess, develop caching using different header rather than “notModifiedSince” Please specify what is implemented and why you chose not to follow the guidelines in your documentation and explain to TA during the interactive grading

Web server Grading Part I Basic functionality (3/4) –Request & response using network connection –Configuration –Images and other mime types –Mandatory session with TA during the week of 3/6 ~ 3/10

Web server Grading Part II Advanced functionality (3/18) –Multithreading –Invoking CGI –Caching –Authentication –Persist connection –More features?