1 26 27 28 package org.objectweb.openccm.deploytool; 29 30 import java.io.*; 31 import java.net.*; 32 33 34 35 public class MicroServerHttp implements Runnable { 36 37 private Socket s; 38 private ServerSocket ss; 39 private InputStream is; 40 private String filename; 41 42 public MicroServerHttp (ServerSocket ss) 43 { 44 this.ss=ss; 45 } 46 47 public MicroServerHttp(ServerSocket ss,java.io.InputStream is,String filename) 48 { 49 this.ss=ss; 50 this.filename=filename; 51 this.is=is; 52 } 53 54 public void run () 55 { 56 try { 57 s=ss.accept(); 58 59 InputStreamReader in = new InputStreamReader(s.getInputStream()); 60 PrintStream out = new PrintStream(s.getOutputStream()); 61 String rq = new LineNumberReader(in).readLine(); 62 System.err.println("Request received:"+rq); 63 if (rq.startsWith("GET ")) { 64 if(filename==null) 65 { 66 File f = new File(rq.substring(5, rq.indexOf(' ', 4))); 67 if (f.exists() && !f.isDirectory()) { 68 is = new FileInputStream(f); 69 } 70 else return; 71 } 72 73 byte[] data = new byte[32000]; 74 75 out.print("HTTP/1.0 200 OK\n\n"); 76 77 int readed=is.read(data,0,32000); 78 while(readed>0) 79 { 80 out.write(data,0,readed); 81 readed=is.read(data,0,32000); 82 } 83 84 is.read(data); 85 is.close(); 86 87 } else { 88 out.print("HTTP/1.0 404 Not Found\n\n"); 89 out.print("<html>Document not found.</html>"); 90 } 91 out.flush(); 92 out.close(); 93 s.close(); 94 95 } catch (Exception e) {e.printStackTrace(); } 96 } 97 98 99 105 107 108 110 113 } 114 | Popular Tags |