⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpd.java

📁 很棒的web服务器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Are we lenient in HTTP mode?     */    private boolean lenient = true;    /**     * What client factory class should the server use.     */    private String     factory_class = "org.w3c.jigsaw.http.socket.SocketClientFactory";    /**     * The coordinate of the shuffler, or <strong>null</strong> is none is to      * be used.      */    private String shuffler_path = null ;    /**     * The server's root directory.     */    private File root_dir = null ;    /**     * The directory containing the server exported documents.     */    private File space_dir = null ;    /**     * FIXME check     * The server host name.     */    protected String host = null ;    /**     * FIXME check     * The server port.     */    protected int port = 8001 ;    /**     * This server client debug flag.     */    private boolean client_debug = false ;    /**     * This server's request time slice, in milliseconds.     */    private int request_time_out = 1200000 ;    /**     * This server's connection allowed idle time in milliseconds.     */    private int connection_time_out = 1200000 ;    /**     * This server's client thread priority.     */    private int client_priority = Thread.NORM_PRIORITY ;    /**     * This server's clients buffer size.     */    private int client_bufsize = 4096 ;    /**     * Is the file system case-sensitive ?     */    private boolean sensitivity = true;    /**     * This server root entity.     */    public FramedResource root = null ;    /**     * the old root ResourceReference     */    private ResourceReference root_reference = null;    /**     * FIXME check for clones     * This server URL.     */    protected URL url = null ;    /**     * Finishing (killing) the server.     */    private boolean finishing = false ;    /**     * Finishing, but restart straight up.     */    private boolean restarting = false ;    /**     * The indexer attached to this server.     */    private ResourceIndexer indexer = null ;    /**     * The realm catalog     */    private RealmsCatalog realms = null ;    /**     * The resource store manager for this server.     */    private ResourceStoreManager manager = null ;    /**     * The root resource's identifier.     */    private String root_name = null ;    private String root_class = null;    /**     * The full URL of Jigsaw's documentation as served by that server.     */    private String docurl = null;    /**     * The trash directory     */    private String trashdir = null;    /**     * The full URL of Jigsaw's chekpointer.     */    private String checkurl = null;    /**     * The list of public methods for that server.     */    private  String publicMethods[] = { "GET"					, "HEAD"					, "PUT"					, "POST"					, "LINK"					, "UNLINK"					, "DELETE"					, "OPTIONS" 					, "TRACE"    } ;    /**     * The <code>Public</code> header value, computed out of the     * <code>publicMethods</code> variable.     */    private HttpTokenList publicHeader = null;    /**     * The edit root for that server.     */    private ResourceReference editroot = null;    /**     * the sets of properties of this server     */    private Vector         propSet     = new Vector(8);    /**     * the catalog of indexers of this server      */    private IndexersCatalog indexers = null;    /**     * the resource context of this server      */    private ResourceContext context = null;    /**     * the config resource of this server     */    private AbstractContainer configResource = null;    /**     * and its dummy resource reference     */    private ResourceReference rr_configResource = null;    // is this server a clone?    private boolean isAClone = false;    // our master server ID, if we are a clone    private String masterID = null;    /**     * The property monitoring implementation.     * @param name The name of the property that has changed.     * @return A boolean, <strong>true</strong> if the changed was taken into     *    account, <strong>false</strong> otherwise.     */    public boolean propertyChanged (String name) {	// Is this a property we are interested in ?	if ( name.equals(SERVER_SOFTWARE_P) ) {	    software = props.getString(name, software);	    return true;	} else if ( name.equals(TRACE_P) ) {	    tracep = props.getBoolean(name, tracep) ;	    errlog (name + " changed to " + tracep) ;	    return true ;	} else if ( name.equals(LENIENT_P) ) {	    lenient = props.getBoolean(name, lenient) ;	    errlog (name + " changed to " + lenient) ;	    return true ;	} else if ( name.equals(DISPLAY_URL_ON_ERROR_P) ) {	    uri_error = props.getBoolean(name, uri_error);	    errlog (name + " changed to " + uri_error);	    return true;	} else if ( name.equals(KEEP_ALIVE_P) ) {	    keep = props.getBoolean (name, keep) ;	    errlog (name + " changed to " + keep) ;	    return true ;	} else if ( name.equals(LOGGER_P) ) {	    String tmp_logger_class;	    Logger tmp_logger;	    tmp_logger_class = props.getString(name, logger_class);	    // for now the removal of the logger should be done by hand	    if (!tmp_logger_class.equals(logger_class)) {		try {		    tmp_logger = (Logger) 			Class.forName(tmp_logger_class).newInstance() ;		} catch (Exception ex) {		    errlog (name + " change failed (bad logger class)") ;		    return false;		}		synchronized (this) {		    if (logger != null) {			logger.shutdown();		    }		    tmp_logger.initialize(this);		    logger = tmp_logger;		    logger_class = tmp_logger_class;		}	    }	    return true;	} else if ( name.equals(ROOT_NAME_P) ) {	    String newname = props.getString(name, null);	    if ( changeRoot(newname) != null ) {		errlog("new root resource ["+newname+"]");		return true;	    } else {		errlog("failed to change root to ["+newname+"].");		return false;	    }	} else if ( name.equals(SPACE_P) ) {	    errlog (name + " change failed (server running)") ;	    return false ;	} else if ( name.equals(HOST_P) ) {	    errlog (name + " change failed (server running)") ;	    return false ;	} else if ( name.equals(PORT_P) ) {	    // we will restart the server	    errlog (name + " switching port : " + props.getInteger(name, 80)) ;	    int newport = props.getInteger(name, 80);	    if (port != newport) {		int oldport = port;		port = newport;		checkpoint();		ServerSocket newsocket = null;		try {		    newsocket = factory.createServerSocket();		    socket.close();		    socket = newsocket;		} catch (Exception ex) {		    try { newsocket.close(); } catch (Exception e) {};		    port = oldport;		    // an error occured, return false		    return false;		}	    }	    return true ;	} else if ( name.equals(CLIENT_DEBUG_P) ) {	    client_debug = props.getBoolean(name, client_debug) ;	    errlog (name + " changed to " + client_debug) ;	    return true ;	} else if ( name.equals(REQUEST_TIMEOUT_P) ){	    request_time_out = props.getInteger(name, request_time_out);	    errlog (name + " changed to " + request_time_out) ;	    return true ;	} else if ( name.equals(KEEP_TIMEOUT_P) ) {	    connection_time_out = props.getInteger(name						   , connection_time_out);	    errlog (name + " changed to " + connection_time_out) ;	    return true ;	} else if ( name.equals(CLIENT_PRIORITY_P) ){	    client_priority = props.getInteger (name, client_priority) ;	    errlog (name + " changed to " + client_priority) ;	    return true ;	} else if ( name.equals(CLIENT_BUFSIZE_P) ){	    client_bufsize = props.getInteger (name, client_bufsize) ;	    errlog (name + " changed to " + client_bufsize) ;	    return true ;	} else if ( name.equals(DOCURL_P) ) {	    String propval = props.getString(name, docurl);	    try {		URL u  = new URL(getURL(), propval);		docurl = u.toExternalForm();	    } catch (Exception ex) {		return false;	    }	    return true;	} else if (name.equals(TRASHDIR_P)) {	    trashdir = props.getString(name, trashdir);	    File dir = new File(trashdir);	    if (! dir.exists())		dir.mkdirs();	    errlog(name + " changed to "+ trashdir);	    return true;	} else if ( name.equals(CHECKURL_P) ) {	    checkurl = props.getString(name, checkurl);	    errlog(name + " changed to "+ checkurl);	    return true;	} else if ( name.equals(PUBLIC_P) ) {	    publicMethods = props.getStringArray(name, publicMethods);	    publicHeader  = null;	    return true;	} else if ( name.equals(SERVER_USER_P) ) {	    String user = props.getString(SERVER_USER_P, null);	    errlog("new user: "+user);	    return false;	} else if (name.equals(SERVER_GROUP_P) ) {	    String group = props.getString(SERVER_GROUP_P, null);	    errlog("new group: "+group);	    return false;	} else {	    // We  don't care about this one	    return true ;	}    }    /**     * Initialize this server indexer.     */    private void initializeIndexer() {	ResourceContext c  = getDefaultContext();	IndexersCatalog ic = getIndexersCatalog();	IndexerModule   m  = new IndexerModule(ic);	// Register the default indexer:	m.registerIndexer(c, "default");	// Register the indexer module:	c.registerModule(IndexerModule.NAME, m);    }    /**     * Initialize the resource store manager for this server.     */    private void initializeResourceSpace(String server_name,					 String root_class,					 String root_name,					 String serializer,					 int max_loaded_store)     {	Hashtable defs = new Hashtable(11) ;	defs.put("url", "/");	defs.put("directory", space_dir) ;	defs.put("context", getDefaultContext()) ;	this.manager = new ResourceStoreManager(server_name,						this.getStoreDirectory(),						root_class,						root_name,						serializer,						max_loaded_store,						store_size_limit,						defs);    }    /**     * Lookup the root store for some resource.     * @param name The name of the resource to lookup in the root store.     * @return The loaded resource, or <strong>null</strong>.     */    public ResourceReference loadResource(String name) {	Hashtable defs = new Hashtable(11) ;	defs.put("url", "/"+name);	defs.put("directory", space_dir) ;	ResourceContext context = new ResourceContext(getDefaultContext());	defs.put("context", context) ;	ResourceReference rr = manager.loadRootResource(name, defs);	if (rr != null)	    context.setResourceReference(rr);	return rr;    }    /**     * start the automatic checkpoint     */    public void startCheckpoint() {	if (checkurl == null) {	    errlog("checkpointer URL unknown.");	    checkpoint();	    return;	}	try {	    LookupState   ls  = new LookupState(checkurl);	    LookupResult  lr  = new LookupResult(root.getResourceReference());	    if (root.lookup(ls,lr)) {		ResourceReference  target = lr.getTarget();		if (target != null) {		    try {			Resource res = target.lock();			if (res instanceof CheckpointResource) {			    ((CheckpointResource) res).activate();			    errlog("Chekpointer started at: "+new Date()+".");			} else {			    errlog("The chekpointer url ("+checkurl+				   ") doesn't point to a CheckpointResource");			    checkpoint();			}		    } catch (InvalidResourceException ex) {			errlog("Invalid Checkpointer : "+ex.getMessage());			checkpoint();		    } finally {			target.unlock();		    }		} else {		    errlog("can't find Checkpointer");		    checkpoint();		}	    } else {		errlog("Checkpointer: lookup fail");		checkpoint();	    }	} catch (ProtocolException ex) {	    errlog("Checkpointer : "+ex.getMessage());	    checkpoint();	}    }    /**     * Checkpoint all cached data, by saving them to disk.     */    public void checkpoint() {	manager.checkpoint();    }    /**     * Dynamically change the root resource for the server.     * This is kind a dangerous operation !     * @param name The name of the new root resource, to be found in the     * root resource store.     * @return The new installed root resource, or <strong>null</strong>     * if we couldn't load the given resource.     */    public synchronized ResourceReference loadRoot(String name) {	ResourceReference newroot = null;	String editRootName = props.getString(EDIT_ROOT_P, null);	// Restore the appropriate root resource:	Hashtable defs = new Hashtable(11) ;	defs.put("url", "/");	defs.put("directory", space_dir) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -