package Serfler; // Serfler - an Http server written in Java based on servlets // Copyright (c) 1998 by Douglas Harris // Distributed under the GNU General Public License // // A copy is included with this software distribution. // The package is available from // http://spectral.mscs.mu.edu/javadev/src/serfler.zip // import javax.servlet.*; import java.net.*; import java.io.*; import java.util.*; public class SerflerServer implements Runnable{ Thread t; ServerSocket l=null; static SerflerContext loader = new SerflerContext(); static String sServerRoot = "/server"; static String sServletRoot = "/servlets"; static String sServletCode = "/javadev/servletCode"; static String sImageRoot = "/images"; static String sDocumentRoot = "/"; static String sServerAdmin = "/Admin"; static String sServerInfo = "Servler0.5";; static String sServerLogFileName=null; static PrintStream sServerLogStream=System.out; static int sMinNumberOfHandlers = 3; static int sMaxNumberOfHandlers = 50; static int sServerPort; static String sServerPortString; static int sTimeout=5000; static int sBacklog=50; static boolean sVerbose; static Properties sDefaultProperties=new Properties(); static Properties sStaticProperties=new Properties(sDefaultProperties); static Properties sFileProperties=new Properties(sStaticProperties); static Properties sProperties=new Properties(sFileProperties); static{ sDefaultProperties.put("document.dir","/"); sDefaultProperties.put("server.dir","/server"); sDefaultProperties.put("servlet.dir","/servlet"); sDefaultProperties.put("servlet.code","/javadev/servletCode"); sDefaultProperties.put("images.dir","/images"); sDefaultProperties.put("admin.dir","/Admin"); sDefaultProperties.put("server.min.handlers","30"); sDefaultProperties.put("server.max.handlers","50"); sDefaultProperties.put("server.port","8989"); sDefaultProperties.put("server.timeout","5000"); sDefaultProperties.put("server.backlog","50"); try{ String propFileName=System.getProperty("java.home")+File.separator+ "lib"+File.separator+"servler.properties"; File propFile=new File(propFileName); if ((propFile!=null)&&propFile.exists()&&propFile.canRead()){ InputStream propInputStream = new BufferedInputStream(new FileInputStream(propFile)); sStaticProperties.load(propInputStream); propInputStream.close(); } } catch(IOException x){ } } SerflerServer(String[] args){ sMinNumberOfHandlers = 50; sMaxNumberOfHandlers = 100; sServerPort=8989; t=new Thread(this); } public void log(String s){ loader.log(s); } public static int getIntProperty(String s, int d){ try{ return (s==null)?d:Integer.parseInt(s); } catch(NumberFormatException x){ return d; } } public void start(){ loader.init(sProperties); t.start(); log("======Serfler Started======"); } //The Server JDH public void run(){ loader.loadSerflerServlets(); log("======Serfler Servlets Loaded======"); loader.setServlets(); log("======Other Servlets Loaded======"); SerflerHandler aHandler; try{ initHandlerQueue(sMinNumberOfHandlers); }catch (Exception x){ x.printStackTrace(); } try{ sServerPort=getIntProperty(sServerPortString,sServerPort); l=new ServerSocket(sServerPort); log("======Listener running at port: " +sServerPort+" ======"); while(true){ aHandler = pull(); aHandler.startConnection(l.accept()); log("======Connection accepted======"); } }catch(Exception x){x.printStackTrace();} } public static void main(String[] args){ for(int i=0;i+1