Hi Juanjo,

Juanjo Vázquez schrieb:
> Hi guys,
> 
> How can i have servlet listeners in Sling? (Sorry if this is a very basic
> OSGi question).

No Problem. This is actually a good question -- I recently wondered
whether it would make sense to start thinking about
SerlvetContextListener support ...

The basic principle in terms of OSGi is very simple: Register a service
with the respective interface (e.g. ServletContextAttributeListener) and
have it receive the events.

The implementation on the Sling or OSGi side, though, is currently
missing. One thing is, that such a thing is not part of the OSGi
HttpService specification (which is based on the Servlet API 2.1). The
other missing thing is support by Sling itself.


> My goal is to implement a ServletContextAttributeListener class to response
> to changes in attributes.

For plain Sling applications, I would think, that SlingServletContext
and SlingMainServlet would be extended to support such a
ServletContextAttributeListener functionality.

For example:

  * SlingMainServlet would act as a proxy providing the attributeAdded,
        attributeRemoved and attributeReplaced methods
  * SlingMainServlet would dispatch the method calls to registered
        services.
  * SlingServletContext would call the respective methods of the
        SlingMainServlet to dispatch the events

WDYT ? Does this sound reasonable ?

A similar mechanism can be built for ServletRequestAttributeListener,
ServletRequestListener, HttpSessionAttributeListener.

I fear, that for ServletContextListener we cannot provide support
currently. But I think, this is not really required in an OSGi
framework. Similar issues might arise for HttpSessionListener.


Regards
Felix

Reply via email to