sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Sling Website > Errorhandling
Date Wed, 21 Oct 2009 13:50:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="">Errorhandling</a></h2>
    <h4>Page  <b>added</b> by             <a href="">Felix
    <div class="notificationGreySide">
         <h1><a name="Errorhandling-HandlingErrors"></a>Handling Errors</h1>

<p>The Sling Engine includes support for handling uncaught <tt>Throwable}}s as
well as rendering custom HTTP status code pages. This is implemented by expecting a (single)
{{</tt> service to which handling of uncaught
{{Throwable}}s and HTTP status responses are delegated.</p>

<p>The Sling Servlet Resolver bundle implements this interface by providing an elaborate
mechanism to find the correct error handling script or servlet using the same algorithms as
are used to select the scripts or servlets to handle regular requests.</p>

<p>This page provides more information on how error handler scripts are selected and
what is provided out of the box.</p>

<h2><a name="Errorhandling-HandlingHTTPStatusCodes"></a>Handling HTTP Status

<p>The Sling engine implements the <tt>HttpServletResponse.sendError</tt>
methods by calling the <tt>ErrorHandler.handleError(int status, String message, SlingHttpServletRequest
request, SlingHttpServletResponse response)</tt> method.</p>

<p>The Servlet Resolver bundle implementation looks up a script to handle the status
code as follows:</p>

	<li>The status code is converted to a string and used as the request extension. Any
request extensions, selectors or suffixes from the actual request are ignored.</li>
	<li>The same resource type hierarchy is followed to find the script as for regular
script resolution. The difference is that for error handler scripts <tt>sling/servlet/errorhandler</tt>
is used as the implied base resource type (as opposed to <tt>sling/servlet/default</tt>
for regular script resolution.</li>


	<li>An application provider my provide a default handler for the 404/NOT FOUND status.
This script might be located in <tt>/libs/sling/servlet/errorhandler/404.jsp</tt>.</li>
	<li>An programmer might provide a handler for the 500/INTERNAL SERVER ERROR status
in <tt>/apps/sling/servlet/errorhandler/500.esp</tt>.</li>

<h2><a name="Errorhandling-HandlingUncaughtThrowables"></a>Handling Uncaught

<p>Work in Progress</p>

<p>To handle uncaught Throwables the simple name of the Throwable class is used as the
Servlet name. Similarly to the Java try-catch clauses the class hierarchy is supported. That
is to handle an uncaught FileNotFoundException, the names FileNotFoundException, IOException,
Exception, Throwable are checked for a Servlet and the first one found is then used. Again,
the Serlvet may be a Servlet registered as an OSGi service or may be a plain script stored
in the JCR repository or provided through some custom Resource provider.</p>
    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message