Re: [osgi-dev] How can I reuse servlet filter across bundles

2018-09-13 Thread Raymond Auge via osgi-dev
Thai, what you described sounds like a bug in the http whiteboard
implementation. Which do you use and could you file a bug against it?

- Ray

On Wed, Sep 12, 2018, 17:38 Nhut Thai Le,  wrote:

> Thank you Raymond,
>
> I called the  HttpServiceRuntim.calculateRequestInfoDTO("/token") inside
> my servlet and i see my filter listed as filterDTOs:
> {"path":"/token", "servletContextId":125,
> "filterDTOs":[{"name":"AuthenticationFilter", "patterns":["/*"],
> "servletNames":null, "regexs":null, "asyncSupported":false,
> "dispatcher":[], "initParams":{"component.id":"33", 
> "component.name":"com.casto...ionFilter",
> "service.id":"117", "objectClass":"[Ljava.la...@5891e480",
> "filterRank":"10", "service.scope":"prototype",
> "osgi.http.whiteboard.filter.pattern":"/*", "
> osgi.http.whiteboard.filter.name":"AuthenticationFilter",
> "osgi.http.whiteboard.context.select":"(osgi.htt...xtHelper)",
> "service.ranking":"10", "service.bundleid":"136"}, "serviceId":117,
> "servletContextId":125}], "servletDTO":{"patterns":["/token"], "name":null,
> "servletInfo":"", "asyncSupported":false, "initParams":{},
> "servletContextId":125, "serviceId":127}, "resourceDTO":null}
>
> However, the filter is still not triggered. If i manually create a
> ServletContextHelper and add "osgi.http.whiteboard.context.select=(
> osgi.http.whiteboard.context.name=SharedServletContextHelper)" to both
> the filter and the servlet then i can see the filter kick in before the
> request hit the servlet. So I think shared servlet context is required to
> have the filters works across bundles. My concern is that i cannot use the
> SharedServletContextHelper on the resource service because it will not see
> the icons folder in my bundle. Here is the debug log if i use the
> SharedServletContextHelper with the resource service:
>
> [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - servlet
> |/static/icons|/bundle1.png -> /static/icons/*:/icons@d606ba18
> ==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
> [qtp345379538-59] DEBUG
> org.ops4j.pax.web.service.jetty.internal.HttpServiceContext - Handling
> request for [/static/icons/bundle1.png] using http context
> [org.ops4j.pax.web.extender.whiteboard.internal.WebApplication$1@1b9ac962]
> [qtp345379538-59] DEBUG
> org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler -
> handling request
> org.ops4j.pax.web.service.jetty.internal.HttpServiceRequestWrapper@5b1bfc6,
> org.ops4j.pax.web.service.jetty.internal.HttpServiceResponseWrapper@b765100
> [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler -
> chain=org.ops4j.pax.web.service.spi.model.FilterModel-13->/static/icons/*:/icons@d606ba18
> ==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
> [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call
> filter org.ops4j.pax.web.service.spi.model.FilterModel-13
> [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call
> servlet 
> /static/icons/*:/icons@d606ba18==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
>  [qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ErrorPageErrorHandler -
> getErrorPage(GET /static/icons/bundle1.png) => error_page=null (from global
> default)
>
> So now the question really is how to hook my servlet filter to a resource
> service.
>
> Thai
>
> On Wed, Sep 12, 2018 at 3:01 PM, Raymond Auge 
> wrote:
>
>> Hello Thai,
>>
>> I don't see anything wrong.
>>
>> It looks like they all "target" the default "ServletContextHelper" (i.e.
>> the same context) and so the filter should apply to each.
>>
>> You should be able to check by getting the HttpServiceRuntime [1] service
>> and calling the method `calculateRequestInfoDTO(String path)` to see what
>> the runtime thinks is wired up for that path.
>>
>> Sincerely,
>> - Ray
>>
>> [1]
>> https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#org.osgi.service.http.runtime.HttpServiceRuntime
>>
>> On Wed, Sep 12, 2018 at 2:39 PM, Nhut Thai Le via osgi-dev <
>> osgi-dev@mail.osgi.org> wrote:
>>
>>> Hello,
>>>
>>> I want to have a filter at the root of my application where all http
>>> requests must pass through, so I make a Servlet filter:
>>> @Component(
>>> service=Filter.class,
>>> scope=ServiceScope.PROTOTYPE,
>>> property= {
>>> "osgi.http.whiteboard.filter.name=AuthenticationFilter",
>>> "osgi.http.whiteboard.filter.pattern=/*",
>>> "service.ranking:Integer=10"
>>> }
>>> )
>>> public final class AuthenticationFilter implements Filter {...}
>>> -
>>> Then I have some servlets (in other bundles) defined like this:
>>> @Component(
>>> service = Servlet.class,
>>> property= {
>>> "osgi.http.whiteboard.servlet.pattern=/token"
>>> }
>>> )
>>> public class AccessTokenServlet extends HttpServlet{...}
>>> ---
>>> I also have some resource services in other bundles:
>>> 

Re: [osgi-dev] How can I reuse servlet filter across bundles

2018-09-12 Thread Nhut Thai Le via osgi-dev
Thank you Raymond,

I called the  HttpServiceRuntim.calculateRequestInfoDTO("/token") inside my
servlet and i see my filter listed as filterDTOs:
{"path":"/token", "servletContextId":125,
"filterDTOs":[{"name":"AuthenticationFilter", "patterns":["/*"],
"servletNames":null, "regexs":null, "asyncSupported":false,
"dispatcher":[], "initParams":{"component.id":"33",
"component.name":"com.casto...ionFilter",
"service.id":"117", "objectClass":"[Ljava.la...@5891e480",
"filterRank":"10", "service.scope":"prototype",
"osgi.http.whiteboard.filter.pattern":"/*", "
osgi.http.whiteboard.filter.name":"AuthenticationFilter",
"osgi.http.whiteboard.context.select":"(osgi.htt...xtHelper)",
"service.ranking":"10", "service.bundleid":"136"}, "serviceId":117,
"servletContextId":125}], "servletDTO":{"patterns":["/token"], "name":null,
"servletInfo":"", "asyncSupported":false, "initParams":{},
"servletContextId":125, "serviceId":127}, "resourceDTO":null}

However, the filter is still not triggered. If i manually create a
ServletContextHelper and add "osgi.http.whiteboard.context.select=(
osgi.http.whiteboard.context.name=SharedServletContextHelper)" to both the
filter and the servlet then i can see the filter kick in before the request
hit the servlet. So I think shared servlet context is required to have the
filters works across bundles. My concern is that i cannot use the
SharedServletContextHelper on the resource service because it will not see
the icons folder in my bundle. Here is the debug log if i use the
SharedServletContextHelper with the resource service:

[qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - servlet
|/static/icons|/bundle1.png -> /static/icons/*:/icons@d606ba18
==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
[qtp345379538-59] DEBUG
org.ops4j.pax.web.service.jetty.internal.HttpServiceContext - Handling
request for [/static/icons/bundle1.png] using http context
[org.ops4j.pax.web.extender.whiteboard.internal.WebApplication$1@1b9ac962]
[qtp345379538-59] DEBUG
org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler -
handling request
org.ops4j.pax.web.service.jetty.internal.HttpServiceRequestWrapper@5b1bfc6,
org.ops4j.pax.web.service.jetty.internal.HttpServiceResponseWrapper@b765100
[qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler -
chain=org.ops4j.pax.web.service.spi.model.FilterModel-13->/static/icons/*:/icons@d606ba18
==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
[qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call
filter org.ops4j.pax.web.service.spi.model.FilterModel-13
[qtp345379538-59] DEBUG org.eclipse.jetty.servlet.ServletHandler - call
servlet 
/static/icons/*:/icons@d606ba18==org.ops4j.pax.web.service.jetty.internal.ResourceServlet,jsp=null,order=-1,inst=true
 error_page=null (from global
default)

So now the question really is how to hook my servlet filter to a resource
service.

Thai

On Wed, Sep 12, 2018 at 3:01 PM, Raymond Auge 
wrote:

> Hello Thai,
>
> I don't see anything wrong.
>
> It looks like they all "target" the default "ServletContextHelper" (i.e.
> the same context) and so the filter should apply to each.
>
> You should be able to check by getting the HttpServiceRuntime [1] service
> and calling the method `calculateRequestInfoDTO(String path)` to see what
> the runtime thinks is wired up for that path.
>
> Sincerely,
> - Ray
>
> [1] https://osgi.org/specification/osgi.cmpn/7.0.0/
> service.http.whiteboard.html#org.osgi.service.http.runtime.
> HttpServiceRuntime
>
> On Wed, Sep 12, 2018 at 2:39 PM, Nhut Thai Le via osgi-dev <
> osgi-dev@mail.osgi.org> wrote:
>
>> Hello,
>>
>> I want to have a filter at the root of my application where all http
>> requests must pass through, so I make a Servlet filter:
>> @Component(
>> service=Filter.class,
>> scope=ServiceScope.PROTOTYPE,
>> property= {
>> "osgi.http.whiteboard.filter.name=AuthenticationFilter",
>> "osgi.http.whiteboard.filter.pattern=/*",
>> "service.ranking:Integer=10"
>> }
>> )
>> public final class AuthenticationFilter implements Filter {...}
>> -
>> Then I have some servlets (in other bundles) defined like this:
>> @Component(
>> service = Servlet.class,
>> property= {
>> "osgi.http.whiteboard.servlet.pattern=/token"
>> }
>> )
>> public class AccessTokenServlet extends HttpServlet{...}
>> ---
>> I also have some resource services in other bundles:
>> @Component(service = IconsResourceService.class,
>> property = {
>> "osgi.http.whiteboard.resource.pattern=/static/icons/*",
>> "osgi.http.whiteboard.resource.prefix=/icons"
>> }
>> )
>> public class IconsResourceService {}
>> ---
>> However, my filter never trigger when i request the icon (static
>> resource) or token (servlet). My understanding is that the 3 components
>> above reside in different bundles thus they have different servlet contexts
>> so the 

Re: [osgi-dev] How can I reuse servlet filter across bundles

2018-09-12 Thread Raymond Auge via osgi-dev
Hello Thai,

I don't see anything wrong.

It looks like they all "target" the default "ServletContextHelper" (i.e.
the same context) and so the filter should apply to each.

You should be able to check by getting the HttpServiceRuntime [1] service
and calling the method `calculateRequestInfoDTO(String path)` to see what
the runtime thinks is wired up for that path.

Sincerely,
- Ray

[1]
https://osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#org.osgi.service.http.runtime.HttpServiceRuntime

On Wed, Sep 12, 2018 at 2:39 PM, Nhut Thai Le via osgi-dev <
osgi-dev@mail.osgi.org> wrote:

> Hello,
>
> I want to have a filter at the root of my application where all http
> requests must pass through, so I make a Servlet filter:
> @Component(
> service=Filter.class,
> scope=ServiceScope.PROTOTYPE,
> property= {
> "osgi.http.whiteboard.filter.name=AuthenticationFilter",
> "osgi.http.whiteboard.filter.pattern=/*",
> "service.ranking:Integer=10"
> }
> )
> public final class AuthenticationFilter implements Filter {...}
> -
> Then I have some servlets (in other bundles) defined like this:
> @Component(
> service = Servlet.class,
> property= {
> "osgi.http.whiteboard.servlet.pattern=/token"
> }
> )
> public class AccessTokenServlet extends HttpServlet{...}
> ---
> I also have some resource services in other bundles:
> @Component(service = IconsResourceService.class,
> property = {
> "osgi.http.whiteboard.resource.pattern=/static/icons/*",
> "osgi.http.whiteboard.resource.prefix=/icons"
> }
> )
> public class IconsResourceService {}
> ---
> However, my filter never trigger when i request the icon (static resource)
> or token (servlet). My understanding is that the 3 components above reside
> in different bundles thus they have different servlet contexts so the
> filter wont trigger. I can created a ServletContextHelper and select it in
> the Servlet component annotation but this wont help in the case of the
> resource service. Is there other way to share filter across bundles?
>
> Thai
>
> ___
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>



-- 
*Raymond Augé* 
 (@rotty3000)
Senior Software Architect *Liferay, Inc.* 
 (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance  (@OSGiAlliance)
___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

[osgi-dev] How can I reuse servlet filter across bundles

2018-09-12 Thread Nhut Thai Le via osgi-dev
Hello,

I want to have a filter at the root of my application where all http
requests must pass through, so I make a Servlet filter:
@Component(
service=Filter.class,
scope=ServiceScope.PROTOTYPE,
property= {
"osgi.http.whiteboard.filter.name=AuthenticationFilter",
"osgi.http.whiteboard.filter.pattern=/*",
"service.ranking:Integer=10"
}
)
public final class AuthenticationFilter implements Filter {...}
-
Then I have some servlets (in other bundles) defined like this:
@Component(
service = Servlet.class,
property= {
"osgi.http.whiteboard.servlet.pattern=/token"
}
)
public class AccessTokenServlet extends HttpServlet{...}
---
I also have some resource services in other bundles:
@Component(service = IconsResourceService.class,
property = {
"osgi.http.whiteboard.resource.pattern=/static/icons/*",
"osgi.http.whiteboard.resource.prefix=/icons"
}
)
public class IconsResourceService {}
---
However, my filter never trigger when i request the icon (static resource)
or token (servlet). My understanding is that the 3 components above reside
in different bundles thus they have different servlet contexts so the
filter wont trigger. I can created a ServletContextHelper and select it in
the Servlet component annotation but this wont help in the case of the
resource service. Is there other way to share filter across bundles?

Thai
___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev