org.mortbay.jetty

Class Server

Implemented Interfaces:
EventProvider, LifeCycle, Serializable
Known Direct Subclasses:
Server

public class Server
extends HttpServer

The Jetty HttpServer. This specialization of org.mortbay.http.HttpServer adds knowledge about servlets and their specialized contexts. It also included support for initialization from xml configuration files that follow the XmlConfiguration dtd. HttpContexts created by Server are of the type org.mortbay.jetty.servlet.ServletHttpContext unless otherwise specified. This class also provides a main() method which starts a server for each config file passed on the command line. If the system property JETTY_NO_SHUTDOWN_HOOK is not set to true, then a shutdown hook is thread is registered to stop these servers.
Version:
$Revision: 1.40 $
Author:
Greg Wilkins (gregw)
See Also:
XmlConfiguration, ServletHttpContext

Constructor Summary

Server()
Constructor.
Server(String configuration)
Constructor.
Server(URL configuration)
Constructor.
Server(Resource configuration)
Constructor.

Method Summary

WebApplicationContext
addWebApplication(String contextPathSpec, String webApp)
Add Web Application.
WebApplicationContext
addWebApplication(String virtualHost, String contextPathSpec, String webApp)
Add Web Application.
WebApplicationContext[]
addWebApplications(String webapps)
Add Web Applications.
WebApplicationContext[]
addWebApplications(String host, String webapps)
Add Web Applications.
WebApplicationContext[]
addWebApplications(String host, String webapps, String defaults, boolean extract)
Add Web Applications.
WebApplicationContext[]
addWebApplications(String host, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader)
Add Web Applications.
WebApplicationContext[]
addWebApplications(String host, String webapps, boolean extract)
Add Web Applications.
void
configure(String configuration)
Configure the server from an XML file.
String
getConfiguration()
String
getRootWebApp()
Get the root webapp name.
boolean
getStopAtShutdown()
String[]
getWebApplicationConfigurationClassNames()
static void
main(String[] arg)
Construct server from command line arguments.
protected HttpContext
newHttpContext()
Create a new ServletHttpContext.
protected WebApplicationContext
newWebApplicationContext(String webApp)
Create a new WebApplicationContext.
void
setRootWebApp(String rootWebApp)
Set the root webapp name.
void
setStopAtShutdown(boolean stop)
void
setWebApplicationConfigurationClassNames(String[] configurationClassNames)
setWebApplicationConfigurationClasses Set up the list of classnames of WebApplicationContext.Configuration implementations that will be applied to configure every webapp.

Methods inherited from class org.mortbay.http.HttpServer

addContext, addContext, addContext, addContext, addHostAlias, addListener, addListener, addListener, addRealm, destroy, doStart, doStop, findHandler, getConnections, getConnectionsDurationAve, getConnectionsDurationMax, getConnectionsDurationMin, getConnectionsDurationTotal, getConnectionsOpen, getConnectionsOpenMax, getConnectionsOpenMin, getConnectionsRequestsAve, getConnectionsRequestsMax, getConnectionsRequestsMin, getContext, getContext, getContext, getContexts, getErrors, getHostMap, getHttpServerList, getHttpServers, getListeners, getRealm, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getRequestsActiveMin, getRequestsDurationAve, getRequestsDurationMax, getRequestsDurationMin, getRequestsDurationTotal, getRequestsPerGC, getResolveRemoteHost, getServerClasses, getStatsOn, getStatsOnMs, getStopGracefully, getSystemClasses, getTrace, join, main, newHttpContext, removeContext, removeListener, removeRealm, save, service, setAnonymous, setContexts, setListeners, setRequestLog, setRequestsPerGC, setResolveRemoteHost, setServerClasses, setStatsOn, setStopGracefully, setSystemClasses, setTrace, statsReset, stop

Methods inherited from class org.mortbay.util.Container

addComponent, addEventListener, destroy, doStart, doStop, getComponents, isStarted, isStarting, isStopping, removeComponent, removeEventListener, start, stop

Constructor Details

Server

public Server()
Constructor.

Server

public Server(String configuration)
            throws IOException
Constructor.
Parameters:
configuration - The filename or URL of the XML configuration file.

Server

public Server(URL configuration)
            throws IOException
Constructor.
Parameters:
configuration - The filename or URL of the XML configuration file.

