|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.tomcat.startup.EmbededTomcat
Use this class to embed tomcat in your application. If all you want is to start/stop tomcat, with minimal customization, you can use Main.main() This class is designed as a java bean, where you set different properties, then call methods to perform actions. The main method is "execute", that will start tomcat. Few other methods allow to perform different other tasks. EmbededTomcat is usable as an "ant" task as well, using the TaskAdapter. ( see sample - TODO XXX ). Adding tomcat to your application: - Create a java class that will act as adapter and start tomcat ( and hold your customization code ). The class and all the files in TOMCAT_HOME/lib/common must be available in the class loader. lib/container and lib/apps should _not_ be visible, EmbededTomcat will handle that. All the application files you want visible from tomcat must be included as well. ADVANCED1. Completely separated classloader - In your adapter, create an instance of EmbededTomcat. - set properties you want to customize. - add all interceptors including your application-specific. That includes the connector modules ( shortcuts are provided for common sets of modules and for common connector configuration ). - add the root context ( required ) and any other contexts you want. More context can be added at runtime. You can also use existing configuration modules that automatically add/deploy Contexts. - call start(). Tomcat will initialize and start. The method returns when everything is ready. - You can add/remove contexts at runtime. - call stop(). Tomcat will clean up all resources and shutdown ( clean shutdown ). All common modules have been tested and shouldn't leave any garbage, however it is possible that user code will leave threads or other garbage ( i.e. not clean on destroy ). If tomcat is run in a sandbox, this shouldn't be a problem ( as untrusted servlets can't create threads ). It is your responsiblity to make sure all apps you trust or custom modules support clean shutdown. - ADVANCED2. You can throw away the classloader, and use another one if you start again. That would take care of all garbage and classes except threads and associated objects ( there is no way to handle dangling threads except killing them, assuming you can distinguish them from your own threads ). All file paths _should_ be absolute. If not, you should set "home" and make sure you include the "PathSetter" module before anything else.
Field Summary | |
protected java.lang.Object |
application
|
protected java.lang.String[] |
args
|
protected java.util.Vector |
connectors
|
protected ContextManager |
contextM
|
protected int |
dL
|
protected boolean |
initialized
|
protected java.lang.String[] |
moduleSet1
|
protected java.lang.String[] |
moduleSetAD
|
static java.lang.String |
PROPERTY_APPS_LOADER
System property used to set the application class loader, which will be the parent of all webapps. |
static java.lang.String |
PROPERTY_CONTAINER_LOADER
|
Constructor Summary | |
EmbededTomcat()
|
Method Summary | |
int |
addAjpEndpoint(int port,
java.net.InetAddress addr,
java.lang.String hostname)
Add AJP12 listener. |
void |
addApplicationAdapter(BaseInterceptor adapter)
This is an adapter object that provides callbacks into the application. |
void |
addAutoDeploy()
Add modules needed for auto-deploy function. |
Context |
addContext(java.lang.String ctxPath,
java.net.URL docRoot,
java.lang.String[] hosts)
Add and init a context. |
void |
addDefaultConnectors()
|
void |
addDefaultModules()
Add all the default modules, needed for a fully functional container. |
int |
addEndpoint(int port,
java.net.InetAddress addr,
java.lang.String hostname)
Add a HTTP listener. |
void |
addInterceptor(BaseInterceptor ri)
|
int |
addModule(BaseInterceptor ri)
|
int |
addModule(java.lang.String className)
Add a custom module. |
protected java.net.URL[] |
addModulesContainerCP(java.net.URL[] orig)
|
void |
addProperty(Property prop)
|
int |
addSecureEndpoint(int port,
java.net.InetAddress addr,
java.lang.String hostname,
java.lang.String keyFile,
java.lang.String keyPass)
Add a secure HTTP listener. |
void |
addServerXmlModules()
Init tomcat using server.xml-style configuration |
protected void |
beforeAddInterceptors()
|
void |
cleanupPrevious()
Cleanup from a previous run |
BaseInterceptor |
createModule(java.lang.String classN)
|
void |
debug(java.lang.String s)
|
void |
debug(java.lang.String s,
java.lang.Throwable t)
|
void |
execute()
Main and Ant action. |
void |
execute1()
|
int |
findModule(java.lang.String className,
int startPos)
|
protected java.net.URL[] |
findModulesCP(java.lang.String dir)
|
java.lang.Object |
getApplication()
Keep a reference to the application in which we are embeded |
java.lang.ClassLoader |
getContainerClassLoader()
|
Context |
getContext(java.lang.String host,
java.lang.String cpath)
Find the context mounted at /cpath for a virtual host. |
ContextManager |
getContextManager()
|
protected java.net.URL[] |
getModulesCommonCP()
Allow modules to add libs in the common CP. |
void |
initClassLoaders()
Initialize class loaders with the defaults, if not set |
void |
initContextManager()
|
boolean |
isInitialized()
|
static void |
main(java.lang.String[] args)
|
static void |
printUsage()
|
boolean |
processArgs(java.lang.String[] args)
|
void |
setApplication(java.lang.Object app)
Keep a reference to the application in which we are embeded |
void |
setAppsClassLoader(java.lang.ClassLoader cl)
Parent class loader for all web applications. |
void |
setArgs(java.lang.String[] args)
|
void |
setAttribute(java.lang.String name,
java.lang.Object v)
|
void |
setCommonClassLoader(java.lang.ClassLoader cl)
Class loader containing lib/common ( or equivalent ). |
void |
setCommonClassPath(java.net.URL[] cp)
Classpath used for common class loader ( probably not needed of URLClassLoader is used ). |
void |
setConfig(java.lang.String s)
|
void |
setContainerClassLoader(java.lang.ClassLoader cl)
Class loader used to load tomcat internal classes, not visible to webapps. |
void |
setDebug(int debug)
Debug for EmbededTomcat. |
void |
setEstart(boolean b)
|
void |
setF(java.lang.String s)
|
void |
setH(java.lang.String s)
|
void |
setHelp(boolean b)
|
void |
setHome(java.lang.String s)
|
void |
setI(java.lang.String s)
|
void |
setInstall(java.lang.String install)
|
void |
setJkconf(boolean b)
|
void |
setModuleProperty(int id,
java.lang.String name,
java.lang.String value)
|
void |
setParentClassLoader(java.lang.ClassLoader cl)
Parent class loader is the parent of "common" loader. |
void |
setProperty(java.lang.String name,
java.lang.String v)
|
void |
setRun(boolean b)
|
void |
setSandbox(boolean b)
Tomcat will run in a sandboxed environment, under SecurityManager |
void |
setSecurity(boolean b)
|
void |
setStart(boolean b)
|
void |
start()
|
void |
stop()
Stop contextM - will not exit the VM. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected ContextManager contextM
protected java.lang.Object application
protected java.util.Vector connectors
protected int dL
protected boolean initialized
protected java.lang.String[] args
public static final java.lang.String PROPERTY_APPS_LOADER
public static final java.lang.String PROPERTY_CONTAINER_LOADER
protected java.lang.String[] moduleSet1
protected java.lang.String[] moduleSetAD
Constructor Detail |
public EmbededTomcat()
Method Detail |
public ContextManager getContextManager()
public void setDebug(int debug)
public void setHome(java.lang.String s)
public void setInstall(java.lang.String install)
public void setConfig(java.lang.String s)
public void setSandbox(boolean b)
public void setJkconf(boolean b)
public void setStart(boolean b)
public void setEstart(boolean b)
public void setRun(boolean b)
public void setHelp(boolean b)
public void setProperty(java.lang.String name, java.lang.String v)
public void setAttribute(java.lang.String name, java.lang.Object v)
public void addProperty(Property prop)
public void setApplication(java.lang.Object app)
public java.lang.Object getApplication()
public int addModule(BaseInterceptor ri) throws TomcatException
public int addModule(java.lang.String className) throws TomcatException
public int findModule(java.lang.String className, int startPos)
public void setModuleProperty(int id, java.lang.String name, java.lang.String value) throws TomcatException
public void addServerXmlModules() throws TomcatException
public void addDefaultModules() throws TomcatException
public void addAutoDeploy() throws TomcatException
public Context addContext(java.lang.String ctxPath, java.net.URL docRoot, java.lang.String[] hosts) throws TomcatException
public Context getContext(java.lang.String host, java.lang.String cpath)
public void initContextManager() throws TomcatException
public void start() throws TomcatException
public void stop() throws TomcatException
public int addEndpoint(int port, java.net.InetAddress addr, java.lang.String hostname) throws TomcatException
public int addAjpEndpoint(int port, java.net.InetAddress addr, java.lang.String hostname) throws TomcatException
public int addSecureEndpoint(int port, java.net.InetAddress addr, java.lang.String hostname, java.lang.String keyFile, java.lang.String keyPass) throws TomcatException
public void addDefaultConnectors() throws TomcatException
public void execute() throws java.lang.Exception
public void execute1() throws java.lang.Exception
public void setArgs(java.lang.String[] args)
public boolean processArgs(java.lang.String[] args)
public static void main(java.lang.String[] args)
public void cleanupPrevious()
public void setParentClassLoader(java.lang.ClassLoader cl)
public void setCommonClassLoader(java.lang.ClassLoader cl)
public void setCommonClassPath(java.net.URL[] cp)
public void setAppsClassLoader(java.lang.ClassLoader cl)
public void setContainerClassLoader(java.lang.ClassLoader cl)
public java.lang.ClassLoader getContainerClassLoader()
public void initClassLoaders() throws java.io.IOException, java.net.MalformedURLException
protected java.net.URL[] getModulesCommonCP()
protected java.net.URL[] findModulesCP(java.lang.String dir)
protected java.net.URL[] addModulesContainerCP(java.net.URL[] orig)
public void debug(java.lang.String s)
public void debug(java.lang.String s, java.lang.Throwable t)
public BaseInterceptor createModule(java.lang.String classN)
public void setSecurity(boolean b)
public void setH(java.lang.String s)
public void setI(java.lang.String s)
public void setF(java.lang.String s)
public void addInterceptor(BaseInterceptor ri) throws TomcatException
public boolean isInitialized()
public void addApplicationAdapter(BaseInterceptor adapter) throws TomcatException
public static void printUsage()
protected void beforeAddInterceptors() throws TomcatException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |