blob: 9a80aae02225597ee9df17147404f96cab7af7f8 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;32.&nbsp;Architecture</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty : The Definitive Reference"><link rel="up" href="reference.html" title="Part&nbsp;V.&nbsp;Reference Guide"><link rel="prev" href="ubuntu.html" title="Ubuntu"><link rel="next" href="jetty-classloading.html" title="Jetty Classloading"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><script type="text/javascript" src="js/shCore.js"></script><script type="text/javascript" src="js/shBrushJava.js"></script><script type="text/javascript" src="js/shBrushXml.js"></script><script type="text/javascript" src="js/shBrushBash.js"></script><script type="text/javascript" src="js/shBrushJScript.js"></script><script type="text/javascript" src="js/shBrushSql.js"></script><script type="text/javascript" src="js/shBrushProperties.js"></script><script type="text/javascript" src="js/shBrushPlain.js"></script><link type="text/css" rel="stylesheet" href="css/shCore.css"><link type="text/css" rel="stylesheet" href="css/shThemeEclipse.css"><link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"><style xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/css">
body {
background-image: url('images/draft-ribbon.png');
background-repeat: no-repeat;
background-position: top left;
}
</style></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.3.0.v20150612</span></td><td style="width: 50%"><script type="text/javascript"> (function() {
var cx = '016459005284625897022:obd4lsai2ds';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script><gcse:search></gcse:search></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;32.&nbsp;Architecture</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ubuntu.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;V.&nbsp;Reference Guide<br><a accesskey="p" href="index.html"><i class="icon-home"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jetty-classloading.html">Next <i class="icon-chevron-right"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
</p></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="draft"><h5>DRAFT</h5><p>
This page contains content that we have migrated from Jetty 7 or Jetty 8 documentation into the correct format, but we have not yet audited it for technical accuracy in Jetty 9. Be aware that examples or information contained on this page may be incorrect. Please check back soon as we continue improving the documentation, or submit corrections yourself to this page through <a href="http://github.com/jetty-project/jetty-documentation" style="text-decoration:none"><i class="icon-github"></i> Github</a>. Thank you.
</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="architecture"></a>Chapter&nbsp;32.&nbsp;Architecture</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="architecture.html#basic-architecture">Jetty Architecture</a></span></dt><dt><span class="section"><a href="jetty-classloading.html">Jetty Classloading</a></span></dt><dt><span class="section"><a href="1xx-responses.html">Managing 1xx Responses</a></span></dt><dt><span class="section"><a href="creating-custom-protocol.html">Creating a Custom Protocol</a></span></dt></dl></div><p>General items related to the architecture of jetty and how it deals with certain design decisions.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="basic-architecture"></a>Jetty Architecture</h2></div></div></div><div class="toc"><dl><dt><span class="section"><a href="architecture.html#d0e22453">View from 20,000 feet</a></span></dt><dt><span class="section"><a href="architecture.html#d0e22492">Patterns</a></span></dt><dt><span class="section"><a href="architecture.html#d0e22523">Connectors</a></span></dt><dt><span class="section"><a href="architecture.html#d0e22571">Handlers</a></span></dt><dt><span class="section"><a href="architecture.html#what-is-a-context">Contexts</a></span></dt><dt><span class="section"><a href="architecture.html#d0e22684">Web Application</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e22453"></a>View from 20,000 feet</h3></div></div></div><p>The Jetty <a class="link" href="http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/Server.html" target="_top">Server</a>
is the plumbing between a collection of Connectors that accept HTTP
connections and a collection of Handlers that service requests from the
connections and produce responses, with threads from a thread pool doing
the work.</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/jetty-high-level-architecture.png" align="middle" width="540"></td></tr></table></div><p>While the Jetty request/responses are derived from the Servlet API,
the full features of the Servlet API are only available if you configure
the appropriate handlers. For example, the session API on the request is
inactive unless the request has been passed to a Session Handler. The
concept of a servlet itself is implemented by a Servlet Handler. If
servlets are not required, there is very little overhead in the use of the
servlet request/response APIs. Thus you can build a Jetty server using
only connectors and handlers, without using servlets.</p><p>The job of configuring Jetty is building a network of connectors and
handlers and providing their individual configurations. As Jetty
components are simply Plain Old Java Objects (POJOs), you can accomplish
this assembly and configuration of components by a variety of
techniques:</p><p>deeper <a class="xref" href="">???</a></p><p>deepest <a class="link" href="">this is custom</a></p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>In code. See the examples in the Jetty 7 Latest Source
XRef.</p></li><li class="listitem"><p>Using Jetty XML&#8211;dependency injection style XML format.</p></li><li class="listitem"><p>With your dependency injection framework of choice: Spring or
XBean.</p></li><li class="listitem"><p>Using Jetty WebApp and Context Deployers.</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e22492"></a>Patterns</h3></div></div></div><p>The implementation of Jetty follows some fairly standard patterns.
Most abstract concepts such as Connector, Handler and Buffer are captured
by interfaces. Generic handling for those interfaces is then provided in
an Abstract implementation such as <code class="code">AbstractConnector</code>,
<code class="code">AbstractHandler</code> and <code class="code"> AbstractBuffer</code>.</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-patterns.png" align="middle" width="540"></td></tr></table></div><p>The JSR77 inspired life cycle of most Jetty components is
represented by the <code class="code">LifeCycle</code> interface and the
<code class="code">AbstractLifeCycle</code> implementation used as the base of many
Jetty components.</p><p>Jetty provides its own IO Buffering abstract over String, byte
arrays and NIO buffers. This allows for greater portability of Jetty as
well as hiding some of the complexity of the NIO layer and its advanced
features.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e22523"></a>Connectors</h3></div></div></div><p>This diagram is a little out of date, as a Connection interface has
been extracted out of <code class="code"> HttpConnector</code> to allow support for the
AJP protocol.</p><p>The connectors represent the protocol handlers that accept
connections, parse requests and generate responses. The different types of
connectors available are based on the protocols, scheduling model, and IO
APIs used:</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-connectors.png" align="middle" width="540"></td></tr></table></div><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><code class="code">SocketConnector</code> &#8211;for few busy connections or when
NIO is not available</p></li><li class="listitem"><p><code class="code">BlockingChannelConnector</code> &#8211;for few busy connections
when NIO is available</p></li><li class="listitem"><p><code class="code">SelectChannelConnector</code> &#8211;for many mostly idle
connections or asynchronous handling of Ajax requests</p></li><li class="listitem"><p><code class="code">SslSocketConnector</code> &#8211;SSL without NIO</p></li><li class="listitem"><p><code class="code">SslSelectChannelConnector</code> &#8211;SSL with non blocking
NIO support</p></li><li class="listitem"><p><code class="code">AJPConnector</code> &#8211;AJP protocol support for connections
from apache mod_jk or mod_proxy_ajp</p></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e22571"></a>Handlers</h3></div></div></div><p>The Handler is the component that deals with received requests. The
core API of a handler is the handle method:</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-handlers.png" align="middle" width="540"></td></tr></table></div><div class="informalexample"><script type="syntaxhighlighter" class="brush: java;toolbar: false">
<![CDATA[
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
]]>
</script></div><p>Parameters:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>target&#8211;The target of the request, either a URI or a name.</p></li><li class="listitem"><p>baseRequest&#8211;The original unwrapped request object.</p></li><li class="listitem"><p>request&#8211;The request either as the Request object or a wrapper of
that request. You can use the HttpConnection.getCurrentConnection()
method to access the Request object if required.</p></li><li class="listitem"><p>response&#8211;The response as the Response object or a wrapper of
that request. You can use the HttpConnection.getCurrentConnection()
method to access the Response object if required.</p></li></ul></div><p>An implementation of this method can handle the request, pass the
request onto another handler (or servlet) or it might modify and/or wrap
the request and then pass it on. This gives three styles of
Handler:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Coordinating Handlers&#8211;Handlers that route requests to other
handlers (HandlerCollection, ContextHandlerCollection)</p></li><li class="listitem"><p>Filtering Handlers&#8211;Handlers that augment a request and pass it
on to other handlers (HandlerWrapper, ContextHandler,
SessionHandler)</p></li><li class="listitem"><p>Generating Handlers&#8211;Handlers that produce content
(ResourceHandler and ServletHandler)</p></li></ul></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="d0e22613"></a>Nested Handlers and Handlers Called Sequentially</h4></div></div></div><p>You can combine handlers to handle different aspects of a request
by nesting them, calling them in sequence, or by combining the two
models.</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-nested-handlers.png" align="middle" width="540"></td></tr></table></div><p>Handlers called in sequence perform actions that do not depend on
the next invocation, nor on the handler order. They handle a request and
generate the response without interacting with other handlers. The main
class for this model is Handler Collection.</p><p>Nested handlers are called according to a before/invokeNext/after
pattern. The main class for nested handlers is Handler Wrapper. Nested
handlers are much more common than those called in sequence.</p><p>See also <a class="xref" href="jetty-handlers.html#writing-custom-handlers" title="Writing Custom Handlers">Writing Custom Handlers</a>.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="d0e22633"></a>Servlet Handler</h4></div></div></div><p>The ServletHandler is a Handler that generates content by passing
the request to any configured filters and then to a Servlet mapped by a
URI pattern.</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-servlet-handler.png" align="middle" width="540"></td></tr></table></div><p>A ServletHandler is normally deployed within the scope of a
servlet Context, which is a ContextHandler that provides convenience
methods for mapping URIs to servlets.</p><p>Filters and Servlets can also use a RequestDispatcher to reroute a
request to another context or another servlet in the current
context.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="what-is-a-context"></a>Contexts</h3></div></div></div><p>Contexts are handlers that group other handlers below a particular
URI context path or a virtual host. Typcially a context can have :</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>A context path that defines which requests are handled by the
context (eg /myapp )</p></li><li class="listitem"><p>A resource base for static content (a docroot)</p></li><li class="listitem"><p>A class loader to obtain classes specific to the context
(typically docroot/WEB-INF/classes)</p></li><li class="listitem"><p>Virtual host names</p></li></ul></div><p>Contexts implementations include:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>ContextHandler</p></li><li class="listitem"><p>Servlet Context</p></li><li class="listitem"><p>Web Application Context</p></li></ul></div><p>A web application context combines handlers for security, session
and servlets in a single unit that you can configure with a
<code class="filename">web.xml</code> descriptor.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="d0e22684"></a>Web Application</h3></div></div></div><p>A WebApp Context is a derivation of the servlet Context that
supports the standardized layout of a web application and configuration of
session, security, listeners, filter, servlets, and JSP via a <code class="filename">
web.xml</code> descriptor normally found in the
<code class="filename">WEB-INF</code> directory of a webapplication.</p><div class="mediaobject" align="center"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="540"><tr><td align="center"><img src="images/basic-architecture-web-application.png" align="middle" width="540"></td></tr></table></div><p>Essentially the WebAppContext is a convenience class that assists
the construction and configuration of other handlers to achieve a standard
web application configuration. Configuration is actually done by pluggable
implementations of the Configuration class and the prime among these is
<code class="code">WebXmlConfiguration.</code></p></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ubuntu.html"><i class="icon-chevron-left"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="reference.html"><i class="icon-chevron-up"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jetty-classloading.html">Next <i class="icon-chevron-right"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Ubuntu&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="icon-home"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Jetty Classloading</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/jetty-project/jetty-documentation">Contribute to this documentation at
<span class="website"><i class="icon-github"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2015-06-15T13:18:55-05:00)</i></span></div></p><script xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1149868-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></html>