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

📄 jkmain.java

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, if *    any, must include the following acknowlegement: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowlegement may appear in the software itself, *    if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software *    Foundation" must not be used to endorse or promote products derived *    from this software without prior written permission. For written *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" *    nor may "Apache" appear in their names without prior written *    permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */package org.apache.jk.server;import java.io.*;import java.net.*;import java.util.*;import org.apache.jk.core.*;import org.apache.jk.common.*;import org.apache.tomcat.util.buf.*;import org.apache.tomcat.util.http.*;import org.apache.tomcat.util.IntrospectionUtils;/** Main class used to startup and configure jk. It manages the conf/jk2.properties file *  and is the target of JMX proxy. * *  It implements a policy of save-on-change - whenever a property is changed at *  runtime the jk2.properties file will be overriden.  * *  You can edit the config file when tomcat is stoped ( or if you don't use JMX or *  other admin tools ). * *  The format of jk2.properties: *  <dl> *   <dt>TYPE[.LOCALNAME].PROPERTY_NAME=VALUE *   <dd>Set a property on the associated component. TYPE will be used to *   find the class name and instantiate the component. LOCALNAME allows *   multiple instances. In JMX mode, TYPE and LOCALNAME will form the *   JMX name ( eventually combined with a 'jk2' component ) * *   <dt>NAME=VALUE *   <dd>Define global properties to be used in ${} substitutions * *   <dt>class.COMPONENT_TYPE=JAVA_CLASS_NAME *   <dd>Adds a new 'type' of component. We predefine all known types. * </dl> * * Instances are created the first time a component name is found. In addition, * 'handler.list' property will override the list of 'default' components that are * loaded automatically. * *  Note that the properties file is just one (simplistic) way to configure jk. We hope *  to see configs based on registry, LDAP, db, etc. ( XML is not necesarily better ) *  * @author Costin Manolache */public class JkMain{    WorkerEnv wEnv=new WorkerEnv();    String propFile;    Properties props=new Properties();    Properties modules=new Properties();    boolean modified=false;    boolean started=false;    boolean saveProperties=false;        public JkMain()    {        JkMain.jkMain=this;        modules.put("channelSocket", "org.apache.jk.common.ChannelSocket");        modules.put("channelUnix", "org.apache.jk.common.ChannelUn");        modules.put("channelJni", "org.apache.jk.common.ChannelJni");        modules.put("apr", "org.apache.jk.apr.AprImpl");        modules.put("mx", "org.apache.jk.common.JkMX");        modules.put("shm", "org.apache.jk.common.Shm");        modules.put("request","org.apache.jk.common.HandlerRequest");        modules.put("container","org.apache.jk.common.HandlerRequest");        initHTTPSUrls();    }    public static JkMain getJkMain() {        return jkMain;    }    private static String DEFAULT_HTTPS="com.sun.net.ssl.internal.www.protocol";    private void initHTTPSUrls() {        try {            // 11657: if only ajp is used, https: redirects need to work ( at least for 1.3+)            String value = System.getProperty("java.protocol.handler.pkgs");            if (value == null) {                value = DEFAULT_HTTPS;            } else if (value.indexOf(DEFAULT_HTTPS) >= 0  ) {                return; // already set            } else {                value += "|" + DEFAULT_HTTPS;            }            System.setProperty("java.protocol.handler.pkgs", value);        } catch(Exception ex ) {            ex.printStackTrace();        }    }        // -------------------- Setting --------------------        /** Load a .properties file into and set the values     *  into jk2 configuration.     */    public void setPropertiesFile( String p  ) {        propFile=p;        try {            props.load( new FileInputStream(propFile) );        } catch(IOException ex ){            ex.printStackTrace();        }    }    public String getPropertiesFile() {        return propFile;    }    public void setSaveProperties( boolean b ) {        saveProperties=b;    }    /** Set a name/value as a jk2 property     */    public void setProperty( String n, String v ) {        if( "jkHome".equals( n ) ) {            setJkHome( v );        }         props.put( n, v );        if( started ) {            processProperty( n, v );            saveProperties();        }    }    /**     * Set the <code>channelClassName</code> that will used to connect to     * httpd.     */    public void setChannelClassName(String name) {        props.put( "handler.channel.className",name);    }    public String getChannelClassName() {        return (String)props.get( "handler.channel.className");    }    /**     * Set the <code>workerClassName</code> that will handle the request.     * ( sort of 'pivot' in axis :-)     */    public void setWorkerClassName(String name) {        props.put( "handler.container.className",name);    }    public String getWorkerClassName() {        return (String)props.get( "handler.container.className");    }    /** Set the base dir of jk2. ( including WEB-INF if in a webapp ).     *  We'll try to guess it from classpath if none is set ( for     *  example on command line ), but if in a servlet environment     *  you need to use Context.getRealPath or a system property or     *  set it expliciltey.     */    public void setJkHome( String s ) {        wEnv.setJkHome(s);    }    public String getJkHome() {        return wEnv.getJkHome();    }        String out;    String err;    File propsF;        public void setOut( String s ) {        this.out=s;    }    public String getOut() {        return this.out;    }    public void setErr( String s ) {        this.err=s;    }        public String getErr() {        return this.err;    }        // -------------------- Initialization --------------------        public void init() throws IOException    {        long t1=System.currentTimeMillis();        if(null != out) {            PrintStream outS=new PrintStream(new FileOutputStream(out));            System.setOut(outS);//             if( stderr==null ) //                 System.setErr(out);        }        if(null != err) {            PrintStream errS=new PrintStream(new FileOutputStream(err));            System.setErr(errS);        }        String home=wEnv.getJkHome();        if( home==null ) {            // XXX use IntrospectionUtil to find myself            this.guessHome();        }        home=wEnv.getJkHome();        if( home != null ) {            File hF=new File(home);            File conf=new File( home, "conf" );            if( ! conf.exists() )                conf=new File( home, "etc" );            propsF=new File( conf, "jk2.properties" );                        if( propsF.exists() ) {                log.debug("Starting Jk2, base dir= " + home + " conf=" + propsF );                setPropertiesFile( propsF.getAbsolutePath());            } else {                log.debug("Starting Jk2, base dir= " + home );                if( log.isWarnEnabled() )                    log.warn( "No properties file found " + propsF );            }        }        long t2=System.currentTimeMillis();        initTime=t2-t1;    }        static String defaultHandlers[]= { "request",                                       "container",                                       "channelSocket"};    /*     static String defaultHandlers[]= { "apr",                                       "shm",                                       "request",                                       "container",                                       "channelSocket",                                       "channelJni",                                       "channelUnix"};    */        public void stop()     {        for( int i=0; i<wEnv.getHandlerCount(); i++ ) {            if( wEnv.getHandler(i) != null ) {                try {                    wEnv.getHandler(i).destroy();

⌨️ 快捷键说明

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