|
Apache Tomcat 7.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.catalina.startup.Tomcat
public class Tomcat
Minimal tomcat starter for embedding/unit tests. Tomcat supports multiple styles of configuration and startup - the most common and stable is server.xml-based, implemented in org.apache.catalina.startup.Bootstrap. This class is for use in apps that embed tomcat. Requirements: - all tomcat classes and possibly servlets are in the classpath. ( for example all is in one big jar, or in eclipse CP, or in any other combination ) - we need one temporary directory for work files - no config file is required. This class provides methods to use if you have a webapp with a web.xml file, but it is optional - you can use your own servlets. This class provides a main() and few simple CLI arguments, see setters for doc. It can be used for simple tests and demo.
Nested Class Summary | |
---|---|
static class |
Tomcat.DefaultWebXmlListener
Fix reload - required if reloading and using programmatic configuration. |
static class |
Tomcat.ExistingStandardWrapper
Helper class for wrapping existing servlets. |
static class |
Tomcat.FixContextListener
Fix startup sequence - required if you don't use web.xml. |
Field Summary | |
---|---|
protected String |
basedir
|
protected Connector |
connector
|
protected Realm |
defaultRealm
|
protected Engine |
engine
|
protected Host |
host
|
protected String |
hostname
|
protected int |
port
|
protected Server |
server
|
protected Service |
service
|
Constructor Summary | |
---|---|
Tomcat()
|
Method Summary | |
---|---|
Context |
addContext(Host host,
String contextPath,
String dir)
|
Context |
addContext(String contextPath,
String baseDir)
Add a context - programmatic mode, no web.xml used. |
void |
addRole(String user,
String role)
|
static Wrapper |
addServlet(Context ctx,
String servletName,
Servlet servlet)
Static version of addServlet(String, String, Servlet) . |
static Wrapper |
addServlet(Context ctx,
String servletName,
String servletClass)
Static version of addServlet(String, String, String) |
Wrapper |
addServlet(String contextPath,
String servletName,
Servlet servlet)
Add an existing Servlet to the context with no class.forName or initialisation. |
Wrapper |
addServlet(String contextPath,
String servletName,
String servletClass)
Equivalent with |
void |
addUser(String user,
String pass)
Add a user for the in-memory realm. |
Context |
addWebapp(Host host,
String url,
String path)
|
Context |
addWebapp(String contextPath,
String baseDir)
Add a webapp using normal WEB-INF/web.xml if found. |
void |
destroy()
Destroy the server. |
void |
enableNaming()
Enables JNDI naming which is disabled by default. |
Connector |
getConnector()
Get the default http connector. |
Engine |
getEngine()
Access to the engine, for further customization. |
Host |
getHost()
|
Server |
getServer()
Get the server object. |
Service |
getService()
Get the service object. |
void |
init()
Initialise the server. |
protected void |
initBaseDir()
|
protected void |
initSimpleAuth()
Initialize an in-memory realm. |
static void |
initWebappDefaults(Context ctx)
Static version of initWebappDefaults(String) |
void |
initWebappDefaults(String contextPath)
Provide default configuration for a context. |
void |
setBaseDir(String basedir)
Tomcat needs a directory for temp files. |
void |
setConnector(Connector connector)
|
void |
setDefaultRealm(Realm realm)
Set a custom realm for auth. |
void |
setHost(Host host)
Sets the current host - all future webapps will be added to this host. |
void |
setHostname(String s)
The the hostname of the default host, default is 'localhost'. |
void |
setPort(int port)
Set the port for the default connector. |
void |
setSilent(boolean silent)
Controls if the loggers will be silenced or not. |
void |
start()
Start the server. |
void |
stop()
Stop the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Server server
protected Service service
protected Engine engine
protected Connector connector
protected Host host
protected int port
protected String hostname
protected String basedir
protected Realm defaultRealm
Constructor Detail |
---|
public Tomcat()
Method Detail |
---|
public void setBaseDir(String basedir)
public void setPort(int port)
public void setHostname(String s)
public Context addWebapp(String contextPath, String baseDir) throws ServletException
contextPath
- baseDir
-
ServletException
public Context addContext(String contextPath, String baseDir)
contextPath
- "" for root context.baseDir
- base dir for the context, for static files. Must exist,
relative to the server homepublic Wrapper addServlet(String contextPath, String servletName, String servletClass)
contextPath
- Context to add Servlet toservletName
- Servlet name (used in mappings)servletClass
- The class to be used for the Servlet
public static Wrapper addServlet(Context ctx, String servletName, String servletClass)
addServlet(String, String, String)
ctx
- Context to add Servlet toservletName
- Servlet name (used in mappings)servletClass
- The class to be used for the Servlet
public Wrapper addServlet(String contextPath, String servletName, Servlet servlet)
contextPath
- Context to add Servlet toservletName
- Servlet name (used in mappings)servlet
- The Servlet to add
public static Wrapper addServlet(Context ctx, String servletName, Servlet servlet)
addServlet(String, String, Servlet)
.
ctx
- Context to add Servlet toservletName
- Servlet name (used in mappings)servlet
- The Servlet to add
public void init() throws LifecycleException
LifecycleException
public void start() throws LifecycleException
LifecycleException
public void stop() throws LifecycleException
LifecycleException
public void destroy() throws LifecycleException
LifecycleException
public void addUser(String user, String pass)
public void addRole(String user, String role)
addUser(String, String)
public Connector getConnector()
public void setConnector(Connector connector)
public Service getService()
public void setHost(Host host)
host
- public Host getHost()
public void setDefaultRealm(Realm realm)
public Engine getEngine()
public Server getServer()
public Context addContext(Host host, String contextPath, String dir)
public Context addWebapp(Host host, String url, String path)
protected void initSimpleAuth()
protected void initBaseDir()
public void setSilent(boolean silent)
silent
- true
sets the log level to WARN for the
loggers that log information on Tomcat start up. This
prevents the usual startup information being logged.
false
sets the log level to the default
level of INFO.public void enableNaming()
Lifecycle
in order for the NamingContextListener
to be
used.
public void initWebappDefaults(String contextPath)
contextPath
- The context to set the defaults forpublic static void initWebappDefaults(Context ctx)
initWebappDefaults(String)
ctx
- The context to set the defaults for
|
Apache Tomcat 7.0.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |