Class SlingServletDelegate
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,Launcher
SlingServletDelegate serves as a basic servlet for Project Sling.
The tasks of this servlet are as follows:
- The
init()method launches ApacheFelixas the OSGi framework implementation we use. - Registers as a service listener interested for services of type
jakarta.servlet.Servlet. - Handles requests by delegating to a servlet which is expected to be
registered with the framework as a service of type
jakarta.servlet.Servlet. If no delegatee servlet has been registered request handlings results in a temporary unavailability of the servlet.
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:
- The
sling.propertiesis read from the servlet class path. This properties file contains default settings. - Extensions of this servlet may provide additional properties to be
loaded overwriting the
loadConfigProperties(String)method. - 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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcalculateServletPackages(String servletVersion, int majorVersion) final voiddestroy()Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.final voidinit()Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and theFelixinstance as servlet context attributes.final voidservice(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) Services the request by delegating to the delegatee servlet.voidsetCommandLine(Map<String, String> args) The commandline provided from the standalone launch case.voidsetNotifiable(Notifiable notifiable) TheNotifiableto notify on framework stop or updatevoidsetSlingHome(String slingHome) Sets the sling.home to be used for starting the framework.booleanstart()Starts the framework and returnstrueif successfull.voidstop()Stops the framework.Methods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
SlingServletDelegate
public SlingServletDelegate()
-
-
Method Details
-
setCommandLine
Description copied from interface:LauncherThe commandline provided from the standalone launch case.- Specified by:
setCommandLinein interfaceLauncher- Parameters:
args- The commandline
-
setSlingHome
Description copied from interface:LauncherSets the sling.home to be used for starting the framework. This method must be called with a non-nullargument before trying to start the framework.- Specified by:
setSlingHomein interfaceLauncher- Parameters:
slingHome- The sling.home directory
-
start
public boolean start()Description copied from interface:LauncherStarts the framework and returnstrueif successfull. -
stop
public void stop()Description copied from interface:LauncherStops 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. -
init
public final void init() throws jakarta.servlet.ServletExceptionInitializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and theFelixinstance as servlet context attributes.- Overrides:
initin classjakarta.servlet.GenericServlet- Throws:
jakarta.servlet.ServletException- if the framework cannot be initialized.
-
service
public final void service(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) throws jakarta.servlet.ServletException, IOException Services the request by delegating to the delegatee servlet. If no delegatee servlet is available, aUnavailableExceptionis thrown.- Specified by:
servicein interfacejakarta.servlet.Servlet- Specified by:
servicein classjakarta.servlet.GenericServlet- Parameters:
req- theServletRequestobject that contains the client's requestres- theServletResponseobject that will contain the servlet's response- Throws:
jakarta.servlet.UnavailableException- if the no delegatee servlet is currently availablejakarta.servlet.ServletException- if an exception occurs that interferes with the servlet's normal operation occurredIOException- 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:
destroyin interfacejakarta.servlet.Servlet- Overrides:
destroyin classjakarta.servlet.GenericServlet
-
calculateServletPackages