Bug fixed
authoradash <adash>
Wed, 1 Nov 2006 21:06:28 +0000 (21:06 +0000)
committeradash <adash>
Wed, 1 Nov 2006 21:06:28 +0000 (21:06 +0000)
Comments added; Most up-to-date working version with logging functionality

Robust/src/Tests/Logger.java
Robust/src/Tests/WebServerExample.java
Robust/src/Tests/WebServerSocket.java

index 88f97142c95cafc855b657f935515045df00985e..6e8ffa0ad594d41a7990b6060ee4082b4a32c7d6 100644 (file)
@@ -1,31 +1,25 @@
 public class Logger extends FileOutputStream {
-       //Logging flag
+       //Logger flag
        flag Initialize;
 
        //Constructor
        public Logger(){
-               System.printString(" Log Object Created\n");
-               //FileOutputStreamOpen("./Tests/htmlfiles/request.log");
+               FileOutputStreamOpen("./Tests/htmlfiles/request.log");//Open request.log file 
        }
-/*
+       //Logs filename as per client requests
        public void logrequest(String filename){
                String request = new String("\nNew Request received: ");
                write(request.getBytes());
                write(filename.getBytes());
                flush();
-               close();
        }
 
        public void logrequest(){
                String request = new String("\nNew Request received: ");
                write(request.getBytes());
                flush();
-               closerequest();
-       }
-*/
-       public void logtesting(){
-               System.printString(" testing log object\n");
        }
+
        public void closerequest() {
                close();        
        }
index 6967e847d67779b4e620a2368dee81a9044c8e5d..c0e482be5215bb1641ea4abfac97a6e548d266fd 100644 (file)
@@ -1,7 +1,7 @@
 /* Startup object is generated with the initialstate flag set by the
  *  system to start the computation up */
 
-/* Create New ServerSocket*/
+// Create New ServerSocket
 task Startup(StartupObject s {initialstate}) {
        System.printString("W> Starting\n");
        ServerSocket ss = new ServerSocket(9000);
@@ -10,7 +10,7 @@ task Startup(StartupObject s {initialstate}) {
        taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
 }
 
-/*Listen for a request and accept request*/ 
+//Listen for a request and accept request 
 task AcceptConnection(ServerSocket ss{SocketPending}) {
        System.printString("W> Waiting for connection...\n");
        WebServerSocket web = new WebServerSocket() {!WritePending};
@@ -18,14 +18,14 @@ task AcceptConnection(ServerSocket ss{SocketPending}) {
        System.printString("W> Connected... \n");
 }
 
-/* Process the incoming http request */
+// Process the incoming http request 
 task ProcessRequest(WebServerSocket web{IOPending}) {
        System.printString("W> Inside ProcessRequest... \n");
        web.clientrequest();
-       taskexit(web {WritePending, LogPending});
+       taskexit(web {WritePending, LogPending}); //Sets the WritePending and LogPending flag true 
 }
 
-/* Do the WriteIO on server socket and send the requested file to Client*/
+//Do the WriteIO on server socket and send the requested file to Client
 task SendFile(WebServerSocket web{WritePending}) {
        System.printString("W> Inside SendFile ... \n");
        web.sendfile();
@@ -33,12 +33,10 @@ task SendFile(WebServerSocket web{WritePending}) {
        taskexit(web {!WritePending});
 }
 
-/* Log the Client request*/
-task LogRequest(WebServerSocket web{LogPending}, Logger log{Initialize}) {
-//task LogRequest(Logger log{Initialize}) {
-//     System.printString("L > Inside logrequest");
-//     log.logrequest();
-       log.logtesting();
+// Log the Client request
+task LogRequest(WebServerSocket web{LogPending}, Logger log{Initialize}) {//Task fired when both
+                                                                        // LogPending and Initialize flags are true 
+       System.printString("L > Inside logrequest\n");
+       log.logrequest(web.filename);
        taskexit(web {!LogPending});
-//     taskexit(log {!Initialize});
 }
index 02d3d029bd480b14a1b9c6fddc81f5c227ffe6e3..3ef5589c2bf66e1db0a8f0ab0497e15e4998dc23 100644 (file)
@@ -2,6 +2,7 @@ public class WebServerSocket extends Socket {
        // Websocket flag
        flag LogPending;
        flag WritePending;
+       //Filename requested by the client 
        String filename;
        
        //Constructor
@@ -21,32 +22,34 @@ public class WebServerSocket extends Socket {
        
        // Send the html file , read from file one byte at a time       
        public void sendfile() {
-               //String filepath = new String("./Tests/htmlfiles/index1.html");
                StringBuffer req_file = new StringBuffer("./Tests/htmlfiles/");
                req_file.append(filename);
                String filepath = new String(req_file);
                FileInputStream def_file = new FileInputStream(filepath);
-               int status = def_file.getfd();  
+               int status = def_file.getfd();//Checks if the file is present in 
+                                             //current directory       
                httpresponse();
                if (status == -1){
-                       StringBuffer response = new StringBuffer("404: not found: ");
+                       StringBuffer response = new StringBuffer("404: not found: ");//Send 404 error if
+                                                                                    // file not found
                        response.append(filename);
                        String buffer = new String(response);
                        write(buffer.getBytes());
-                       //System.printString("File does not  exist");
                        def_file.close();
                        return;
                }
                byte buf[] = new byte[16];
                int ret;
                
-               while ((ret = def_file.read(buf)) > 0) {
+               while ((ret = def_file.read(buf)) > 0) {// Read from file and write 
+                                                       // one byte at a time into the socket 
+
                        byte tosend[] = new byte[ret];
                        for (int i = 0; i < ret; i++) {
                                tosend[i] = buf[i];
                        }
                        write(tosend);
-                       String str = new String(tosend);
+                       //String str = new String(tosend);
                }
                def_file.close();
        }
@@ -54,14 +57,11 @@ public class WebServerSocket extends Socket {
        //Discover what the client wants and handle their request       
        public int clientrequest(){
                byte b1[] = new byte[1024];
-               read(b1);
+               read(b1);//Read client request from web server socket
                String clientreq = new String(b1);
-               int index = clientreq.indexOf('/');
+               int index = clientreq.indexOf('/');//Parse the GET client request to find filename
                int end = clientreq.indexOf('H');
                filename = clientreq.subString((index+1), (end-1));
-               System.printString("DEBUG -> Client requested: ");
-               System.printString(filename);
-               System.printString("\n");
                return 0;
        }
 }