Hi all,

Currently the Sling Web Application (launchpad/webapp) has one serious
drawback: Unless you unpack the war file and configure the sling.home
init-parameter, the Sling Web Application can only be deployed once into
a single servlet container. The reason for this is, that the default
value assumed by the Sling class is the "sling" folder in the current
working directory.

To fix this issue, I propose to enhance the SlingServlet which bridges
the Servlet container, in which the Sling Web Application is deployed,
to the SlingMainServlet in the sling/engine bundle as follows:

* add a new method to the SlingServlet :

     protected String getSlingHome(ServletRequest request)

The getSlingHome first checks whether the sling.home init-param is set
in the servlet configuration. Next it checks the sling.home init-param
of the servlet context. Next if checks calls the
ServletContext.getContextPath() method. This call may fail since the
method is only defined in Servlet API 2.5. If getContextPatch is not
supported in the servlet container and request is not null, the
request.getContextPath() method is called to retreived the context paht.
If the context path can be retrieved it is converted into the path used
as sling.home by just replacing all "/" by "_", thus the context path
"/sling" would become "_sling. Otherwise (if no init-param is set,
ServletContext.getContextPath is not supported and request is null),
getSlingHome returns null.

* SlingServlet.init() is modified to call getSlingHome(null) and only
continue with Sling startup if the value returned is not null. If
getSlingHome() returns null, the SlingServlet.init() method does not
initialize Sling.

* SlingServlet.service() is enhanced to check whether the init() method
started Sling. If not, it calls getSlingHome() with the current request
object and starts Sling. This may take some time, so the
SlingServlet.service method sends back a quick response telling the
caller, that Sling is about to start. As soon as Sling has started up
the request will be processed.

This mechanism should allow the same Sling Web Application war file to
be deployed multiple times in the same servlet container and should also
account for Servlet API 2.4 containers, which do not support the
ServletContext.getContextPath() method yet.

WDYT ?

Regards
Felix

Reply via email to