tags correspond to:
listener.setPort(8080);
listener.setMinThreads(5);
listener.setMaxThreads(255);
listener.setMaxIdleTimeMs(50000);
Adding a Web Application
A WebApplication is a bundled collection of resources, servlets
and configuration that can provide a unified WWW application. It
is part of the 2.2 servlet standard. The contents of the
application are configured by the web.xml deployment descriptor
within the application. The configuration of the application
within Jetty requires on the context of the application to be
set.
<Call name="addWebApplication">
<Arg>/default/*</Arg>
<Arg><SystemProperty name="user.dir"/>/webapps/default/</Arg>
</Call>
These tags correspond to:
server.addWebApplication(
"/default/*",
System.getProperty("user.dir")+"/webapps/default"
);
Adding Servlets and Other Handlers
Jetty groups Servlets and other handlers into Contexts. A
Context is a grouping of server resources that share the same URL
path prefix, class path and resource base. A Web application is
an example of a specific context. Generic contexts may have
arbitrary request handlers added to them. All contexts have a
path specification (frequently the default "*" [[??? -cp]]) and
an optional virtual host alias.
Request URL paths matching this pattern will be further matched
against the patterns for the Handlers and Servlets in the
Context. The request's path will have to match the Context's
path, and the remainder of the request path will need to match
one of the path specs of the Servlet or Handler.
The following context allows servlet classes placed in the ./servlets
directory to be dynamically loaded.
<Call name="addContext">
<Arg>/servlet/*</Arg>
<Set name="ClassPath">./servlets/</Set>
<Set name="ServingDynamicServlets">TRUE</Set>
</Call>
As Java code, this is:
context = server.addContext("/servlet/*");
context.setClassPath("./servlet/");
context.setServingDynamicServlet(true);
The second context is similar, but is set to serve resources.
<Call name="addContext">
<Arg>/*</Arg>
<Set name="ResourceBase">./docroot/</Set>
<Set name="ServingResources">TRUE</Set>
Handlers are the objects that actually service the HTTP
requests. Examples of Handlers include ServletHandler,
ResourceHandler and NotFoundHandler. Handlers are contained
within Contexts, which provide convenience methods for the common
handlers so that servlet and file serving may be concisely
configured for a context.
To this context we add the "Dump" servlet:
<Call name="addServlet">
<Arg>Dump</Arg>
<Arg>/dump/*:/handler/Dump/*</Arg>
<Arg>org.mortbay.servlet.Dump</Arg>
</Call>
In pseudo-Java, this is:
context.addServlet(
"Dump",
"/dump/*:/handler/Dump/*",
"com.mortaby.Servlet.Dump"
);
The last adds a non-Servlet Handler to the context:
<Call name="addHandler">
<Arg><New class="org.mortbay.http.handler.NotFoundHandler"/></Arg>
</Call>
As Java:
context.addHandler(new org.mortbay.http.handler.NotFoundHandler());
Return to JettyConfiguration.