incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r853465 - in /websites/staging/sling/trunk/content: ./ documentation/the-sling-engine/servlets.html
Date Thu, 07 Mar 2013 12:17:14 GMT
Author: buildbot
Date: Thu Mar  7 12:17:14 2013
New Revision: 853465

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/the-sling-engine/servlets.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Thu Mar  7 12:17:14 2013
@@ -1 +1 @@
-1453385
+1453801

Modified: websites/staging/sling/trunk/content/documentation/the-sling-engine/servlets.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/the-sling-engine/servlets.html (original)
+++ websites/staging/sling/trunk/content/documentation/the-sling-engine/servlets.html Thu
Mar  7 12:17:14 2013
@@ -89,6 +89,7 @@
       <div class="toc">
 <ul>
 <li><a href="#servlet-registration">Servlet Registration</a><ul>
+<li><a href="#registering-a-servlet-using-java-annotations">Registering a Servlet
using Java Annotations</a></li>
 <li><a href="#automated-tests">Automated tests</a></li>
 <li><a href="#example-registration-by-path">Example: Registration by Path</a></li>
 <li><a href="#example-registration-by-resource-type-etc">Example: Registration
by Resource Type etc.</a></li>
@@ -138,11 +139,54 @@
 </tbody>
 </table>
 <p>A <code>SlingServletResolver</code> listens for <code>Servlet{</code>}services
and - given the correct service registration properties - provides the servlets as resources
in the (virtual) resource tree. Such servlets are provided as <code>ServletResource</code>
instances which adapt to the <code>javax.servlet.Servlet</code> class.</p>
-<p>For a Servlet registered as an OSGi service to be used by the Sling Servlet Resolver,
the either or both of the <code>sling.servlet.paths</code> or the <code>sling.servlet.resourceTypes</code>
service reference properties must be set. If neither is set, the Servlet service is ignored.</p>
+<p>For a Servlet registered as an OSGi service to be used by the Sling Servlet Resolver,
either or both of the <code>sling.servlet.paths</code> or the <code>sling.servlet.resourceTypes</code>
service reference properties must be set. If neither is set, the Servlet service is ignored.</p>
 <p>Each path to be used for registration - either from the <code>sling.servlet.paths</code>
property or constructed from the other <code>sling.servlet.\*</code> properties
- must be absolute. Any relative path is made absolute by prefixing it with a root path. This
prefix may be set with the <code>sling.servlet.prefix</code> service registration
property. If this property is not set, the first entry in the <code>ResourceResolver</code>
search path for the <code>ResourceResolver.getResource(String)</code> method is
used as the prefix. If this entry cannot be derived, a simpe slash - <code>/</code>
- is used as the prefix.</p>
 <p>If <code>sling.servlet.methods</code> is not specified, the servlet
