You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Roy Teeuwen <ro...@teeuwen.be> on 2020/11/16 15:36:48 UTC

Getting SlingHttpServletRequest in a HTTP Whiteboard

Hey all,

I would like to retrieve the SlingHttpServletRequest in a filter that has been registered through the HTTP whiteboard instead of registering it with OSGi DS and implementing the Filter service interface. Is this possible?

The code of the registration of the filter:

https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/fe1d698b3012909597490690b4fbcd054a10f4fa/bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/AbstractDispatcherCacheHeaderFilter.java#L180 <https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/fe1d698b3012909597490690b4fbcd054a10f4fa/bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/AbstractDispatcherCacheHeaderFilter.java#L180>

I already tried to set the context to org.apache.sling instead of *, but still when I debug the code, the request you get in the doFilter is the I18n…Request

If this is not possible, how can you register a Filter programatically that its inside the SlingHttpServletRequest chain?

Greets,
Roy

Re: Getting SlingHttpServletRequest in a HTTP Whiteboard

Posted by Julian Sedding <js...@gmail.com>.
Hey Roy

No this is not possible. The SlingHttpServletRequest is only available
once you're "inside" the SlingMainServlet, i.e. in filters or servlets
registered within Sling. The HTTP Whiteboard is pure OSGi and filters
registered that way are executed before the SlingMainServlet.

The order of execution is something like this (in reality it is more
complicated once inside the SlingMainServlet):

1. OSGi HTTP Service filter chain
2. SlingMainServlet (SlingHttpServletRequest/Response available after
this point)
3. Sling filter chain (i.e. Filters registered with "sling.filter.scope")
4. Sling servlet / script (e.g. Servlets registered with
"sling.servlet.resourceTypes")

Regards
Julian


On Mon, Nov 16, 2020 at 4:37 PM Roy Teeuwen <ro...@teeuwen.be> wrote:
>
> Hey all,
>
> I would like to retrieve the SlingHttpServletRequest in a filter that has been registered through the HTTP whiteboard instead of registering it with OSGi DS and implementing the Filter service interface. Is this possible?
>
> The code of the registration of the filter:
>
> https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/fe1d698b3012909597490690b4fbcd054a10f4fa/bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/AbstractDispatcherCacheHeaderFilter.java#L180 <https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/fe1d698b3012909597490690b4fbcd054a10f4fa/bundle/src/main/java/com/adobe/acs/commons/http/headers/impl/AbstractDispatcherCacheHeaderFilter.java#L180>
>
> I already tried to set the context to org.apache.sling instead of *, but still when I debug the code, the request you get in the doFilter is the I18n…Request
>
> If this is not possible, how can you register a Filter programatically that its inside the SlingHttpServletRequest chain?
>
> Greets,
> Roy

Re: Getting SlingHttpServletRequest in a HTTP Whiteboard

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Mon, Nov 16, 2020 at 4:37 PM Roy Teeuwen <ro...@teeuwen.be> wrote:
> ...how can you register a Filter programmatically that its inside the SlingHttpServletRequest chain?...

As explained at
https://sling.apache.org/documentation/the-sling-engine/filters.html ,
you need a javax.servlet.Filter OSGi service with some specific
properties described there. If you search the Sling codebase for
"sling.filter" you'll find some examples.

-Bertrand