org.apache.airavata.server
Class BetterTomcat

java.lang.Object
  extended by org.apache.airavata.server.BetterTomcat

public class BetterTomcat
extends Object

This is an improvement to Embedded Tomcat. The objective is to provide a cleaner API for embedders.


Nested Class Summary
static class BetterTomcat.Protocol
          The valid protocol types
 
Constructor Summary
BetterTomcat()
           
BetterTomcat(int port)
           
 
Method Summary
 org.apache.catalina.connector.Connector addConnector(BetterTomcat.Protocol protocol, String address, int port)
          Get a Tomcat Connector.
 org.apache.catalina.connector.Connector addConnector(int port)
           
 org.apache.catalina.Context addContext(org.apache.catalina.Host host, String contextPath, String dir)
           
 org.apache.catalina.Context addContext(String contextPath, String baseDir)
          Add a context - programmatic mode, no web.xml used.
 org.apache.catalina.Wrapper addServlet(String contextPath, String servletName, javax.servlet.Servlet servlet)
          Add an existing Servlet to the context with no class.forName or initialisation.
 org.apache.catalina.Wrapper addServlet(String contextPath, String servletName, String servletClass)
          Equivalent with .
 org.apache.catalina.Context addWebapp(org.apache.catalina.Host host, String contextPath, String webappFilePath)
          Add a webapp to a particular Host
 org.apache.catalina.Context addWebapp(String contextPath, String webappFilePath)
          Add a webapp using normal WEB-INF/web.xml if found.
 void enableNaming()
          Enables JNDI naming which is disabled by default.
 org.apache.catalina.connector.Connector getConnector(BetterTomcat.Protocol protocol, String address, int port)
           
 org.apache.catalina.Host getHost()
           
 org.apache.catalina.startup.Tomcat getTomcat()
          Returns the wrapped Tomcat instance.
 void setBaseDir(String baseDir)
           
 void setClientAuth(org.apache.catalina.connector.Connector connector, String clientAuth)
           
 void setDefaultHost(String defaultHostName)
           
 void setDefaultRealm(org.apache.catalina.Realm realm)
           
 void setUnpackWars(boolean unpackWars)
          Indicates whether WAR files should be unpacked 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
 

Constructor Detail

BetterTomcat

public BetterTomcat()

BetterTomcat

public BetterTomcat(int port)
Method Detail

setUnpackWars

public void setUnpackWars(boolean unpackWars)
Indicates whether WAR files should be unpacked or not

Parameters:
unpackWars - true - unpackWars

start

public void start()
           throws org.apache.catalina.LifecycleException
Start the server.

Throws:
org.apache.catalina.LifecycleException - If an irrecoverable error occurs while starting

stop

public void stop()
          throws org.apache.catalina.LifecycleException
Stop the server.

Throws:
org.apache.catalina.LifecycleException - If an irrecoverable error occurs while stopping

getHost

public org.apache.catalina.Host getHost()

addWebapp

public org.apache.catalina.Context addWebapp(String contextPath,
                                             String webappFilePath)
                                      throws BetterTomcatException
Add a webapp using normal WEB-INF/web.xml if found.

Parameters:
contextPath - The context of the webapp, e.g., /foo
webappFilePath - The file path of the webapp. Can be the path to a WAR file or a directory, e.g., 1. /home/azeez/bettertomcat/foo.war 2. /home/azeez/bettertomcat/foo
Returns:
new Context The Context of the deployed webapp
Throws:
BetterTomcatException - If webapp deployment fails

addWebapp

public org.apache.catalina.Context addWebapp(org.apache.catalina.Host host,
                                             String contextPath,
                                             String webappFilePath)
Add a webapp to a particular Host

Parameters:
host - The Host to which this webapp is added to
contextPath - The context of the webapp, e.g., /foo
webappFilePath - The file path of the webapp. Can be the path to a WAR file or a directory, e.g., 1. /home/azeez/bettertomcat/foo.war 2. /home/azeez/bettertomcat/foo
Returns:
new Context The Context of the deployed webapp

addContext

public org.apache.catalina.Context addContext(String contextPath,
                                              String baseDir)
Add a context - programmatic mode, no web.xml used.

API calls equivalent with web.xml:

context-param ctx.addParameter("name", "value");

error-page ErrorPage ep = new ErrorPage(); ep.setErrorCode(500); ep.setLocation("/error.html"); ctx.addErrorPage(ep);

ctx.addMimeMapping("ext", "type");

Note: If you reload the Context, all your configuration will be lost. If you need reload support, consider using a LifecycleListener to provide your configuration.

Parameters:
contextPath - The context of the webapp. "" for root context.
baseDir - base dir for the context, for static files. Must exist, relative to the server home
Returns:
new Context The Context of the deployed webapp

addContext

public org.apache.catalina.Context addContext(org.apache.catalina.Host host,
                                              String contextPath,
                                              String dir)

addServlet

public org.apache.catalina.Wrapper addServlet(String contextPath,
                                              String servletName,
                                              String servletClass)
Equivalent with .

In general it is better/faster to use the method that takes a Servlet as param - this one can be used if the servlet is not commonly used, and want to avoid loading all deps. ( for example: jsp servlet )

You can customize the returned servlet, ex:

wrapper.addInitParameter("name", "value");

Parameters:
contextPath - Context to add Servlet to
servletName - Servlet name (used in mappings)
servletClass - The class to be used for the Servlet
Returns:
The wrapper for the servlet

addServlet

public org.apache.catalina.Wrapper addServlet(String contextPath,
                                              String servletName,
                                              javax.servlet.Servlet servlet)
Add an existing Servlet to the context with no class.forName or initialisation.

Parameters:
contextPath - Context to add Servlet to
servletName - Servlet name (used in mappings)
servlet - The Servlet to add
Returns:
The wrapper for the servlet

enableNaming

public void enableNaming()
Enables JNDI naming which is disabled by default. Server must implement Lifecycle in order for the NamingContextListener to be used.


addConnector

public org.apache.catalina.connector.Connector addConnector(int port)

addConnector

public org.apache.catalina.connector.Connector addConnector(BetterTomcat.Protocol protocol,
                                                            String address,
                                                            int port)
Get a Tomcat Connector. If a connector with the Tomcat connector does not exist, create a new one.

Parameters:
protocol - The protocol of the connector.
address - The IP address of the network interface to which this connector should bind to. Specify this as null if the connector should bind to all network interfaces.
port - The port on which this connector has to be run
Returns:
The Tomcat connector

setClientAuth

public void setClientAuth(org.apache.catalina.connector.Connector connector,
                          String clientAuth)

getConnector

public org.apache.catalina.connector.Connector getConnector(BetterTomcat.Protocol protocol,
                                                            String address,
                                                            int port)

setBaseDir

public void setBaseDir(String baseDir)

setDefaultHost

public void setDefaultHost(String defaultHostName)

setDefaultRealm

public void setDefaultRealm(org.apache.catalina.Realm realm)

getTomcat

public org.apache.catalina.startup.Tomcat getTomcat()
Returns the wrapped Tomcat instance. This should be used only when advanced functionality is required

Returns:
The Tomcat instance which can be used by advanced users who wish to gain more control


Copyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.