is only registered for handling GET requests. Make sure to list all methods you want to be
handled by this servlet.</p>
+<h4 id="registering-a-servlet-using-java-annotations">Registering a Servlet using Java
Annotations</h4>
+<p>If you are working with the default Apache Sling development stack you can use Java
Annotations from <a href="http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html">Apache
Felix Maven SCR Plugin</a> to describe the binding details for your Sling servlets:</p>
+<ol>
+<li>
+<p>The <code>@SlingServlet</code> annotation</p>
+<div class="codehilite"><pre><span class="nd">@SlingServlet</span><span
class="o">(</span>
+    <span class="n">resourceTypes</span> <span class="o">=</span>
<span class="s">&quot;sling/servlet/default&quot;</span><span class="o">,</span>
+    <span class="n">selectors</span> <span class="o">=</span> <span
class="s">&quot;hello&quot;</span><span class="o">,</span>
+    <span class="n">extensions</span> <span class="o">=</span> <span
class="s">&quot;html&quot;</span><span class="o">,</span>
+    <span class="n">methods</span> <span class="o">=</span> <span
class="s">&quot;GET&quot;</span><span class="o">)</span>
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">MyServlet</span> <span class="kd">extends</span> <span
class="n">SlingSafeMethodsServlet</span> <span class="o">{</span>
+
+    <span class="nd">@Override</span>
+    <span class="kd">protected</span> <span class="kt">void</span>
<span class="nf">doGet</span><span class="o">(</span><span class="n">SlingHttpServletRequest</span>
<span class="n">request</span><span class="o">,</span> <span class="n">SlingHttpServletResponse</span>
<span class="n">response</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">ServletException</span><span class="o">,</span> <span
class="n">IOException</span> <span class="o">{</span>
+        <span class="o">...</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+</li>
+<li>
+<p>The <code>@Properties</code> and <code>@Property</code>
annotations</p>
+<div class="codehilite"><pre><span class="nd">@Component</span><span
class="o">(</span><span class="n">metatype</span> <span class="o">=</span>
<span class="kc">true</span><span class="o">)</span>
+<span class="nd">@Service</span><span class="o">(</span><span
class="n">Servlet</span><span class="o">.</span><span class="na">class</span><span
class="o">)</span>
+<span class="nd">@Properties</span><span class="o">({</span>
+    <span class="nd">@Property</span><span class="o">(</span><span
class="n">name</span> <span class="o">=</span> <span class="s">&quot;sling.servlet.resourceTypes&quot;</span><span
class="o">,</span> <span class="n">value</span> <span class="o">=</span>
<span class="s">&quot;sling/servlet/default&quot;</span><span class="o">),</span>
+    <span class="nd">@Property</span><span class="o">(</span><span
class="n">name</span> <span class="o">=</span> <span class="s">&quot;sling.servlet.selectors&quot;</span><span
class="o">,</span> <span class="n">value</span> <span class="o">=</span>
<span class="s">&quot;hello&quot;</span><span class="o">),</span>
+    <span class="nd">@Property</span><span class="o">(</span><span
class="n">name</span> <span class="o">=</span> <span class="s">&quot;sling.servlet.extensions&quot;</span><span
class="o">,</span> <span class="n">value</span> <span class="o">=</span>
<span class="s">&quot;html&quot;</span><span class="o">),</span>
+    <span class="nd">@Property</span><span class="o">(</span><span
class="n">name</span> <span class="o">=</span> <span class="s">&quot;sling.servlet.methods&quot;</span><span
class="o">,</span> <span class="n">value</span> <span class="o">=</span>
<span class="s">&quot;GET&quot;</span><span class="o">)</span>
+<span class="o">})</span>
+<span class="kd">public</span> <span class="kd">class</span> <span
class="nc">MyServlet</span> <span class="kd">extends</span> <span
class="n">SlingSafeMethodsServlet</span> <span class="o">{</span>
+
+    <span class="nd">@Override</span>
+    <span class="kd">protected</span> <span class="kt">void</span>
<span class="nf">doGet</span><span class="o">(</span><span class="n">SlingHttpServletRequest</span>
<span class="n">request</span><span class="o">,</span> <span class="n">SlingHttpServletResponse</span>
<span class="n">response</span><span class="o">)</span> <span class="kd">throws</span>
<span class="n">ServletException</span><span class="o">,</span> <span
class="n">IOException</span> <span class="o">{</span>
+        <span class="o">...</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+</li>
+</ol>
 <h3 id="automated-tests">Automated tests</h3>
-<p>The <a href="">launchpad/test-services</a> module contains test servlets
that use various combinations of the above properties. </p>
+<p>The <a href="">launchpad/test-services</a> module contains test servlets
that use various combinations of the above properties.</p>
 <p>The <a href="">launchpad/integration-tests</a> module contains a number
of tests (like the [ExtensionServletTest|http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ExtensionServletTest.java]
for example) that verify the results.</p>
 <p>Such tests run as part of our continuous integration process, to demonstrate and
verify the behavior of the various servlet registration mechanisms, in a way that's guaranteed
to be in sync with the actual Sling core code. If you have an idea for additional tests, make
sure to let us know!</p>
 <h3 id="example-registration-by-path">Example: Registration by Path</h3>
@@ -213,7 +257,7 @@ The mechanism helping the provider here 
 <h2 id="error-handler-servlets-or-scripts">Error Handler Servlet(s) or Scripts</h2>
 <p>Error handling support is now described on the <a href="/documentation/the-sling-engine/errorhandling.html">Errorhandling</a>
page.</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1348706 by fmeschbe on Mon, 11 Jun 2012 01:55:58 +0000
+        Rev. 1453801 by fmeschbe on Thu, 7 Mar 2013 12:17:03 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project



Mime
View raw message