Skip to main content
Jump to: navigation, search

Difference between revisions of "Jetty/Reference/Jetty Architecture"

(New page: =Jetty 7 Architecture= ==View from 20,000 feet== <span class="image-wrap">Image:JettyUML1.png</span> The Jetty [http://jetty.mortbay.org/xref/org/mortbay/jetty/Server.html Server] i...)
 
Line 3: Line 3:
 
==View from 20,000 feet==
 
==View from 20,000 feet==
  
<span class="image-wrap">[[Image:JettyUML1.png]]</span>
+
[[Image:JettyUML1.png]]
  
The Jetty [http://jetty.mortbay.org/xref/org/mortbay/jetty/Server.html Server] is the plumbing between a collection of [http://jetty.mortbay.org/xref/org/mortbay/jetty/Connector.html Connector]s that accept [http://jetty.mortbay.org/xref/org/mortbay/jetty/HttpConnection.html HTTP connections], and a collection of [http://jetty.mortbay.org/xref/org/mortbay/jetty/Handler.html Handler]s that service [http://jetty.mortbay.org/xref/org/mortbay/jetty/Request.html request]s from the connections and produce [http://jetty.mortbay.org/xref/org/mortbay/jetty/Response.html response]s, with the work being done by threads taken from a [http://jetty.mortbay.org/xref/org/mortbay/thread/ThreadPool.html thread pool].
+
The Jetty [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/Server.html] is the plumbing between a collection of [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/Connector.html Connector]s that accept [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/server/HttpConnection.html HTTP connections], and a collection of [http://org.eclipse.jetty/xref/org/mortbay/jetty/Handler.html Handler]s that service [http://org.eclipse.jetty/xref/org/mortbay/jetty/Request.html request]s from the connections and produce [http://org.eclipse.jetty/xref/org/mortbay/jetty/Response.html response]s, with the work being done by threads taken from a [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/util/thread/ThreadPool.html thread pool].
  
 
<div class="panelMacro">
 
<div class="panelMacro">
Line 14: Line 14:
 
[[Image:information.gif]]
 
[[Image:information.gif]]
 
|
 
|
While the jetty request/responses are derived from the [http://jetty.mortbay.org/apidocs/javax/servlet/package-summary.html Servlet API], the full features of the servlet API are only available if the appropriate handlers are configured. For example, the session API on the request is inactive unless the request has been passed to a [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/SessionHandler.html Session Handler]. The concept of a Servlet itself is implemented by a [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/ServletHandler.html Servlet Handler]. If servlets are not required, there is very little overhead in the use of the servlet request/response APIs
+
While the jetty request/responses are derived from the [http://org.eclipse.jetty/apidocs/javax/servlet/package-summary.html Servlet API], the full features of the servlet API are only available if the appropriate handlers are configured. For example, the session API on the request is inactive unless the request has been passed to a [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/SessionHandler.html Session Handler]. The concept of a Servlet itself is implemented by a [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/ServletHandler.html Servlet Handler]. If servlets are not required, there is very little overhead in the use of the servlet request/response APIs
  
 
Thus a Jetty server may be built using simply connectors and handlers, but without using Servlets.
 
Thus a Jetty server may be built using simply connectors and handlers, but without using Servlets.
Line 23: Line 23:
 
The job of configuring jetty is the job of building a network of connectors and handlers and providing their individual configurations. As Jetty components are simply Plain Old Java Objects (POJOs) this assembly and configuration of components can be done by a variety of techniques:
 
The job of configuring jetty is the job of building a network of connectors and handlers and providing their individual configurations. As Jetty components are simply Plain Old Java Objects (POJOs) this assembly and configuration of components can be done by a variety of techniques:
  
* In code. See the examples in the [http://jetty.mortbay.org/xref/org/mortbay/jetty/example/package-summary.html org.mortbay.jetty.example] package.
+
* In code. See the examples in the [http://org.eclipse.jetty/xref/org/mortbay/jetty/example/package-summary.html org.mortbay.jetty.example] package.
 
* With [/display/JETTY/jetty.xml jetty.xml] - dependency injection style XML format.
 
* With [/display/JETTY/jetty.xml jetty.xml] - dependency injection style XML format.
* With your dependency injection framework of choice: <span class="error">[Spring]</span> or <span class="error">[XBean]</span>
+
* With your dependency injection framework of choice: [Spring] or [XBean]
 
* Deployers: [/display/JETTY/WebAppDeployer WebAppDeployer], [/display/JETTY/ContextDeployer ContextDeployer]
 
* Deployers: [/display/JETTY/WebAppDeployer WebAppDeployer], [/display/JETTY/ContextDeployer ContextDeployer]
  
 
==Patterns==
 
==Patterns==
  
<span class="image-wrap">[[Image:JettyUML2.png]]</span>
+
[[Image:JettyUML2.png]]
  
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 [http://jetty.mortbay.org/xref/org/mortbay/jetty/AbstractConnector.html AbstractConnector], [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/AbstractHandler.html AbstractHandler] and [http://jetty.mortbay.org/xref/org/mortbay/io/AbstractBuffer.html AbstractBuffer].
+
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 [http://org.eclipse.jetty/xref/org/mortbay/jetty/AbstractConnector.html AbstractConnector], [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/AbstractHandler.html AbstractHandler] and [http://org.eclipse.jetty/xref/org/mortbay/io/AbstractBuffer.html AbstractBuffer].
  
The JSR77 inspired life cycle of most jetty components is represented by [http://jetty.mortbay.org/xref/org/mortbay/component/LifeCycle.html LifeCycle] interface and the [http://jetty.mortbay.org/xref/org/mortbay/component/AbstractLifeCycle.html AbstractLifeCycle] implementation used as the base of many Jetty components.
+
The JSR77 inspired life cycle of most jetty components is represented by [http://org.eclipse.jetty/xref/org/mortbay/component/LifeCycle.html LifeCycle] interface and the [http://org.eclipse.jetty/xref/org/mortbay/component/AbstractLifeCycle.html AbstractLifeCycle] implementation used as the base of many Jetty components.
  
Jetty provides is own [http://jetty.mortbay.org/xref/org/mortbay/io/package-summary.html 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 it's advanced features.
+
Jetty provides is own [http://org.eclipse.jetty/xref/org/mortbay/io/package-summary.html 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 it's advanced features.
  
 
==Connectors==
 
==Connectors==
  
<span class="image-wrap">[[Image:JettyUML3.png]]</span>
+
[[Image:JettyUML3.png]]
  
 
<div class="panelMacro">
 
<div class="panelMacro">
Line 49: Line 49:
 
[[Image:information.gif]]
 
[[Image:information.gif]]
 
|
 
|
This diagram is a little out of date, as a [http://jetty.mortbay.org/xref/org/mortbay/io/Connection.html Connection] interface has been extracted out of HttpConnector to allow support for the [http://jetty.mortbay.org/xref/org/mortbay/jetty/ajp/package-summary.html AJP protocol]
+
This diagram is a little out of date, as a [http://org.eclipse.jetty/xref/org/mortbay/io/Connection.html Connection] interface has been extracted out of HttpConnector to allow support for the [http://org.eclipse.jetty/xref/org/mortbay/jetty/ajp/package-summary.html AJP protocol]
 
|}
 
|}
  
Line 56: Line 56:
 
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:
 
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:
  
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/bio/SocketConnector.html SocketConnector] - for few busy connections or when NIO is not available.
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/bio/SocketConnector.html SocketConnector] - for few busy connections or when NIO is not available.
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/nio/BlockingChannelConnector.html BlockingChannelConnector] - for few busy connections when NIO is available
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/nio/BlockingChannelConnector.html BlockingChannelConnector] - for few busy connections when NIO is available
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/nio/SelectChannelConnector.html SelectChannelConnector] - for many mostly idle connections or asynchronous handling of Ajax requests.
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/nio/SelectChannelConnector.html SelectChannelConnector] - for many mostly idle connections or asynchronous handling of Ajax requests.
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/security/SslSocketConnector.html SslSocketConnector] - SSL without NIO
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/security/SslSocketConnector.html SslSocketConnector] - SSL without NIO
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/security/SslSelectChannelConnector.html SslSelectChannelConnector] - SSL with non blocking NIO support.
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/security/SslSelectChannelConnector.html SslSelectChannelConnector] - SSL with non blocking NIO support.
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/ajp/Ajp13SocketConnector.html AJPConnector] AJP protocol support for connections from apache mod_jk or mod_proxy_ajp
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/ajp/Ajp13SocketConnector.html AJPConnector] AJP protocol support for connections from apache mod_jk or mod_proxy_ajp
  
 
==Handlers==
 
==Handlers==
  
<span class="image-wrap">[[Image:JettyUML4.png]]</span>
+
[[Image:JettyUML4.png]]
  
The [http://jetty.mortbay.org/xref/org/mortbay/jetty/Handler.html Handler] is the component that deals with received requests. The core API of a handler is the handle method:
+
The [http://org.eclipse.jetty/xref/org/mortbay/jetty/Handler.html Handler] is the component that deals with received requests. The core API of a handler is the handle method:
  
 
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
 
<div class="code panel" style="border-width: 1px"><div class="codeContent panelContent">
  
  <span class="code-keyword">public</span> void handle(<span class="code-object">String</span> target, HttpServletRequest request, HttpServletResponse response, <span class="code-object">int</span> dispatch)
+
  public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
     <span class="code-keyword">throws</span> IOException, ServletException;
+
     throws IOException, ServletException;
  
 
</div></div>
 
</div></div>
Line 78: Line 78:
 
An implementation of this method may handle the request, pass the request onto another handler (or servlet) or may modify and/or wrap the request and then pass it on. This gives three styles of Handler: <br class="atl-forced-newline" />
 
An implementation of this method may handle the request, pass the request onto another handler (or servlet) or may modify and/or wrap the request and then pass it on. This gives three styles of Handler: <br class="atl-forced-newline" />
  
# Coordinating Handlers - Handlers that route requests to other handlers (eg [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/HandlerCollection.html HandlerCollection], [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ContextHandlerCollection.html ContextHandlerCollection])
+
# Coordinating Handlers - Handlers that route requests to other handlers (eg [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/HandlerCollection.html HandlerCollection], [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/ContextHandlerCollection.html ContextHandlerCollection])
# Filtering Handlers - Handlers that augment a request and pass it on to other handlers (eg. [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/HandlerWrapper.html HandlerWrapper], [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler], [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/SessionHandler.html SessionHandler])
+
# Filtering Handlers - Handlers that augment a request and pass it on to other handlers (eg. [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/HandlerWrapper.html HandlerWrapper], [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler], [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/SessionHandler.html SessionHandler])
# Generating Handlers - Handlers that produce content (eg [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ResourceHandler.html ResourceHandler] and [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/ServletHandler.html ServletHandler])
+
# Generating Handlers - Handlers that produce content (eg [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/ResourceHandler.html ResourceHandler] and [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/ServletHandler.html ServletHandler])
  
 
See also [/display/JETTY/Writing+a+Jetty+Handler Writing a Jetty Handler].
 
See also [/display/JETTY/Writing+a+Jetty+Handler Writing a Jetty Handler].
Line 86: Line 86:
 
==Servlets==
 
==Servlets==
  
<span class="image-wrap">[[Image:JettyUML5.png]]</span>
+
[[Image:JettyUML5.png]]
  
The [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/ServletHandler.html ServletHandler] is a Handler that generates content by passing the request to any configured [http://jetty.mortbay.org/xref/javax/servlet/Filter.html Filter]s and then to a [http://jetty.mortbay.org/xref/javax/servlet/Servlet.html Servlet] mapped by a URI pattern.
+
The [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/ServletHandler.html ServletHandler] is a Handler that generates content by passing the request to any configured [http://org.eclipse.jetty/xref/javax/servlet/Filter.html Filter]s and then to a [http://org.eclipse.jetty/xref/javax/servlet/Servlet.html Servlet] mapped by a URI pattern.
  
A ServletHandler is normally deployed within the scope of a servlet [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/Context.html Context], which is a ContextHandler that provides convenience methods for mapping URIs to servlets.
+
A ServletHandler is normally deployed within the scope of a servlet [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/Context.html Context], which is a ContextHandler that provides convenience methods for mapping URIs to servlets.
  
Filters and Servlets may also use a [http://jetty.mortbay.org/xref/javax/servlet/RequestDispatcher.html RequestDispatcher] to reroute a request to another context or another servlet in the current context.
+
Filters and Servlets may also use a [http://org.eclipse.jetty/xref/javax/servlet/RequestDispatcher.html RequestDispatcher] to reroute a request to another context or another servlet in the current context.
  
 
==Context==
 
==Context==
Line 105: Line 105:
 
Contexts implementations include:
 
Contexts implementations include:
  
* [http://jetty.mortbay.org/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler]
+
* [http://org.eclipse.jetty/xref/org/mortbay/jetty/handler/ContextHandler.html ContextHandler]
* Servlet [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/Context.html Context]
+
* Servlet [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/Context.html Context]
* or a [http://jetty.mortbay.org/xref/org/mortbay/jetty/webapp/WebAppContext.html Web Application Context].
+
* or a [http://org.eclipse.jetty/xref/org/mortbay/jetty/webapp/WebAppContext.html Web Application Context].
  
 
A web application context combines handlers for security, session and servlets in a single unit that can be configured with a web.xml descriptor.
 
A web application context combines handlers for security, session and servlets in a single unit that can be configured with a web.xml descriptor.
Line 113: Line 113:
 
==Web Applications==
 
==Web Applications==
  
<span class="image-wrap">[[Image:JettyUML6.png]]</span>
+
[[Image:JettyUML6.png]]
  
A [http://jetty.mortbay.org/xref/org/mortbay/jetty/webapp/WebAppContext.html WebAppContext] is a derivation of the servlet [http://jetty.mortbay.org/xref/org/mortbay/jetty/servlet/Context.html Context] that supports the standardized layout of a web application and configuration of session, security, listeners, filter, servlets and JSP via a web.xml descriptor normally found in the WEB-INF directory of a webapplication.
+
A [http://org.eclipse.jetty/xref/org/mortbay/jetty/webapp/WebAppContext.html WebAppContext] is a derivation of the servlet [http://org.eclipse.jetty/xref/org/mortbay/jetty/servlet/Context.html Context] that supports the standardized layout of a web application and configuration of session, security, listeners, filter, servlets and JSP via a web.xml descriptor normally found in the WEB-INF directory of a webapplication.
  
 
Essentially the WebAppContext is a convenience class to assist the construction and configuration of other handlers to achieve a standard web application configuration.
 
Essentially the WebAppContext is a convenience class to assist the construction and configuration of other handlers to achieve a standard web application configuration.
  
Configuration is actually done by pluggable implementations of the [http://jetty.mortbay.org/xref/org/mortbay/jetty/webapp/Configuration.html Configuration] class and the prime among these is [http://jetty.mortbay.org/xref/org/mortbay/jetty/webapp/WebXmlConfiguration.html WebXmlConfiguration]
+
Configuration is actually done by pluggable implementations of the [http://org.eclipse.jetty/xref/org/mortbay/jetty/webapp/Configuration.html Configuration] class and the prime among these is [http://org.eclipse.jetty/xref/org/mortbay/jetty/webapp/WebXmlConfiguration.html WebXmlConfiguration]
  
 
</div></div></div>
 
</div></div></div>

Revision as of 15:37, 19 July 2010

Jetty 7 Architecture

View from 20,000 feet

JettyUML1.png

The Jetty [1] 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 the work being done by threads taken from a thread pool.

File:Information.gif

While the jetty request/responses are derived from the Servlet API, the full features of the servlet API are only available if the appropriate handlers are configured. 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 a Jetty server may be built using simply connectors and handlers, but without using Servlets.

The job of configuring jetty is the job of building a network of connectors and handlers and providing their individual configurations. As Jetty components are simply Plain Old Java Objects (POJOs) this assembly and configuration of components can be done by a variety of techniques:

  • In code. See the examples in the org.mortbay.jetty.example package.
  • With [/display/JETTY/jetty.xml jetty.xml] - dependency injection style XML format.
  • With your dependency injection framework of choice: [Spring] or [XBean]
  • Deployers: [/display/JETTY/WebAppDeployer WebAppDeployer], [/display/JETTY/ContextDeployer ContextDeployer]

Patterns

JettyUML2.png

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 AbstractConnector, AbstractHandler and AbstractBuffer.

The JSR77 inspired life cycle of most jetty components is represented by LifeCycle interface and the AbstractLifeCycle implementation used as the base of many Jetty components.

Jetty provides is 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 it's advanced features.

Connectors

JettyUML3.png

File:Information.gif

This diagram is a little out of date, as a Connection interface has been extracted out of HttpConnector to allow support for the AJP protocol

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:

Handlers

JettyUML4.png

The Handler is the component that deals with received requests. The core API of a handler is the handle method:

public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
    throws IOException, ServletException;

An implementation of this method may handle the request, pass the request onto another handler (or servlet) or may modify and/or wrap the request and then pass it on. This gives three styles of Handler:

  1. Coordinating Handlers - Handlers that route requests to other handlers (eg HandlerCollection, ContextHandlerCollection)
  2. Filtering Handlers - Handlers that augment a request and pass it on to other handlers (eg. HandlerWrapper, ContextHandler, SessionHandler)
  3. Generating Handlers - Handlers that produce content (eg ResourceHandler and ServletHandler)

See also [/display/JETTY/Writing+a+Jetty+Handler Writing a Jetty Handler].

Servlets

JettyUML5.png

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.

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.

Filters and Servlets may also use a RequestDispatcher to reroute a request to another context or another servlet in the current context.

Context

Contexts are handlers that group other handlers below a particular URI context path or a virtual host. Typcially a context may have :

  • A context path that defines which requests are handled by the context (eg /myapp )
  • A resource base for static content (a docroot)
  • A class loader to obtain classes specific to the context (typically docroot/WEB-INF/classes)
  • Virtual host names

Contexts implementations include:

A web application context combines handlers for security, session and servlets in a single unit that can be configured with a web.xml descriptor.

Web Applications

JettyUML6.png

A WebAppContext 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 web.xml descriptor normally found in the WEB-INF directory of a webapplication.

Essentially the WebAppContext is a convenience class to assist 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 WebXmlConfiguration

</div></div></div>

Back to the top