org.apache.sling.launchpad.base.webapp
Class SlingServletDelegate

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by org.apache.sling.launchpad.base.webapp.SlingServletDelegate
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, Launcher

public class SlingServletDelegate
extends javax.servlet.GenericServlet
implements Launcher

The SlingServletDelegate serves as a basic servlet for Project Sling. The tasks of this servlet are as follows:

Request Handling

This servlet handles request by forwarding to a delegatee servlet. The delegatee servlet is automatically retrieved from the service registry by the getDelegatee(). This method also makes sure, the such a servlet actually exits by throwing an UnvailableException if not and also makes sure the servlet is initialized.

Launch Configuration

The Apache Felix framework requires configuration parameters to be specified for startup. This servlet builds the list of parameters from three locations:

  1. The sling.properties is read from the servlet class path. This properties file contains default settings.
  2. Extensions of this servlet may provide additional properties to be loaded overwriting the loadConfigProperties(String) method.
  3. Finally, web application init parameters are added to the properties and may overwrite existing properties of the same name(s).

After loading all properties, variable substitution takes place on the property values. A variable is indicated as ${<prop-name>} where <prop-name> is the name of a system or configuration property (configuration properties override system properties). Variables may be nested and are resolved from inner-most to outer-most. For example, the property value ${outer-${inner}} is resolved by first resolving ${inner} and then resolving the property whose name is the catenation of outer- and the result of resolving ${inner}.

Logging

This servlet logs through the servlet container logging mechanism by calling the GenericServlet.log methods. Bundles launched within the framework provided by this servlet may use whatever logging mechanism they choose to use. The Commons OSGI Log Bundle provides an OSGi Log Service implementation, which also provides access to Apache Commons Logging, SLF4J and Log4J logging. It is recommended that this bundle is used to setup and configure logging for systems based on this servlet.

See Also:
Serialized Form

Constructor Summary
SlingServletDelegate()
           
 
Method Summary
 void destroy()
          Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.
 void init()
          Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.
 void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
          Services the request by delegating to the delegatee servlet.
 void setCommandLine(Map<String,String> args)
          The commandline provided from the standalone launch case.
 void setNotifiable(Notifiable notifiable)
          The Notifiable to notify on framework stop or update
 void setSlingHome(String slingHome)
          Sets the sling.home to be used for starting the framework.
 boolean start()
          Starts the framework and returns true if successfull.
 void stop()
          Stops the framework.
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlingServletDelegate

public SlingServletDelegate()
Method Detail

setNotifiable

public void setNotifiable(Notifiable notifiable)
Description copied from interface: Launcher
The Notifiable to notify on framework stop or update

Specified by:
setNotifiable in interface Launcher

setCommandLine

public void setCommandLine(Map<String,String> args)
Description copied from interface: Launcher
The commandline provided from the standalone launch case.

Specified by:
setCommandLine in interface Launcher

setSlingHome

public void setSlingHome(String slingHome)
Description copied from interface: Launcher
Sets the sling.home to be used for starting the framework. This method must be called with a non-null argument before trying to start the framework.

Specified by:
setSlingHome in interface Launcher

start

public boolean start()
Description copied from interface: Launcher
Starts the framework and returns true if successfull.

Specified by:
start in interface Launcher

stop

public void stop()
Description copied from interface: Launcher
Stops the framework. This method only returns when the framework has actually been stopped. This method may be used by the main class or servlet to initiate a shutdown of the framework.

Specified by:
stop in interface Launcher

init

public final void init()
                throws javax.servlet.ServletException
Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if the framework cannot be initialized.

service

public final void service(javax.servlet.ServletRequest req,
                          javax.servlet.ServletResponse res)
                   throws javax.servlet.ServletException,
                          IOException
Services the request by delegating to the delegatee servlet. If no delegatee servlet is available, a UnavailableException is thrown.

Specified by:
service in interface javax.servlet.Servlet
Specified by:
service in class javax.servlet.GenericServlet
Parameters:
req - the ServletRequest object that contains the client's request
res - the ServletResponse object that will contain the servlet's response
Throws:
javax.servlet.UnavailableException - if the no delegatee servlet is currently available
javax.servlet.ServletException - if an exception occurs that interferes with the servlet's normal operation occurred
IOException - if an input or output exception occurs

destroy

public final void destroy()
Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.