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 > Filters
Date Wed, 08 Sep 2010 13:26:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Filters">Filters</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        ua<br />
    </div>
        <br/>
                         <h4>Changes (35)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-unchanged" >h1. Servlet Filter Support <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >Sling supports filter processing
by applying filter chains to the requests before actually dispatching to the servlet or script
for processing. Filters to be used in such filter processing are plain OSGi services <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">for
the</span> <span class="diff-added-words"style="background-color: #dfd;">of</span>
type {{javax.servlet.Filter}} which of course means that the services implement this interface.
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{note}
<br>Support for Servlet Filters is currently being further developed in the trunk of
the Sling Engine module. This page is being updated to reflect these changes. There is a section
at the end of this page which will shortly describe the Servlet Filter Support of Sling up
to and including the Sling Engine 2.1.0 bundle.\\ <br>See [SLING-1213|https://issues.apache.org/jira/browse/SLING-1213],
[SLING-1734|https://issues.apache.org/jira/browse/SLING-1734], and [Registering filters with
Sling|http://markmail.org/message/quxhm7d5s6u66crr] for more details. <br>{note} <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >For Sling to pick up a {{javax.servlet.Filter}}
service for filter processing two service registration properties are inspected: <br>
<br>|| Property || Type || Default Value || Valid Values || Description || <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
{{filter.scope}} | {{String}} | {{request}} | {{component}}, {{request}} | Indication of which
chain the filter should be added to. By default a filter is added to the request filter chain.
The default value also applies if the value of this property is any other value than one of
the valid values. *Using this default behavior is highly discouraged and will result a logged
warning.* | <br>| {{filter.order}} | {{Integer}} | {{Integer.MAX_VALUE}} | Any {{Integer}}
value | Indication of where to place the filter in the filter chain. The smaller the number
the earlier in the filter chain. This value may span the whole range of integer values. The
default value causes the filter to just be appended to the filter chain. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{sling.filter.scope}} | {{String}}, {{String[]}} or {{Vector&lt;String&gt;}} | {{request}}
| {{REQUEST}}, {{INCLUDE}}, {{FORWARD}}, {{ERROR}}, {{COMPONENT}} | Indication of which chain
the filter should be added to. This property is required. If it is missing from the service,
the service is ignored because it is assumed another consumer will be interested in using
the service. Any unknown values of this property are also ignored causing the service to be
completely ignored if none of the values provided by the property are valid. See below for
the description of the filter chains. | <br>| {{service.ranking}} | {{Integer}} | {{0}}
| Any {{Integer}} value | Indication of where to place the filter in the filter chain. The
higher the number the earlier in the filter chain. This value may span the whole range of
integer values. Two filters with equal {{service.ranking}} property value (explicitly set
or default value of zero) will be ordered according to their {{service.id}} service property
as described in section 5.2.5, Service Properties, of the OSGi Core Specification R 4.2. |
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h2.
Felix Whiteboard Compatibility <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">In
order to achive compatibility with Apache Felix&#39;s HttpService Whiteboard implementation
([http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard]),
Sling will skip any filters registered with the {{pattern}} service registration property.
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Filter Chains <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Sling
maintains two filter chains: the request filter chain and the component filter chain. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Sling
maintains five filter chains: request level, component level, include filters, forward filters
and error filters. Except for the component level filter these filter chains correspond to
the filter {{&lt;dispatcher&gt;}} configurations as defined for Servlet API 2.5 web
applications (see section SRV.6.2.5 Filters and the RequestDispatcher). <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
filters on the request filter chain are only called once for the complete request processing.
The request level filter chain is comparable to the set of filters configured as {{&lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;}}
in Servlet API 2.5 web applications (see section SRV.6.2.5 Filters and the RequestDispatcher).
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
following table summarizes when each of the filter chains is called and what value must be
defined in the {{sling.filter.scope}} property to have a filter added to the respective chain:
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The
filters on the component filter chain are processed for each included resource initiated through
the RequestDispatcher. The component level filter chain is comparable to the set of filters
configured as {{&lt;dispatcher&gt;INCLUDE,FORWARD,ERROR&lt;/dispatcher&gt;}}
in Servlet API 2.5 web applications (see section SRV.6.2.5 Filters and the RequestDispatcher).
Note, that it is currently not possible to call filters only on include, forward, or error
or any combination. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">||
{{sling.filter.scope}} || Servlet API Correspondence || Description || <br>| {{REQUEST}}
| {{REQUEST}} | Filters are called once per request hitting Sling from the outside. These
filters are called after the resource addressed by the request URL and the Servlet or script
to process the request has been resolved before the {{COMPONENT}} filters (if any) and the
Servlet or script are called. | <br>| {{INCLUDE}} | {{INCLUDE}} | Filters are called
upon calling the {{RequestDispatcher.include}} method after the included resource and the
Servlet or script to process the include have been resolved before the Servlet or script is
called. | <br>| {{FORWARD}} | {{FORWARD}} | Filters are called upon calling the {{RequestDispatcher.forward}}
method after the included resource and the Servlet or script to process the include have been
resolved before the Servlet or script is called. | <br>| {{ERROR}} | {{ERROR}} | Filters
are called upon {{HttpServletResponse.sendError}} or any uncaught {{Throwable}} before resolving
the error handler Servlet or script. | <br>| {{COMPONENT}} | {{REQUEST,INCLUDE,FORWARD}}
| The {{COMPONENT}} scoped filters are present for backwards compatibility with earlier Sling
Engine releases. These filters will be called among the {{INCLUDE}} and {{FORWARD}} filters
upon {{RequestDispatcher.include}} or {{RequestDispatcher.forward}} as well as before calling
the request level Servlet or script after the {{REQUEST}} filters. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Note
on {{INCLUDE}} and {{FORWARD}} with respect to JSP tags: These filters are also called if
the respective including (e.g. {{&lt;jsp:include&gt;}} or {{&lt;sling:include&gt;}})
or forwarding (e.g. {{&lt;jsp:forward&gt;}} or {{&lt;sling:forward&gt;}})
ultimately calls the {{RequestDispatcher}}. <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| Call Servlet or Script | <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >When a servlet or script is including
<span class="diff-added-words"style="background-color: #dfd;">or forwarding to</span>
another resource for processing through the {{RequestDispatcher}} (or any JSP tag or other
language feature ultimately using a {{RequestDispatcher}}) the following _Dispatch_ processing
takes place: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>| _Dispatch_ | <br>|
Resolve the resource to dispatch to if not already defined when getting the {{RequestDispatcher}}
| <br>| Servlet/Script resolution | <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|
_Component Level_ | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
Call include or forward filters depending on the kind of dispatch | <br>| Call Servlet
or Script | <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Note,
that after ensuring the resource to be included (or forwarded to) and resolving the servlet
or script to handle the included (or forwarded) resource, the _Component Level_ processing
takes place as for the general request processing. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">As
a consequence, request level filters will be called at most once during request processing
(they may not be called at all if a filter earlier in the filter chain decides to terminate
the request) while the component level, include, and forward filters may be called multiple
times while processing a request. <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">As
a consequence, request level filters will be called at most once during request processing
(they may not be called at all if a filter earlier in the filter chain decides to terminate
the request) while the component level filters may be called multiple times while processing
a request. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Troubleshooting <br>Apart
form the logs which tell you when filters are executed, two Sling plugins provide information
about filters in the OSGi console. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>{code:title=Recent Requests
plugin info} <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-added-words"style="background-color:
#dfd;">0 (2010-09-08 15:22:38)</span> TIMER_START{Request Processing} <br></td></tr>
            <tr><td class="diff-unchanged" >... <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">LOG
Resource Path Info: SlingRequestPathInfo: path=&#39;/libs/foo/welcome&#39;... <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">0
(2010-09-08 15:22:38) LOG Method=GET, PathInfo=/libs/wcm/core/content/siteadmin.html <br>3
(2010-09-08 15:22:38) LOG Applying request filters <br>3 (2010-09-08 15:22:38) LOG Calling
filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter <br>3 (2010-09-08
15:22:38) LOG Calling filter: org.apache.sling.portal.container.internal.request.PortalFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
<br>3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
<br>3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
<br>3 (2010-09-08 15:22:38) LOG RedirectFilter did not redirect (MobileUtil.isMobileResource()
returns false) <br>3 (2010-09-08 15:22:38) LOG Applying inner filters <br>3 (2010-09-08
15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter <br>3 (2010-09-08
15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter <br>3 (2010-09-08
15:22:38) TIMER_START{/libs/cq/ui/components/widget/html.jsp#0} <br></td></tr>
            <tr><td class="diff-unchanged" >... <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">LOG
Applying request filters <br>LOG Calling filter: org.apache.sling.portal.container.internal.request.PortalFilter
<br>LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter <br>LOG
Calling filter: org.apache.sling.i18n.impl.I18NFilter <br>LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
<br>LOG Applying inner filters <br>LOG Calling filter: com.foo.SomeComponentFilter
<br>LOG Calling filter: com.foo.AnotherComponentFilter <br>... <br>TIMER_END{4833,Request
Processing} Request Processing <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">8
(2010-09-08 15:22:38) TIMER_END{8,Request Processing} Request Processing <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>Request Filters: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">-2147483648
: class org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter (2547) <br></td></tr>
            <tr><td class="diff-changed-lines" >-3000 : class org.apache.sling.portal.container.internal.request.PortalFilter
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">(222)</span>
<span class="diff-added-words"style="background-color: #dfd;">(2562)</span> <br></td></tr>
            <tr><td class="diff-changed-lines" >-2500 : class org.apache.sling.rewriter.impl.RewriterFilter
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">(248)</span>
<span class="diff-added-words"style="background-color: #dfd;">(3365)</span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">-2000
: class com.day.cq.wcm.core.impl.WCMRequestFilter (2548) <br></td></tr>
            <tr><td class="diff-changed-lines" >-700 : class org.apache.sling.i18n.impl.I18NFilter
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">(240)</span>
<span class="diff-added-words"style="background-color: #dfd;">(2334)</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">2147483647
: class org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter (231) <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">-600
: class com.day.cq.theme.impl.ThemeResolverFilter (2244) <br>-600 : class com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
(2268) <br>0 : class org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
(2402) <br>1000 : class com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter (3363)
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Error
Filters: <br>--- <br> <br>Include Filters: <br>-200 : class com.day.cq.wcm.core.impl.WCMComponentFilter
(2583) <br>1000 : class com.day.cq.wcm.core.impl.WCMDebugFilter (2449) <br> <br>Forward
Filters: <br>-200 : class com.day.cq.wcm.core.impl.WCMComponentFilter (2583) <br>1000
: class com.day.cq.wcm.core.impl.WCMDebugFilter (2449) <br> <br></td></tr>
            <tr><td class="diff-unchanged" >Component Filters: <br></td></tr>
            <tr><td class="diff-changed-lines" >-200 : class <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">com.foo.SomeComponentFilter
(564)</span> <span class="diff-added-words"style="background-color: #dfd;">com.day.cq.wcm.core.impl.WCMComponentFilter
(2583)</span> <br></td></tr>
            <tr><td class="diff-changed-lines" >1000 : class <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">com.foo.AnotherComponentFilter
(348)</span> <span class="diff-added-words"style="background-color: #dfd;">com.day.cq.wcm.core.impl.WCMDebugFilter
(2449)</span> <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br>The first
numbers on those lines are the filter priorities, and the last number in parentheses is the
OSGi service ID. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br> <br>h2. Support in Sling Engine 2.1.0 <br> <br>Up to and including
Sling Engine 2.1.0 support for Servlet Filters has been as follows: <br> <br>*
Any {{javax.servlet.Filter}} service is accepted as a filter for Sling unless the {{pattern}}
property used by the [Apache Felix HttpService whiteboard support|http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard]
is set in the service registration properties. <br>* The {{filter.scope}} property is
optional and supports the case-sensitive values {{request}} and {{component}}. <br>*
Filter ordering is defined by the {{filter.order}} property whose default value is {{Integer.MAX_VALUE}}
where smaller values have higher priority over higher values. <br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="Filters-ServletFilterSupport"></a>Servlet Filter Support</h1>

<p>Sling supports filter processing by applying filter chains to the requests before
actually dispatching to the servlet or script for processing. Filters to be used in such filter
processing are plain OSGi services of type <tt>javax.servlet.Filter</tt> which
of course means that the services implement this interface.</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>Support for Servlet Filters is
currently being further developed in the trunk of the Sling Engine module. This page is being
updated to reflect these changes. There is a section at the end of this page which will shortly
describe the Servlet Filter Support of Sling up to and including the Sling Engine 2.1.0 bundle.<br
class="atl-forced-newline" />
See <a href="https://issues.apache.org/jira/browse/SLING-1213" class="external-link" rel="nofollow">SLING-1213</a>,
<a href="https://issues.apache.org/jira/browse/SLING-1734" class="external-link" rel="nofollow">SLING-1734</a>,
and <a href="http://markmail.org/message/quxhm7d5s6u66crr" class="external-link" rel="nofollow">Registering
filters with Sling</a> for more details.</td></tr></table></div>

<p>For Sling to pick up a <tt>javax.servlet.Filter</tt> service for filter
processing two service registration properties are inspected:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Valid Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>sling.filter.scope</tt> </td>
<td class='confluenceTd'> <tt>String</tt>, <tt>String[]</tt>
or <tt>Vector&lt;String&gt;</tt> </td>
<td class='confluenceTd'> <tt>request</tt> </td>
<td class='confluenceTd'> <tt>REQUEST</tt>, <tt>INCLUDE</tt>,
<tt>FORWARD</tt>, <tt>ERROR</tt>, <tt>COMPONENT</tt> </td>
<td class='confluenceTd'> Indication of which chain the filter should be added to. This
property is required. If it is missing from the service, the service is ignored because it
is assumed another consumer will be interested in using the service. Any unknown values of
this property are also ignored causing the service to be completely ignored if none of the
values provided by the property are valid. See below for the description of the filter chains.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>service.ranking</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> Any <tt>Integer</tt> value </td>
<td class='confluenceTd'> Indication of where to place the filter in the filter chain.
The higher the number the earlier in the filter chain. This value may span the whole range
of integer values. Two filters with equal <tt>service.ranking</tt> property value
(explicitly set or default value of zero) will be ordered according to their <tt>service.id</tt>
service property as described in section 5.2.5, Service Properties, of the OSGi Core Specification
R 4.2. </td>
</tr>
</tbody></table>
</div>



<h2><a name="Filters-FilterChains"></a>Filter Chains</h2>

<p>Sling maintains five filter chains: request level, component level, include filters,
forward filters and error filters. Except for the component level filter these filter chains
correspond to the filter <tt>&lt;dispatcher&gt;</tt> configurations as
defined for Servlet API 2.5 web applications (see section SRV.6.2.5 Filters and the RequestDispatcher).</p>

<p>The following table summarizes when each of the filter chains is called and what
value must be defined in the <tt>sling.filter.scope</tt> property to have a filter
added to the respective chain:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> <tt>sling.filter.scope</tt> </th>
<th class='confluenceTh'> Servlet API Correspondence </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>REQUEST</tt> </td>
<td class='confluenceTd'> <tt>REQUEST</tt> </td>
<td class='confluenceTd'> Filters are called once per request hitting Sling from the
outside. These filters are called after the resource addressed by the request URL and the
Servlet or script to process the request has been resolved before the <tt>COMPONENT</tt>
filters (if any) and the Servlet or script are called. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>INCLUDE</tt> </td>
<td class='confluenceTd'> <tt>INCLUDE</tt> </td>
<td class='confluenceTd'> Filters are called upon calling the <tt>RequestDispatcher.include</tt>
method after the included resource and the Servlet or script to process the include have been
resolved before the Servlet or script is called. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>FORWARD</tt> </td>
<td class='confluenceTd'> <tt>FORWARD</tt> </td>
<td class='confluenceTd'> Filters are called upon calling the <tt>RequestDispatcher.forward</tt>
method after the included resource and the Servlet or script to process the include have been
resolved before the Servlet or script is called. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ERROR</tt> </td>
<td class='confluenceTd'> <tt>ERROR</tt> </td>
<td class='confluenceTd'> Filters are called upon <tt>HttpServletResponse.sendError</tt>
or any uncaught <tt>Throwable</tt> before resolving the error handler Servlet
or script. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>COMPONENT</tt> </td>
<td class='confluenceTd'> <tt>REQUEST,INCLUDE,FORWARD</tt> </td>
<td class='confluenceTd'> The <tt>COMPONENT</tt> scoped filters are present
for backwards compatibility with earlier Sling Engine releases. These filters will be called
among the <tt>INCLUDE</tt> and <tt>FORWARD</tt> filters upon <tt>RequestDispatcher.include</tt>
or <tt>RequestDispatcher.forward</tt> as well as before calling the request level
Servlet or script after the <tt>REQUEST</tt> filters. </td>
</tr>
</tbody></table>
</div>


<p>Note on <tt>INCLUDE</tt> and <tt>FORWARD</tt> with respect
to JSP tags: These filters are also called if the respective including (e.g. <tt>&lt;jsp:include&gt;</tt>
or <tt>&lt;sling:include&gt;</tt>) or forwarding (e.g. <tt>&lt;jsp:forward&gt;</tt>
or <tt>&lt;sling:forward&gt;</tt>) ultimately calls the <tt>RequestDispatcher</tt>.</p>


<h2><a name="Filters-FilterProcessing"></a>Filter Processing</h2>

<p>Filter processing is part of the Sling request processing, which may be sketched
as follows:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> <em>Request Level</em> </td>
</tr>
<tr>
<td class='confluenceTd'> Authentication </td>
</tr>
<tr>
<td class='confluenceTd'> Resource Resolution </td>
</tr>
<tr>
<td class='confluenceTd'> Servlet/Script Resolution </td>
</tr>
<tr>
<td class='confluenceTd'> Request Level Filter Processing </td>
</tr>
<tr>
<td class='confluenceTd'> <em>Component Level</em> </td>
</tr>
</tbody></table>
</div>


<p>The first step of request processing is the <em>Request Level</em> processing
which is concerned with resolving the resource, finding the appropriate servlet and calling
into the request level filter chain. The next step is the <em>Component Level</em>
processing, calling into the component level filters before finally calling the servlet or
script:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> <em>Component Level</em> </td>
</tr>
<tr>
<td class='confluenceTd'> Component Level Filter Processing </td>
</tr>
<tr>
<td class='confluenceTd'> Call Servlet or Script </td>
</tr>
</tbody></table>
</div>


<p>When a servlet or script is including or forwarding to another resource for processing
through the <tt>RequestDispatcher</tt> (or any JSP tag or other language feature
ultimately using a <tt>RequestDispatcher</tt>) the following <em>Dispatch</em>
processing takes place:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> <em>Dispatch</em> </td>
</tr>
<tr>
<td class='confluenceTd'> Resolve the resource to dispatch to if not already defined
when getting the <tt>RequestDispatcher</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> Servlet/Script resolution </td>
</tr>
<tr>
<td class='confluenceTd'> Call include or forward filters depending on the kind of dispatch
</td>
</tr>
<tr>
<td class='confluenceTd'> Call Servlet or Script </td>
</tr>
</tbody></table>
</div>


<p>As a consequence, request level filters will be called at most once during request
processing (they may not be called at all if a filter earlier in the filter chain decides
to terminate the request) while the component level, include, and forward filters may be called
multiple times while processing a request.</p>


<h2><a name="Filters-Troubleshooting"></a>Troubleshooting</h2>
<p>Apart form the logs which tell you when filters are executed, two Sling plugins provide
information about filters in the OSGi console.</p>

<h3><a name="Filters-RecentRequestsplugin"></a>Recent Requests plugin</h3>
<p>The request traces provided at <tt>/system/console/requests</tt> contain
information about filter execution, as in this example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Recent Requests plugin info</b></div><div
class="codeContent panelContent">
<pre class="code-java">
0 (2010-09-08 15:22:38) TIMER_START{Request Processing}
...
0 (2010-09-08 15:22:38) LOG Method=GET, PathInfo=/libs/wcm/core/content/siteadmin.html
3 (2010-09-08 15:22:38) LOG Applying request filters
3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.portal.container.internal.request.PortalFilter
3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
3 (2010-09-08 15:22:38) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
3 (2010-09-08 15:22:38) LOG RedirectFilter did not redirect (MobileUtil.isMobileResource()
returns <span class="code-keyword">false</span>)
3 (2010-09-08 15:22:38) LOG Applying <span class="code-keyword">inner</span> filters
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
3 (2010-09-08 15:22:38) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
3 (2010-09-08 15:22:38) TIMER_START{/libs/cq/ui/components/widget/html.jsp#0}
...
8 (2010-09-08 15:22:38) TIMER_END{8,Request Processing} Request Processing
</pre>
</div></div>

<h3><a name="Filters-ConfigStatusplugin"></a>Config Status plugin</h3>
<p>The configuration status page at <tt>/system/console/config</tt> includes
the current list of active filters in its <em>Servlet Filters</em> category, as
in this example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Config Status plugin info</b></div><div
class="codeContent panelContent">
<pre class="code-java">
Current Apache Sling Servlet Filter Configuration

Request Filters:
-2147483648 : class org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter (2547)
-3000 : class org.apache.sling.portal.container.internal.request.PortalFilter (2562)
-2500 : class org.apache.sling.rewriter.impl.RewriterFilter (3365)
-2000 : class com.day.cq.wcm.core.impl.WCMRequestFilter (2548)
-700 : class org.apache.sling.i18n.impl.I18NFilter (2334)
-600 : class com.day.cq.theme.impl.ThemeResolverFilter (2244)
-600 : class com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet (2268)
0 : class org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter (2402)
1000 : class com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter (3363)

Error Filters:
---

Include Filters:
-200 : class com.day.cq.wcm.core.impl.WCMComponentFilter (2583)
1000 : class com.day.cq.wcm.core.impl.WCMDebugFilter (2449)

Forward Filters:
-200 : class com.day.cq.wcm.core.impl.WCMComponentFilter (2583)
1000 : class com.day.cq.wcm.core.impl.WCMDebugFilter (2449)

Component Filters:
-200 : class com.day.cq.wcm.core.impl.WCMComponentFilter (2583)
1000 : class com.day.cq.wcm.core.impl.WCMDebugFilter (2449)
</pre>
</div></div>

<p>The first numbers on those lines are the filter priorities, and the last number in
parentheses is the OSGi service ID.</p>


<h2><a name="Filters-SupportinSlingEngine2.1.0"></a>Support in Sling Engine
2.1.0</h2>

<p>Up to and including Sling Engine 2.1.0 support for Servlet Filters has been as follows:</p>

<ul>
	<li>Any <tt>javax.servlet.Filter</tt> service is accepted as a filter for
Sling unless the <tt>pattern</tt> property used by the <a href="http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard"
class="external-link" rel="nofollow">Apache Felix HttpService whiteboard support</a>
is set in the service registration properties.</li>
	<li>The <tt>filter.scope</tt> property is optional and supports the case-sensitive
values <tt>request</tt> and <tt>component</tt>.</li>
	<li>Filter ordering is defined by the <tt>filter.order</tt> property whose
default value is <tt>Integer.MAX_VALUE</tt> where smaller values have higher priority
over higher values.</li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Filters">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=115575&revisedVersion=5&originalVersion=4">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Filters?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message