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

📄 httpd.java

📁 很棒的web服务器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// httpd.java// $Id: httpd.java,v 1.138 2004/02/18 12:24:35 ylafon Exp $// (c) COPYRIGHT MIT and INRIA, 1996.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.jigsaw.http ;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.PrintStream;import java.util.Date;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import java.net.InetAddress;import java.net.MalformedURLException;import java.net.ServerSocket;import java.net.Socket;import java.net.URL;import java.net.UnknownHostException;import org.w3c.tools.resources.AbstractContainer;import org.w3c.tools.resources.DummyResourceReference;import org.w3c.tools.resources.FilterInterface;import org.w3c.tools.resources.FramedResource;import org.w3c.tools.resources.InvalidResourceException;import org.w3c.tools.resources.LookupResult;import org.w3c.tools.resources.LookupState;import org.w3c.tools.resources.ProtocolException;import org.w3c.tools.resources.ReplyInterface;import org.w3c.tools.resources.RequestInterface;import org.w3c.tools.resources.Resource;import org.w3c.tools.resources.ResourceContext;import org.w3c.tools.resources.ResourceException;import org.w3c.tools.resources.ResourceFilter;import org.w3c.tools.resources.ResourceReference;import org.w3c.tools.resources.ResourceSpace;import org.w3c.tools.resources.ServerInterface;import org.w3c.tools.resources.store.ResourceStoreManager;import org.w3c.tools.resources.indexer.IndexerModule;import org.w3c.tools.resources.indexer.IndexersCatalog;import org.w3c.tools.resources.indexer.ResourceIndexer;import org.w3c.tools.timers.EventManager;import org.w3c.jigsaw.auth.RealmsCatalog;import org.w3c.jigsaw.resources.CheckpointResource;import org.w3c.jigsaw.daemon.ServerHandler;import org.w3c.jigsaw.daemon.ServerHandlerInitException;import org.w3c.jigsaw.daemon.ServerHandlerManager;import org.w3c.www.http.HTTP;import org.w3c.www.http.HeaderValue;import org.w3c.www.http.HttpEntityMessage;import org.w3c.www.http.HttpFactory;import org.w3c.www.http.HttpMessage;import org.w3c.www.http.HttpReplyMessage;import org.w3c.www.http.HttpRequestMessage;import org.w3c.www.http.HttpTokenList;import org.w3c.jigsaw.config.PropertySet;import org.w3c.util.IO;import org.w3c.util.ObservableProperties;import org.w3c.util.PropertyMonitoring;import org.w3c.util.Status;import org.w3c.tools.resources.ProtocolException;import org.w3c.tools.resources.upgrade.Upgrader;import org.w3c.www.mime.MimeParserFactory;import org.w3c.www.mime.MimeType;/** * <p>The server main class. This class can be used either through its * main method, to run a full httpd server, or simply by importing it * into your app. This latter possibility allows you to export some of * your application state through http. * * <p>The server itself uses this to report about memory consumption, * running threads, etc. */public class httpd implements       ServerInterface, Runnable, PropertyMonitoring, Cloneable, Status{    /**     * The current displayed version of Jigsaw.     */    public static final String version = "2.2.4";    /**     * The current internal version counter of Jigsaw.     * This counter is bumped anytime the configuration needs upgrade.     */    public static final int verscount = 4;    /**     * debug flag     */    public static final boolean debug = true;    public static final    String VERSCOUNT_P = "org.w3c.jigsaw.version.counter";    /**     * Name of the server software property.     * The server software is the string that gets emited by Jigsaw      * on each reply, to tell the client what server emited the reply.     * <p>This property defaults to <strong>Jigsaw/1.0a</strong>.     */    public static final     String SERVER_SOFTWARE_P = "org.w3c.jigsaw.server";    /**     * If the Host property is not set (see below), you can select if you     * want to use FQDN (broken on some jdk implementation) or just the IP     * address as the default host name, it usually defaults to "false"     * means, use FQDN.     */    public static final String DEFHOSTIP_P = "org.w3c.jigsaw.defhostip" ;    /**     * Name of the server host property.     * The host property should be set to the name of the host running     * this server.     * <p>This property defaults to the local host name, although if you want     * directory listing to work propertly, you might need to provide the      * full host name (including its domain).     */    public static final String HOST_P            = "org.w3c.jigsaw.host" ;    /**     * Name of the property giving the server root directory.     * <p>The server root directory is used to deduce a bunch of defaults     * properties, when they don't have any specific values.     * <p>This property has no defaults.     */    public static final String ROOT_P = "org.w3c.jigsaw.root" ;    /**     * Name of the property giving the server's config directory.     */    public static final String CONFIG_P = "org.w3c.jigsaw.config";    /**     * Name of the property giving the server space directory.     * The server space directory should contain an index file, built     * with the indexer.     * <p>This property defaults to <org.w3c.jigsaw.root>/WWW.     */    public static final String SPACE_P            = "org.w3c.jigsaw.space" ;    /**     * Name of the server port property.     * At initializatiojn time, the server will bind its accepting socket     * to the host its runs on, and to the provided port.     * <p>This property defaults to <code>8888</code>.     */    public static final String PORT_P            = "org.w3c.jigsaw.port" ;    /**     * Name of the server's trace property.     * When set to true, the server will emit some traces indicating      * its current state by using the logger <em>trace</em> methods.     * This property should be set to <string>true</strong> if you want     * clients to emit traces.     * <p>This property defaults to <strong>false</strong>.     */    public static final String TRACE_P           = "org.w3c.jigsaw.trace" ;    /**     * Name of the server's keep alive flag.     * This property is used to determine wether this server should keep     * its connection alive. Keeping connection alive requires this flag     * to set to <strong>true</strong>, and clients to be compliant to the     * keep alive feature as described in HTTP/1.1 specification.     * <p>This property defaults to <strong>true</strong>.     */    public static final String KEEP_ALIVE_P      = "org.w3c.jigsaw.keepAlive" ;    /**     * Name of the server's connection time out property.     * This property gives, in milliseconds, the timeout to use for     * connections that remains idel, waiting for an incoming request.     * <p>This property defaults to <code>10000</code> milliseconds.     */    public static final String KEEP_TIMEOUT_P=                                           "org.w3c.jigsaw.keep_alive.timeout";    /**     * Name of the server's request time out property.     * The request time out property value indicates, in milliseconds, the     * allowed duration of a request. Any request whose duration exceeds     * this time out value will be aborted.     * <p>This property defaults to <code>60000</code>.     */    public static final String REQUEST_TIMEOUT_P=                                              "org.w3c.jigsaw.request.timeout";    /**     * Name of the client thread priority property.     * Every client threads will run at the given priority, which should be     * in the range of valid threads priority.     * <p>This property defaults to <code>Thread.NORM_PRIORITY</code>.     */    public static final String CLIENT_PRIORITY_P=                                              "org.w3c.jigsaw.client.priority";    /**     * Nam eof the property giving the client output buffer size.     * Each clients, when not using a shuffler, has to allocate its own     * output buffer, Output buffer size may increase/decrease significantly     * the Jigsaw performances, so change it with care.     * <p>This property defaults to <code>8192</code>.     */    public static final String CLIENT_BUFSIZE_P=                                               "org.w3c.jigsaw.client.bufsize";    /**   * Name of the property indicating wether client should be debuged.   * When debuged, clients emit some traces, through the server logger   * about their current state.   * <p>This property defaults to <strong>false</strong>.   */    public static final String CLIENT_DEBUG_P="org.w3c.jigsaw.client.debug" ;    /**     * Name of  property that indicates if some security manager is required.     * You usually don't want to run a security manager for the server,      * except in the unlikely (right now) case that you want the server to     * be able to host agents.     * <p>This property defaults to <string>false</strong>.     */    public static final String USE_SM_P = "org.w3c.http.useSecurityManager" ;    /**     * Name of property indicating the logger class to use.     * The Jigsaw server allows you to implement your own logger. The only     * logger provided with the core server is the      * <code>org.w3c.jigsaw.core.CommonLogger</code>, which implements the     * common log format.     * <p>Property defaults to <code>org.w3c.jigsaw.core.CommonLogger</code>     */    public static final String LOGGER_P = "org.w3c.jigsaw.logger" ;    /**     * Name of property indicating the "lenient" mode of HTTP parsing.     * <p>Property defaults to <code>true</code>     */    public static final String LENIENT_P = "org.w3c.jigsaw.http.lenient" ;    /**     * Name of the property indicating the client factory class.     */    public static final String CLIENT_FACTORY_P = 	"org.w3c.jigsaw.http.ClientFactory";    /**     * Name of the property giving the shuffler path.     * This property should be set if you are to use the shuffler. The      * data shuffler is an external process to whiuch Jigsaw delegates      * the task of writing back document content to clients. Use this     * when you think your server isn't fast enough.     * <p>This should be an absloute path.     * <p>This property has no defaults.     */    public static final String SHUFFLER_PATH_P="org.w3c.jigsaw.shuffler.path";    /**     * Name of the property giving the name of the root resource.     * Upon startup, or restart, the server will look in its root store     * a resource whose name is given by this resource, and install it as     * its root resource.     * <p>This property defaults to <code>root</code>.     */    public static final String ROOT_NAME_P = "org.w3c.jigsaw.root.name" ;    public static final String ROOT_CLASS_P = "org.w3c.jigsaw.root.class" ;    /**     * Max number of store loaded in memory.     */     public static final String MAX_LOADED_STORE_P="org.w3c.jigsaw.loadedstore";    public static final int MAX_LOADED_STORE = 128;    int max_loaded_store = -1;    /**     * Max number of store loaded in memory.     */     public static final String STORE_SIZE_LIMIT_P="org.w3c.jigsaw.storesize";    public static final int STORE_SIZE_LIMIT = -1;    int store_size_limit = -1;        /**     * Name of the property giving the path of the property file.     * this should be used internally (for restart) only.     * <p>This property defaults to <code>config/httpd.props</code>.     */    public static final String PROPS_P = "org.w3c.jigsaw.propfile" ;    /**     * Name of the property indicating if the file-system is case sensitive.     * This property determines wether Jigsaw will list all files to check      * for case sensitivity, before creating a resource for that file.     * <p>For obvious security reasons, this property defaults to      * <strong>true</strong>.     */    public static final     String FS_SENSITIVITY = "org.w3c.jigsaw.checkSensitivity";    /**     * Name of the property indicating the URL of Jigsaw's help.     * This URL should point to the URL path of Jigsaw's documentation     * as served by that server.     */    public static String DOCURL_P = "org.w3c.jigsaw.docurl";    /**     * Name of the property indicating the startup classes to load     */    public static String STARTUP_P = "org.w3c.jigsaw.startup";    /**     * Name of the property indicating the trash directory.     */    public static String TRASHDIR_P = "org.w3c.jigsaw.trashdir";    /**     * Name of the property indicating the URL of Jigsaw's chekpointer.     */    public static     String CHECKURL_P = "org.w3c.jigsaw.checkpointer";    /**     * Name of the property indicating the public methods allowed on that      * server.     * This property should provide a <code>|</code> separated list of     * methods available on that server.     * <p>This property defaults to: <strong>GET | HEAD | PUT | POST      * | OPTIONS | DELETE | LINK | UNLINK | TRACE</code>.     */    public static     String PUBLIC_P = "org.w3c.jigsaw.publicMethods";    /**     * Name of the property that indicates the root resource for edit.     * The edit root resource is the one that will show up by default     * when accessing the admin server from JigAdmin.     */    public static     String EDIT_ROOT_P = "org.w3c.jigsaw.edit.root";    /**     * Name of the serializer class used to store resources.     */    public static String SERIALIZER_CLASS_P = "org.w3c.jigsaw.serializer";    /**     * UNIX - Name of the property that indicates the server user.     * When set, the server will try to turn itself to the given user name     * after initialization. If this fail, the server will abort.     * <p>This property has no default value.     */    public static    String SERVER_USER_P = "org.w3c.jigsaw.unix.user";    /**     * UNIX - Name of the property that indicates the server group.     * When set, the server will try to turn itself to the given group name     * after initialization. If this fail, the server will abort.     * <p>This property has no default value.     */    public static    String SERVER_GROUP_P = "org.w3c.jigsaw.unix.group";    /**     * Should we show the URL that triggered an error in the error message     * or not?     * Displaying it can lead to so-called "cross-scripting" hacks     */    public static    String DISPLAY_URL_ON_ERROR_P = "org.w3c.jigsaw.error.url";       /**     * The list of currently running servers.     */    private static Hashtable servers = new Hashtable() ;    /* FIXME */ public Thread thread    = null ;    private String         software  = "Jigsaw/2.2.4";    private ServerSocket   socket    = null ;    private Logger         logger    = null ;    private Shuffler       shuffler  = null ;    public  EventManager   timer     = null ;    ClientFactory          factory   = null ;    // FIXME This is a temporary hack to take care of clones    protected int[] instances = {1};    // object containing the nb of clones    /**     * The (optional) server handler manager that created us.     */    private ServerHandlerManager shm = null;    /**     * The server identifier can be any String.     * This identifier is used by the configuration applets, to show all the      * running servers in the process, and to edit their properties, etc.     */    private String identifier = null ;    /**     * This server statistics object.     */    private httpdStatistics statistics = null ;    /**     * This server set of properties.     */    protected ObservableProperties props    = null ;    /**      * Should the server run the server in trace mode ?     */    private boolean tracep = false ;    /**     * Should the server try to keep connections alive ?     */    private boolean keep = true ;     /**     * What logger class should the server use to log accesses.     */    private String logger_class = null ;    /**     * Should we display URL on error?     */    private boolean uri_error = false;

⌨️ 快捷键说明

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