Server

public Server(Resource configuration)
            throws IOException
Constructor.
Parameters:
configuration - The filename or URL of the XML configuration file.

Method Details

addWebApplication

public WebApplicationContext addWebApplication(String contextPathSpec,
                                               String webApp)
            throws IOException
Add Web Application.
Parameters:
contextPathSpec - The context path spec. Which must be of the form / or /path/*
webApp - The Web application directory or WAR file.
Returns:
The WebApplicationContext

addWebApplication

public WebApplicationContext addWebApplication(String virtualHost,
                                               String contextPathSpec,
                                               String webApp)
            throws IOException
Add Web Application.
Parameters:
virtualHost - Virtual host name or null
contextPathSpec - The context path spec. Which must be of the form / or /path/*
webApp - The Web application directory or WAR file.
Returns:
The WebApplicationContext

addWebApplications

public WebApplicationContext[] addWebApplications(String webapps)
            throws IOException
Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If a webapp is called "root" it is added at "/".
Parameters:
webapps - Directory file name or URL to look for auto webapplication.

addWebApplications

public WebApplicationContext[] addWebApplications(String host,
                                                  String webapps)
            throws IOException
Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.
Parameters:
host - Virtual host name or null
webapps - Directory file name or URL to look for auto webapplication.

addWebApplications

public WebApplicationContext[] addWebApplications(String host,
                                                  String webapps,
                                                  String defaults,
                                                  boolean extract)
            throws IOException
Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.
Parameters:
host - Virtual host name or null
webapps - Directory file name or URL to look for auto webapplication.
defaults - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
extract - If true, extract war files

addWebApplications

public WebApplicationContext[] addWebApplications(String host,
                                                  String webapps,
                                                  String defaults,
                                                  boolean extract,
                                                  boolean java2CompliantClassLoader)
            throws IOException
Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.
Parameters:
host - Virtual host name or null
webapps - Directory file name or URL to look for auto webapplication.
defaults - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
extract - If true, extract war files
java2CompliantClassLoader - True if java2 compliance is applied to all webapplications

addWebApplications

public WebApplicationContext[] addWebApplications(String host,
                                                  String webapps,
                                                  boolean extract)
            throws IOException
Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.
Parameters:
host - Virtual host name or null
webapps - Directory file name or URL to look for auto webapplication.
extract - If true, extract war files

configure

public void configure(String configuration)
            throws IOException
Configure the server from an XML file.
Parameters:
configuration - The filename or URL of the XML configuration file.

getConfiguration

public String getConfiguration()

getRootWebApp

public String getRootWebApp()
Get the root webapp name.
Returns:
The name of the root webapp (eg. "root" for root.war).

getStopAtShutdown

public boolean getStopAtShutdown()

getWebApplicationConfigurationClassNames

public String[] getWebApplicationConfigurationClassNames()

main

public static void main(String[] arg)
Construct server from command line arguments.
Overrides:
main in interface HttpServer
Parameters:

newHttpContext

protected HttpContext newHttpContext()
Create a new ServletHttpContext. Ths method is called by HttpServer to creat new contexts. Thus calls to addContext or getContext that result in a new Context being created will return an org.mortbay.jetty.servlet.ServletHttpContext instance.
Overrides:
newHttpContext in interface HttpServer
Returns:
ServletHttpContext

newWebApplicationContext

protected WebApplicationContext newWebApplicationContext(String webApp)
Create a new WebApplicationContext. Ths method is called by Server to creat new contexts for web applications. Thus calls to addWebApplication that result in a new Context being created will return an correct class instance. Derived class can override this method to create instance of its own class derived from WebApplicationContext in case it needs more functionality.
Parameters:
webApp - The Web application directory or WAR file.
Returns:
WebApplicationContext

setRootWebApp

public void setRootWebApp(String rootWebApp)
Set the root webapp name.
Parameters:
rootWebApp - The name of the root webapp (eg. "root" for root.war).

setStopAtShutdown

public void setStopAtShutdown(boolean stop)

setWebApplicationConfigurationClassNames

public void setWebApplicationConfigurationClassNames(String[] configurationClassNames)
setWebApplicationConfigurationClasses Set up the list of classnames of WebApplicationContext.Configuration implementations that will be applied to configure every webapp. The list can be overridden by individual WebApplicationContexts.
Parameters:

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.