📄 httpd.java
字号:
ResourceContext context = null; if ((editRootName != null) && (! name.equals(editRootName))) { if (editroot == null) { Hashtable edefs = new Hashtable(11) ; edefs.put("url", "/"); edefs.put("directory", space_dir) ; ResourceContext econtext = new ResourceContext(getDefaultContext()); edefs.put("context", econtext) ; editroot = manager.loadRootResource(editRootName, edefs); if (editroot != null) econtext.setResourceReference(editroot); } context = new ResourceContext(editroot); } else { context = new ResourceContext(getDefaultContext()); } defs.put("context", context) ; ResourceReference rr = manager.loadRootResource(name, defs); if (rr != null) context.setResourceReference(rr); return rr; } private synchronized FramedResource changeRoot(String name) { ResourceReference newroot = loadRoot(name); FramedResource oldroot = this.root; String oldroot_name = this.root_name; if ( newroot != null ) { try { this.root = (FramedResource)newroot.lock(); this.root_name = name; if (root_reference != null) root_reference.unlock(); root_reference = newroot; return root; } catch (InvalidResourceException ex) { this.root = oldroot; this.root_name = oldroot_name; return null; } } return null; } /** * Initialize this server's root resource. * @exception ServerHandlerInitException if unable to be initialized. */ private void initializeRootResource() throws ServerHandlerInitException { // Check for un-found root resource: if ( changeRoot(root_name) == null ) { String err = ("Unable to restore root resource ["+root_name+"]" +" from store (not found)."); throw new ServerHandlerInitException(err); } } /** * Initialize the realms catalog for this server. */ private void initializeRealmsCatalog() { this.realms = new RealmsCatalog(new ResourceContext(getDefaultContext())); } /** * Initialize the server logger and the statistics object. * @exception ServerHandlerInitException if unable to be initialized. */ private void initializeLogger() throws ServerHandlerInitException { if ( logger_class != null ) { try { logger = (Logger) Class.forName(logger_class).newInstance() ; logger.initialize (this) ; } catch (Exception ex) { String err = ("Unable to create logger of class ["+ logger_class +"]"+ "\r\ndetails: \r\n"+ ex.getMessage()); throw new ServerHandlerInitException(err); } } else { warning (getBanner() + ": no logger specified, not logging."); } // Initialize the statistics object: statistics = new httpdStatistics(this) ; } /** * Initialize the server socket, create a suitable client factory, start. * This method creates the physicall listening socket, and instantiate * an appropriate client factory for that socket. It then run the accept * thread, ready to accept new incomming connections. * @exception ServerHandlerInitException if unable to be initialized. */ private void initializeServerSocket() throws ServerHandlerInitException { // Create a suitable client factory: try { Class c = Class.forName(factory_class); factory = (ClientFactory) c.newInstance(); factory.initialize(this); } catch (Exception ex) { String err = ("Unable to create a client factory of class "+ "\"" + factory_class + "\""+ " details: \r\n" + ex.getMessage()); throw new ServerHandlerInitException(err); } // If needed, create a server socket instance for that context: try { socket = factory.createServerSocket(); } catch (IOException ex) { String err = ("Unable to create server socket on port "+port + ": " + ex.getMessage() + "."); throw new ServerHandlerInitException(err); } this.thread = new Thread (this) ; this.thread.setName(identifier) ; this.thread.setPriority (Thread.MAX_PRIORITY) ; } protected MimeParserFactory getMimeClientFactory(Client client) { return new MimeClientFactory(client); } /** * Initialize our event manager. */ private void initializeEventManager() { this.timer = new EventManager () ; this.timer.setDaemon(true); this.timer.start() ; } /** * startup classes */ protected void loadStartupClasses() { String classes[] = props.getStringArray(STARTUP_P, null); if (classes != null) { for (int i = 0 ; i < classes.length ; i++) { try { Class c = Class.forName(classes[i]); httpdPreloadInterface hpi = (httpdPreloadInterface)c.newInstance(); hpi.preload(this); } catch (ClassNotFoundException cnfex) { errlog("Startup class not found : "+cnfex.getMessage()); } catch (InstantiationException iex) { errlog("Unable to instanciate : "+iex.getMessage()); } catch (ClassCastException ccex) { errlog("Startup classes must be instance of "+ "httpdPreloadInterface: "+ccex.getMessage()); } catch (IllegalAccessException iaex) { errlog("IllegalAccess "+iaex.getMessage()); } } } } /** * FIXME protected for now to handle clones * Initialize some of the servers instance values from properties. * @exception ServerHandlerInitException if unable to be initialized. */ protected void initializeProperties() throws ServerHandlerInitException { // Compute some default values (host and port) String defhost = null ; String rootstr = null ; String spacestr = null ; boolean ip_host = props.getBoolean(DEFHOSTIP_P, false); try { if (ip_host) defhost = InetAddress.getLocalHost().getHostAddress() ; else defhost = InetAddress.getLocalHost().getHostName() ; } catch (UnknownHostException e) { defhost = null; } // Second stage: get property values: software = props.getString(SERVER_SOFTWARE_P, software); tracep = props.getBoolean(TRACE_P,tracep) ; uri_error = props.getBoolean(DISPLAY_URL_ON_ERROR_P, false); lenient = props.getBoolean(LENIENT_P, true); keep = props.getBoolean(KEEP_ALIVE_P,keep) ; logger_class = props.getString(LOGGER_P, null) ; factory_class = props.getString(CLIENT_FACTORY_P,factory_class); shuffler_path = props.getString(SHUFFLER_PATH_P, null) ; rootstr = props.getString(ROOT_P, null) ; spacestr = props.getString(SPACE_P, null); host = props.getString(HOST_P, defhost) ; port = props.getInteger(PORT_P, port) ; root_name = props.getString(ROOT_NAME_P, "root") ; root_class = props.getString(ROOT_CLASS_P, null); max_loaded_store = props.getInteger(MAX_LOADED_STORE_P, MAX_LOADED_STORE); store_size_limit = props.getInteger(STORE_SIZE_LIMIT_P, STORE_SIZE_LIMIT); sensitivity = props.getBoolean(FS_SENSITIVITY, true); publicMethods = props.getStringArray(PUBLIC_P, publicMethods); // Get client properties: client_debug = props.getBoolean (CLIENT_DEBUG_P, client_debug) ; request_time_out = props.getInteger (REQUEST_TIMEOUT_P , request_time_out); connection_time_out = props.getInteger (KEEP_TIMEOUT_P , connection_time_out); client_priority = props.getInteger(CLIENT_PRIORITY_P , client_priority); client_bufsize = props.getInteger(CLIENT_BUFSIZE_P , client_bufsize); // Check that a host name has been given: if ( host == null ) throw new ServerHandlerInitException(this.getClass().getName() +"[initializeProperties]: " +"[host] undefined."); // Default the root directory to the current directory: if ( rootstr == null ) { // Try the current directory as root: rootstr = System.getProperties().getProperty("user.dir", null) ; if ( rootstr == null ) throw new ServerHandlerInitException(this.getClass().getName() +"[initializeProperties]:" +"[root] undefined."); } root_dir = new File(rootstr) ; // Default the space directory to root/WWW if ( spacestr == null ) space_dir = new File(root_dir, "WWW") ; else space_dir = new File(spacestr) ; // Help URL: String propval = props.getString(DOCURL_P, null); if ( propval != null ) { try { URL u = new URL(getURL(), propval); docurl = u.toExternalForm(); } catch (Exception ex) { } } // Trash Dir trashdir = props.getString(TRASHDIR_P, trashdir); // checpointer url checkurl = props.getString(CHECKURL_P, checkurl); } /** * Register a property set to the server. * @param propSet The property set to register. */ public synchronized void registerPropertySet(PropertySet set) { // Add this set to our known property set: propSet.addElement(set); } /** * Enumerate all the registered property sets * @return an enumeration of </code>PropertySet</code> */ public Enumeration enumeratePropertySet() { return propSet.elements(); } /** * Get a property set matching a specific name * @return a Resource, the property set found */ public Resource getPropertySet(String name) { for (int i = 0 ; i < propSet.size() ; i++) { PropertySet set = (PropertySet) propSet.elementAt(i); if ( set.getIdentifier().equals(name) ) return set; } return null; } protected void initializePropertySets() { registerPropertySet(new GeneralProp("general", this)); registerPropertySet(new ConnectionProp("connection", this)); registerPropertySet(new LoggingProp("logging", this)); } /** * Get this server statistics. */ public httpdStatistics getStatistics() { return statistics ; } /** * Get this server properties. */ public ObservableProperties getProperties() { return props ; } /** * Is the underlying file-system case sensitive ? * @return A boolean, <strong>true</strong> if file system is case * sensitive, <strong>false</strong> otherwise. */ public boolean checkFileSystemSensitivity() { return sensitivity; } /** * Get the full URL of Jigsaw's documentation. * @return A String encoded URL. */ public String getDocumentationURL() { return docurl; } /** * Get the tracsh directory */ public String getTrashDirectory() { return trashdir; } /** * Get the client's debug flags from the properties. */ public final boolean getClientDebug() { return client_debug ; } /** * Does this server wants clients to try keeping connections alive ? */ public final boolean getClientKeepConnection() { return keep ; } /** * Get the request allowed time slice from the properties. */ public final int getRequestTimeOut() { return request_time_out ; } /** * Get the connection allowed idle time from the properties. */ public final int getConnectionTimeOut() { return connection_time_out ; } /** * Get the client's threads priority from the properties. */ public final int getClientThreadPriority() { return client_priority ; } /** * Get the client's buffer size. */ public final int getClientBufferSize() { return client_bufsize ; } /** * Get this server host name. */ public String getHost () { return host ; } /** * Get this server port number. */ public int getPort () { return port ; } /** * Get the server current root resource. */ public FramedResource getRoot() { return root ; } /** * get the resource reference of the root resource of the server */ public ResourceReference getRootReference() { return root_reference; } /** * Get the logger for that server. * @return A Logger compatible instance, or <strong>null</strong> if * no logger specified. */ public Logger getLogger() { return logger; } /** * Get the server's edit root resource. * The edit root is the one that shows up by default when using JigAdmin * It is named "root" in the interface. * @return An HTTPResource. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -