📄 embedded.java
字号:
/*
*
* ====================================================================
*
* 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.catalina.startup;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import org.apache.catalina.Connector;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
import org.apache.catalina.Logger;
import org.apache.catalina.Realm;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.core.StandardService;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.logger.FileLogger;
import org.apache.catalina.net.ServerSocketFactory;
import org.apache.catalina.security.SecurityConfig;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.util.IntrospectionUtils;
/**
* Convenience class to embed a Catalina servlet container environment
* inside another application. You must call the methods of this class in the
* following order to ensure correct operation.
*
* <ul>
* <li>Instantiate a new instance of this class.</li>
* <li>Set the relevant properties of this object itself. In particular,
* you will want to establish the default Logger to be used, as well
* as the default Realm if you are using container-managed security.</li>
* <li>Call <code>createEngine()</code> to create an Engine object, and then
* call its property setters as desired.</li>
* <li>Call <code>createHost()</code> to create at least one virtual Host
* associated with the newly created Engine, and then call its property
* setters as desired. After you customize this Host, add it to the
* corresponding Engine with <code>engine.addChild(host)</code>.</li>
* <li>Call <code>createContext()</code> to create at least one Context
* associated with each newly created Host, and then call its property
* setters as desired. You <strong>SHOULD</strong> create a Context with
* a pathname equal to a zero-length string, which will be used to process
* all requests not mapped to some other Context. After you customize
* this Context, add it to the corresponding Host with
* <code>host.addChild(context)</code>.</li>
* <li>Call <code>addEngine()</code> to attach this Engine to the set of
* defined Engines for this object.</li>
* <li>Call <code>createConnector()</code> to create at least one TCP/IP
* connector, and then call its property setters as desired.</li>
* <li>Call <code>addConnector()</code> to attach this Connector to the set
* of defined Connectors for this object. The added Connector will use
* the most recently added Engine to process its received requests.</li>
* <li>Repeat the above series of steps as often as required (although there
* will typically be only one Engine instance created).</li>
* <li>Call <code>start()</code> to initiate normal operations of all the
* attached components.</li>
* </ul>
*
* After normal operations have begun, you can add and remove Connectors,
* Engines, Hosts, and Contexts on the fly. However, once you have removed
* a particular component, it must be thrown away -- you can create a new one
* with the same characteristics if you merely want to do a restart.
* <p>
* To initiate a normal shutdown, call the <code>stop()</code> method of
* this object.
* <p>
* <strong>IMPLEMENTATION NOTE</strong>: The <code>main()</code> method of
* this class is a simple example that exercizes the features of dynamically
* starting and stopping various components. You can execute this by executing
* the following steps (on a Unix platform):
* <pre>
* cd $CATALINA_HOME
* ./bin/catalina.sh embedded
* </pre>
*
* @author Craig R. McClanahan
* @version $Revision: 1.12 $ $Date: 2004/01/26 19:48:01 $
*/
public class Embedded extends StandardService implements Lifecycle {
private static Log log = LogFactory.getLog(Embedded.class);
// ----------------------------------------------------------- Constructors
/**
* Construct a new instance of this class with default properties.
*/
public Embedded() {
this(null, null);
}
/**
* Construct a new instance of this class with specified properties.
*
* @param logger Logger implementation to be inherited by all components
* (unless overridden further down the container hierarchy)
* @param realm Realm implementation to be inherited by all components
* (unless overridden further down the container hierarchy)
*/
public Embedded(Logger logger, Realm realm) {
super();
setLogger(logger);
setRealm(realm);
setSecurityProtection();
}
// ----------------------------------------------------- Instance Variables
/**
* The set of Connectors that have been deployed in this server.
*/
protected Connector connectors[] = new Connector[0];
/**
* The debugging detail level for this component.
*/
protected int debug = 0;
/**
* Is naming enabled ?
*/
protected boolean useNaming = true;
/**
* The set of Engines that have been deployed in this server. Normally
* there will only be one.
*/
protected Engine engines[] = new Engine[0];
/**
* Descriptive information about this server implementation.
*/
protected static final String info =
"org.apache.catalina.startup.Embedded/1.0";
/**
* The lifecycle event support for this component.
*/
protected LifecycleSupport lifecycle = new LifecycleSupport(this);
/**
* The default logger to be used by this component itself. Unless this
* is overridden, log messages will be writted to standard output.
*/
protected Logger logger = null;
/**
* The default realm to be used by all containers associated with
* this compoennt.
*/
protected Realm realm = null;
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
/**
* The socket factory that will be used when a <code>secure</code>
* Connector is created. If a standard Connector is created, the
* internal (to the Connector class default socket factory class)
* will be used instead.
*/
protected String socketFactory =
"org.apache.catalina.net.SSLSocketFactory";
/**
* Has this component been started yet?
*/
protected boolean started = false;
/**
* Use await.
*/
protected boolean await = false;
/**
* The property change support for this component.
*/
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
// ------------------------------------------------------------- Properties
/**
* Return the debugging detail level for this component.
*/
public int getDebug() {
return (this.debug);
}
/**
* Set the debugging detail level for this component.
*
* @param debug The new debugging detail level
*/
public void setDebug(int debug) {
int oldDebug = this.debug;
this.debug = debug;
support.firePropertyChange("debug", new Integer(oldDebug),
new Integer(this.debug));
}
/**
* Return true if naming is enabled.
*/
public boolean isUseNaming() {
return (this.useNaming);
}
/**
* Enables or disables naming support.
*
* @param useNaming The new use naming value
*/
public void setUseNaming(boolean useNaming) {
boolean oldUseNaming = this.useNaming;
this.useNaming = useNaming;
support.firePropertyChange("useNaming", new Boolean(oldUseNaming),
new Boolean(this.useNaming));
}
/**
* Return the Logger for this component.
*/
public Logger getLogger() {
return (this.logger);
}
/**
* Set the Logger for this component.
*
* @param logger The new logger
*/
public void setLogger(Logger logger) {
Logger oldLogger = this.logger;
this.logger = logger;
support.firePropertyChange("logger", oldLogger, this.logger);
}
/**
* Return the default Realm for our Containers.
*/
public Realm getRealm() {
return (this.realm);
}
/**
* Set the default Realm for our Containers.
*
* @param realm The new default realm
*/
public void setRealm(Realm realm) {
Realm oldRealm = this.realm;
this.realm = realm;
support.firePropertyChange("realm", oldRealm, this.realm);
}
/**
* Return the secure socket factory class name.
*/
public String getSocketFactory() {
return (this.socketFactory);
}
/**
* Set the secure socket factory class name.
*
* @param socketFactory The new secure socket factory class name
*/
public void setSocketFactory(String socketFactory) {
this.socketFactory = socketFactory;
}
public void setAwait(boolean b) {
await = b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -