incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling Website > Dispatching Requests
Date Tue, 01 Sep 2009 20:54:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/SLINGxSITE/Dispatching+Requests">Dispatching
Requests</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~mykee">Mike
Mueller</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h1><a name="DispatchingRequests-RequestProcessing"></a>Request
Processing</h1>

<h2><a name="DispatchingRequests-Mainprocess"></a>Main process</h2>

<p>The following steps should give you an overview how a request is processed in Sling.
Details can be found under provided links.</p>

<h3><a name="DispatchingRequests-Step1"></a>Step 1</h3>

<p>The client sends the request</p>

<h3><a name="DispatchingRequests-Step2"></a>Step 2</h3>

<p>This step applies only if a Servlet Container is installed and Sling is embedded:<br/>
Servlet Container gets request and forwards to OSGi HttpService</p>

<h3><a name="DispatchingRequests-Step3"></a>Step 3</h3>

<p>OSGi HttpService looks for responsible registered Servlet or resource (see 102.4
of the OSGi compendium)</p>

<h3><a name="DispatchingRequests-Step4"></a>Step 4</h3>

<p>OSGi HttpService calls <tt>handleSecurity</tt> of the HttpContext associated
with the servlet/resource. In case of Sling this calls into SlingMainServlet.handleSecurity
and then into SlingAuthenticator.authenticate</p>

<h3><a name="DispatchingRequests-Step4a"></a>Step 4a</h3>

<p>SlingAuthenticator selects an authentication handler for the request and forwards
the authenticate call. On success a <tt>javax.jcr.Session</tt> is created, the
request attributes required by the HTTP Service spec are set (like <tt>org.osgi.service.http.authentication.remote.user</tt>
and <tt>org.osgi.service.http.authentication.type}}and also the {{javax.jcr.Session</tt>
which is used later is set in the request attributes.<br/>
On success, continue with step 5.</p>

<h3><a name="DispatchingRequests-Step4b"></a>Step 4b</h3>

<p>If authentication fails either an anonymous session is acquired (if anonymous is
allowed per configuration) or the login method is called.<br/>
If anonymous is allowed, continue with step 5.</p>

<h3><a name="DispatchingRequests-Step4c"></a>Step 4c</h3>

<p>The login method selects an AuthenticationHandler and forwards the login call to
the AuthenticationHandler.requestAuthentication method to cause the client to authenticate.
Request processing stops here (<tt>SlingMainServlet.handleSecurity</tt> returns
false).</p>

<h3><a name="DispatchingRequests-Step5"></a>Step 5</h3>

<p>After getting a response the HttpService either terminates the request (if authentication
failed and <tt>SlingMainServlet.handleSecurity</tt> returned false) or continues
by either spooling the resource or in the case of Sling calling the <tt>SlingMainServlet.service</tt>
method.</p>

<h3><a name="DispatchingRequests-Step6"></a>Step 6</h3>

<p>The <tt>SlingMainServlet.service</tt> method is the entry point into
the Sling proper. This method sets up the request:</p>
<ul>
	<li>Wraps the <tt>HttpServletRequest</tt> and the <tt>HttpServletResponse</tt>
into the <tt>SlingHttpServletRequest</tt> and the <tt>SlingHttpServletResponse</tt></li>
	<li>Checks if Sling is ready for processing the request (checks at the moment for an
existing ResourceResolverFactory service, a ServletResolver service and a MimeTypeService)</li>
	<li>Create the ResourceResolver based on the Session (by default creates a <tt>JcrResourceResolver2</tt>)</li>
	<li>Locate the <a href="/confluence/display/SLINGxSITE/Resources" title="Resources">Resource</a>
on the basis of the request by calling <tt>ResourceResovler.resolve</tt> through
<tt>RequestData.initResource</tt> (see also <a href="/confluence/display/SLINGxSITE/URL+decomposition"
title="URL decomposition">URL decomposition</a>)</li>
	<li>Locate the servlet or script (see <a href="/confluence/display/SLINGxSITE/Servlets"
title="Servlets">Servlets</a>) by calling <tt>ServletResolver.resolveServlet</tt>
through <tt>RequestData.initServlet</tt></li>
</ul>


<h3><a name="DispatchingRequests-Step7"></a>Step 7</h3>

<p>After this setup, the request level filters are called (the ones registered as <tt>javax.servlet.Filter</tt>
with the property <tt>filter.scope=request</tt>, see <a href="/confluence/display/SLINGxSITE/Filters"
title="Filters">Filters</a> for details).<br/>
If any called filter doesn't call <tt>FilterChain.doFilter</tt> at the end of
the <tt>Filter.doFilter</tt> method request processing stops here.</p>

<h3><a name="DispatchingRequests-Step8"></a>Step 8</h3>

<p>After having called all request level filters, the component level filters (registered
with the property <tt>filter.scope=component</tt>, see <a href="/confluence/display/SLINGxSITE/Filters"
title="Filters">Filters</a> for details) are called.</p>

<h3><a name="DispatchingRequests-Step9"></a>Step 9</h3>

<p>After having called the component level filters, the request servlet or script is
finally called to process the request.</p>

<h2><a name="DispatchingRequests-Include%2FForward"></a>Include/Forward</h2>

<p>If a servlet or script is including another resource for processing through the <tt>RequestDispatcher.include</tt>
or <tt>RequestDispatcher.forward</tt> (or any JSP or feature of another scripting
language which relies on one of this two methods) the following processing takes place:</p>

<h3><a name="DispatchingRequests-Step1"></a>Step 1</h3>

<p>Code in the processing servlet or script calls <tt>RequestDispatcher.include</tt>
or <tt>RequestDispatcher.forward</tt>.</p>

<h3><a name="DispatchingRequests-Step2"></a>Step 2</h3>

<p>The resource is resolved though ResourceResolver.getResource (if the RequestDispatcher
has not been created with a resource already)</p>

<h3><a name="DispatchingRequests-Step3"></a>Step 3</h3>

<p>The servlet or script to handle the resource is resolved calling the <tt>ServletResolver.resolverServlet</tt>
method.</p>

<h3><a name="DispatchingRequests-Step4"></a>Step 4</h3>

<p>The component level filters (registered with the property <tt>filter.scope=component</tt>)
are called again (see <a href="/confluence/display/SLINGxSITE/Filters" title="Filters">Filters</a>
for details).</p>

<h3><a name="DispatchingRequests-Step5"></a>Step 5</h3>

<p>The servlet or script is called to process the request.</p>

<p>Note that these steps are processed for every include or forward call.</p>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/SLINGxSITE/Dispatching+Requests">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=76180&revisedVersion=5&originalVersion=4">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/SLINGxSITE/Dispatching+Requests?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message